使用windos模拟搭建web集群(二)
一.通过rsync搭建备份服务器
这三个目录我们需要做实时热备,他们分别是 系统的脚本目录 系统的配置文件目录 系统的定时任务目录
[root@mage-monitor- ~]# cat /server/scripts/backuplist
/server/scripts
/etc
/var/spool/cron
1.使用ansible 的 file模块 在所有主机上模拟创建 一个写脚本的 目录
[root@mage-monitor- scripts]# for i in `cat backuplist`;do ansible all -m file -a "path=/server/scripts state=directory"; done;
2.服务端安装部署rsync
[root@store-rsync-01 ~]# yum install -y rsync
设置rsync的开机自启动
[root@store-rsync- ~]# chmod +x /etc/rc.d/rc.local
[root@store-rsync-01 ~]# echo "rsync --daemon" >>/etc/rc.d/rc.local
配置
uid = root
gid = root
use chroot = no
max connections =
timeout =
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.5.0/
auth users = benjamin
secrets file = /etc/rsync.password
[backup]
comment = "backup dir "
path = /backup
[nfsbackup]
comment = "nfsbackup dir"
path = /nfsbackup
[scripts]
comment = "scripts dir"
path = /server/scripts
[etc]
comment = "etc dir"
path = /etc
[crontab]
comment = "crontab dir"
path = /var/spool/cron
创建 rsync用户
[root@store-rsync- ~]# useradd -s /sbin/nologin -M rsync
创建数据备份储存目录,目录修改属主
[root@backup ~]# mkdir /nfsbackup/
[root@backup ~]# chown -R rsync.rsync /nfsbackup/
创建认证用户密码文件并进行授权600
[root@store-rsync- ~]# echo "benjamin:123" >>/etc/rsync.password
[root@store-rsync- ~]# chmod /etc/rsync.password
启动rsync服务
rsync --daemon
[root@store-rsync- ~]# ps -ef |grep rsync
root : ? :: rsync --daemon
root : pts/ :: grep --color=auto rsync
3.客户端测试
创建安全认证文件,并进行修改权限600
echo "123" >>/etc/rsync.password
chmod 600 /etc/rsync.password
[root@mage-monitor-01 scripts]# rsync -avz `pwd` benjamin@192.168.5.131::nfsbackup --password-file=/etc/rsync.password
sending incremental file list
rsync: chgrp "scripts" (in nfsbackup) failed: Operation not permitted ()
scripts/
scripts/a.sh
rsync: chgrp "scripts/.a.sh.SdKZyg" (in nfsbackup) failed: Operation not permitted () sent bytes received bytes 676.00 bytes/sec
total size is speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code ) at main.c() [sender=3.1.]
4.使用ansible copy模块 将/etc/rsync.password 和 同步脚本发送到所有主机
备份脚本
[root@mage-monitor- scripts]# cat backup_to_rsync.sh
#!/bin/bash #source function lib
. /etc/init.d/functions rsync_host=rsync.woniu.com #Defined varibles
IP=$(ifconfig eth1|awk -F '[ :]+' 'NR==2 {print $3}')
Path="/backup/$IP"
TIME=`/bin/date +%F`
BackupFile=/server/scripts/backuplist # Judge the existence of varibles
[ ! -d $Path ] && mkdir -p $Path [ ! -f $BackupFile ] && {
echo "Please give me $BackupFile"
exit
} # Defined result function
function Msg(){
if [ $? -eq ];then
action "$*" /bin/true
else
action "$*" /bin/false
fi
} # Backup config files
tar zcfh $Path/conf_${TIME}.tar.gz `cat $BackupFile` &>/dev/null
Msg 'Backup config files' # Make a flag for backup
find $Path -type f -name "${TIME}.tar.gz"|xargs md5sum >$Path/flag_$TIME >/dev/null
Msg 'Make a flag for backup' # Send backup to backup server
rsync -avz $Path benjamin@${rsync_host}::backup --password-file=/etc/rsync.password
Msg 'Send backup to backup server' # Delete backup a week ago
find ${Path-/tmp} -type f -name "*.tar.gz" -mtime +|xargs rm -f &>/dev/null
Msg 'Delete backup a week ago'
[root@mage-monitor- ~]# ansible all -m copy -a "src=/server/scripts/backuplist dest=/server/scripts/"
[root@mage-monitor- scripts]# ansible all -m copy -a "src=/etc/rsync.password dest=/etc"
[root@mage-monitor- scripts]# ansible all -m copy -a "src=/server/scripts/backup_to_rsync.sh dest=/server/scripts/"
5.将脚本加入定时任务使用每天凌晨推送 ansible的 shell 模块
centos7默认 的定时任务文件没有执行权限需要添加一下
[root@mage-monitor- scripts]# ansible all -m shell -a "chmod +x /etc/rc.d/rc.local"
定时脚本
[root@mage-monitor- scripts]# cat set_backup_script.sh
#!/bin/bash
function crond_backup(){
[ `crontab -l|grep "backup data"|wc -l` -eq ]&&{ echo -e "#backup data\n 00 00 * * * /bin/sh /server/scripts/backup_to_rsync.sh >/dev/null 2>&1" >> \
/var/spool/cron/root
crontab -l
sleep
}||{
echo "backup cron is exist,no config."
} }
crond_backup
将脚本 发送到所有主机 已存在的不做覆盖
[root@mage-monitor- ~]# ansible all -m copy -a "src=/server/scripts/set_backup_script.sh dest=/server/scripts/"
使用ansible的 script模块 执行脚本 removes参数判断脚本不存在就不执行,反之就执行
[root@mage-monitor- ~]# ansible all -m script -a "removes=/server/scripts/set_backup_script.sh /server/scripts/set_backup_script.sh "
将备份结果发邮件提醒就不弄了,比较简单。
下一节搞小米监控
使用windos模拟搭建web集群(二)的更多相关文章
- 使用windos电脑模拟搭建web集群(一)
资源规划 1.环境准备 centos7.2 虚拟机 13个 可以先配置一台,做好基础优化,然后克隆13台分布在 windos宿主机上 两台windos笔记 都是8g的内存 一台有点内存吃紧. 没有物 ...
- Haproxy配合Nginx搭建Web集群部署
Haproxy配合Nginx搭建Web集群部署实验 1.Haproxy介绍 2.Haproxy搭建 Web 群集 1.Haproxy介绍: a)常见的Web集群调度器: 目前常见的Web集群调度器分为 ...
- Haproxy搭建web集群
目录: 一.常见的web集群调度器 二.Haproxy应用分析 三.Haproxy调度算法原理 四.Haproxy特性 五.Haproxy搭建 Web 群集 一.常见的web集群调度器 目前常见的we ...
- 搭建Hadoop集群 (二)
前面的步骤请看 搭建Hadoop集群 (一) 安装Hadoop 解压安装 登录master, 下载解压hadoop 2.6.2压缩包到/home/hm/文件夹. (也可以从主机拖拽或者psftp压缩 ...
- 在本地模拟搭建zookeeper集群环境实例
先给一堆学习文档,方便以后查看 官网文档地址大全: OverView(概述) http://zookeeper.apache.org/doc/r3.4.6/zookeeperOver.html Get ...
- Web集群调度器-Haproxy
Web集群调度器-Haproxy 目录 Web集群调度器-Haproxy 一.Web集群调度器 1.常用的Web集群调度器 2. Haproxy应用分析 3. Haproxy的主要特性 4. 常用集群 ...
- 搭建Hadoop集群 (三)
通过 搭建Hadoop集群 (二), 我们已经可以顺利运行自带的wordcount程序. 下面学习如何创建自己的Java应用, 放到Hadoop集群上运行, 并且可以通过debug来调试. 有多少种D ...
- 搭建Hadoop集群 (一)
上面讲了如何搭建Hadoop的Standalone和Pseudo-Distributed Mode(搭建单节点Hadoop应用环境), 现在我们来搭建一个Fully-Distributed Mode的 ...
- Windows及Linux环境搭建Redis集群
一.Windows环境搭建Redis集群 参考资料:Windows 环境搭建Redis集群 二.Linux环境搭建Redis集群 参考资料:Redis Cluster的搭建与部署,实现redis的分布 ...
随机推荐
- Maven项目Update Project自动恢复为JRE1.5的问题
问题: 使用Eclipse建立Maven项目的时候,JDK默认为1.5在用户使用Config Build Path更新为最新JRE库比如1.8或者1.7的后,Maven项目显示JRE1.8 or 1. ...
- ElasticSearch学习笔记(三)-- 查询
1. URISearch详解与演示 2. QueryDSL简介 3. 字段类查询简介及match-query 4. 相关性算分 5. match-phrase-query 6. query-strin ...
- 编译器错误消息: CS1617: 选项“6”对 /langversion 无效
编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地修改源代码. 编译器错误消息: CS1617: 选项“6”对 /langversion 无效:必须是 ...
- 对setTimeout函数的理解
之前去面试一家公司时,面试官出了一道关于js的setTimeout函数的题目: /* *面试官给的原题目如下: *执行mytest()后,控制台输出内容是_____ *function mytest( ...
- Java入门 手把手教你配置环境变量
很多人觉得配置Java开发的环境变量很麻烦,很容易忘记,时常被它搞得晕头转向.如果出现这样的情况,那么原因只有一个,你不了解为毛需要配置环境变量,不配置环境变量就不能开发了吗? 答案是:NO!,那么下 ...
- 《Cracking the Coding Interview》——第9章:递归和动态规划——题目9
2014-03-20 04:08 题目:八皇后问题. 解法:DFS解决. 代码: // 9.9 Eight-Queen Problem, need I say more? #include <c ...
- 项目中DataTables分页插件的使用
在项目开发的过程中,一般都会对表格进行分页处理,大多是情况下会在项目中配置好后台分页插件,提高效率,减轻浏览器的压力.但是有时会遇到有些数据不能直接通过分页插件操作数据库进行分页数据查询,那就需要用到 ...
- ASP.NET Core API ---状态码
摘录自:https://www.cnblogs.com/cgzl/p/9047626.html 状态码是非常重要的,因为只有状态码会告诉API的消费者: 请求是否如预期的成功,或者失败 如果出现了错误 ...
- codeblocks17.12 debug 报错:ERROR: You need to specify a debugger program in the debuggers's settings.
DebugERROR: You need to specify a debugger program in the debuggers's settings.(For MinGW compilers, ...
- [CF632E]Thief in a Shop
题目大意:有一个小偷,拿$k$个东西,有$n$种产品,每种产品都有无限多个.对于每个第$i$ 种产品,它的价值是$A_i$.可能偷走的物品价值之和. 题解:对于所有的物品构造生成函数$F(x)=\su ...