使用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的分布 ...
随机推荐
- P1875 佳佳的魔法药水
P1875 佳佳的魔法药水 题目描述 发完了 k 张照片,佳佳却得到了一个坏消息:他的 MM 得病了!佳佳和大家一样焦急 万分!治好 MM 的病只有一种办法,那就是传说中的 0 号药水 ……怎么样才能 ...
- bootstrap重新设计按钮样式
1.将btn的样式换成以下的样式 2.思路: (1)将原来的btn样式设置color:#FFF,同时text-shadow设置,这样原来的btn样式就会变淡了,后面再加上新的样式就可以覆盖掉 注意:要 ...
- centos使用--防火墙
目录 1 切换到zsh 1.1 查看系统当前的shell 1.2 查看bin下是否有zsh包 1.3 安装zsh包 1.4 切换shell至zsh 2 安装oh-my-zsh 2.1 oh-my-zs ...
- 【转】Android 添加系统服务
Android系统本身提供了很多系统服务,如WindowManagerService,PowerManagerService等.下面描述一下添加一个系统服务的具体步骤. 1. 撰写一个aidl文件, ...
- 《Cracking the Coding Interview》——第5章:位操作——题目6
2014-03-19 06:24 题目:将一个整数的奇偶二进制位交换,(0, 1) (2, 3) ... 解法:使用掩码来进行快速交换,定义掩码为'0101...'和‘1010...’. 代码: // ...
- ul中li元素横向排列且不换行
ul { white-space: nowrap; } li { display: inline-block; } white-space 属性设置如何处理元素内的空白. normal 默认. ...
- linux系统下怎么关闭一个端口
netstat -an | grep 22查看22端口 netstat -ntulp |grep 80 //查看所有80端口使用情况
- vue常用片段
事件处理 基本骨架 子组件 axios v-if v-for 路由 设置style 计算属性 动态class 路由跳转 store nextTick 事件处理: 直接写表达式: @click=&q ...
- 爬虫:Scrapy8 - Item Pipeline
当 Item 在 Spider 中被收集之后,它将会被传递到 Item Pipeline,一些组件会按照一定的顺序执行对 Item 的处理. 每个 item pipeline 组件(有时也称之为“It ...
- ZOJ 3606 Lazy Salesgirl ( 线段树 + 思路 )
卖切糕的小女孩 http://www.cnblogs.com/wuyiqi/archive/2012/04/28/2474672.html #include <cstdio> #inclu ...