磁盘同步rsync+sersync
2015-11-19 14:31
204 查看
一、说明
1. rsync在同步的时候,并不知道具体是哪个文件或者哪个目录发生了变化,每次都是对整个目录进行同步,当数据量很大时,整个目录同步非常耗时(rsync要对整个目录遍历查找对比文件),因此,效率很低。
2. sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字;
3. sersync + rsync 可以用sersync监听某一个目录发生变化,然后通知另一台机器的rsync来同步此变化. 所以,sersync安装在主服务器上,用于监控. rsync 安装在备服务上用户复制主服务器上的变化.
二、具体步骤
1. 二台机器 (192.168.1.7 备 , 192.168.1.165 主)
2. 两台机器上都关闭selinux.
3. 安装Rsync服务端软件 (192.168.1.7 安装)
yum install rsync xinetd -y
vim /etc/xinetd.d/rsync
4. 配置Rsync (192.168.1.7)
a) 配置rsyncd.conf文件
vim /etc/rsyncd.conf
log file =/usr/local/rsync/rsyncd.log #日志文件位置.
pidfile =/usr/local/rsync/rsyncd.pid #pid文件的存放位置
lock file =/usr/local/rsync/rsync.lock #支持max connections参数的锁文件
secrets file= /usr/local/rsync/rsync.pass #用户认证配置文件,里面保存用户名称和密码,后面会创建这个文件
motd file =/usr/local/rsync/rsyncd.Motd #rsync启动时欢迎信息页面文件位置(文件内容自定义)
[rongzhongalex07] #自定义名称 , 用于监控连接的名字
path =/data/web/home/index/ #rsync服务端数据目录路径
comment =rongzhongalex07
#模块名称与[rongzhongalex07]自定义名称相同
uid =rongzhong
#设置rsync运行权限为root
gid =rongzhong
#设置rsync运行权限为root
port=873 #默认端口
use chroot =no #默认为true,修改为no,增加对目录文件软连接的备份
read only =no #读权限
write only =no
#写权限
list = no #不显示rsync服务端资源列表
maxconnections = 200
#最大连接数
timeout =600 #设置超时时间
hosts allow= 192.168.1.165 #允许进行数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
hosts deny =*
#禁止数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
*号表示所有
[rongzhongalex07_2] #
与上面是一样的,这是同时同步2个目录.
path =/data/web/home/page/static
comment =rongzhongalex07_2
uid =rongzhong
gid =rongzhong
port=873
use chroot =no
read only =no
write only =no
list = no
maxconnections = 200
timeout =600
hosts allow= 192.168.1.165
hosts deny =*
如下图:
b). 创建用户认证密码
echo “123456” > /usr/local/rsync/rsync.pass
c). 设置文件权限
chmod 600 /usr/local/rsync/rsync.pass
chmod 600 /etc/rsyncd.conf
d). 重启 xinetd 服务
/etc/init.d/xinetd restart
5. 配置sersync (192.168.1.165)
a). 下载sersync直接解压到 /usr/local/sersync目录中.
b). 添加密码验证文件,跟备机上一样的密文.
echo “123456” > /usr/local/rsync/rsync.pass
chmod 600 /usr/local/rsync/rsync.pass
c). 在目录下面有一个conxml.xml.
修改文件名.
cp conxml.xml alexconf_index.xml
cp conxml.xml alexconf_static.xml
因为这里要同时监控2个目录,所以配置2个配置文件.
vim alexconf_index.xml
vim alexconf_static.xml (这个跟上面的一样的修改方法)
D). 添加脚本,监控sersync是否正常运行
vim check_sersync.sh
# 用于检查alexconf_index.xml配置文件的sersync是否运行正常.
vim check_sersync_2.sh
# 用于检查alexconf_static.xml配置文件的sersync是否运行正常.
E). 加入crontab中 . (每10分钟检查一次)
*/10 * * * */usr/local/sersync/check_sersync.sh >> /usr/local/sersync/ser.log
*/10 * * * */usr/local/sersync/check_sersync_2.sh >> /usr/local/sersync/ser.log
F). 启动sersync
/usr/local/sersync/sersync2-d -n 20 -o /usr/local/sersync/alexconf_index.xml
/usr/local/sersync/sersync2-d -n 20 -o /usr/local/sersync/ alexconf_static.xml
# 参数-d:启用守护进程模式
# 参数-n: 指定开启守护线程的数量,默认为10个
# 参数-o:指定配置文件,默认使用confxml.xml文件
1. rsync在同步的时候,并不知道具体是哪个文件或者哪个目录发生了变化,每次都是对整个目录进行同步,当数据量很大时,整个目录同步非常耗时(rsync要对整个目录遍历查找对比文件),因此,效率很低。
2. sersync可以记录下被监听目录中发生变化的(包括增加、删除、修改)具体某一个文件或某一个目录的名字;
3. sersync + rsync 可以用sersync监听某一个目录发生变化,然后通知另一台机器的rsync来同步此变化. 所以,sersync安装在主服务器上,用于监控. rsync 安装在备服务上用户复制主服务器上的变化.
二、具体步骤
1. 二台机器 (192.168.1.7 备 , 192.168.1.165 主)
2. 两台机器上都关闭selinux.
3. 安装Rsync服务端软件 (192.168.1.7 安装)
yum install rsync xinetd -y
vim /etc/xinetd.d/rsync
disable = no # 其实rsync 由 xinetd管理 /etc/init.d/xinetd start # 启动xinetd chkconfig xinetdon # 设置为开机启动
4. 配置Rsync (192.168.1.7)
a) 配置rsyncd.conf文件
vim /etc/rsyncd.conf
log file =/usr/local/rsync/rsyncd.log #日志文件位置.
pidfile =/usr/local/rsync/rsyncd.pid #pid文件的存放位置
lock file =/usr/local/rsync/rsync.lock #支持max connections参数的锁文件
secrets file= /usr/local/rsync/rsync.pass #用户认证配置文件,里面保存用户名称和密码,后面会创建这个文件
motd file =/usr/local/rsync/rsyncd.Motd #rsync启动时欢迎信息页面文件位置(文件内容自定义)
[rongzhongalex07] #自定义名称 , 用于监控连接的名字
path =/data/web/home/index/ #rsync服务端数据目录路径
comment =rongzhongalex07
#模块名称与[rongzhongalex07]自定义名称相同
uid =rongzhong
#设置rsync运行权限为root
gid =rongzhong
#设置rsync运行权限为root
port=873 #默认端口
use chroot =no #默认为true,修改为no,增加对目录文件软连接的备份
read only =no #读权限
write only =no
#写权限
list = no #不显示rsync服务端资源列表
maxconnections = 200
#最大连接数
timeout =600 #设置超时时间
hosts allow= 192.168.1.165 #允许进行数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
hosts deny =*
#禁止数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
*号表示所有
[rongzhongalex07_2] #
与上面是一样的,这是同时同步2个目录.
path =/data/web/home/page/static
comment =rongzhongalex07_2
uid =rongzhong
gid =rongzhong
port=873
use chroot =no
read only =no
write only =no
list = no
maxconnections = 200
timeout =600
hosts allow= 192.168.1.165
hosts deny =*
如下图:
b). 创建用户认证密码
echo “123456” > /usr/local/rsync/rsync.pass
c). 设置文件权限
chmod 600 /usr/local/rsync/rsync.pass
chmod 600 /etc/rsyncd.conf
d). 重启 xinetd 服务
/etc/init.d/xinetd restart
5. 配置sersync (192.168.1.165)
a). 下载sersync直接解压到 /usr/local/sersync目录中.
b). 添加密码验证文件,跟备机上一样的密文.
echo “123456” > /usr/local/rsync/rsync.pass
chmod 600 /usr/local/rsync/rsync.pass
c). 在目录下面有一个conxml.xml.
修改文件名.
cp conxml.xml alexconf_index.xml
cp conxml.xml alexconf_static.xml
因为这里要同时监控2个目录,所以配置2个配置文件.
vim alexconf_index.xml
vim alexconf_static.xml (这个跟上面的一样的修改方法)
D). 添加脚本,监控sersync是否正常运行
vim check_sersync.sh
# 用于检查alexconf_index.xml配置文件的sersync是否运行正常.
#!/bin/sh sersync="/usr/local/sersync/sersync2" confxml="/usr/local/sersync/alexconf_index.xml" status=$(psaux |grep 'alexconf_index.xml'|grep -v 'grep'|wc -l) if [$status -eq 0 ]; then $sersync-d -n 20 -o $confxml & else exit0; fi
vim check_sersync_2.sh
# 用于检查alexconf_static.xml配置文件的sersync是否运行正常.
#!/bin/sh sersync="/usr/local/sersync/sersync2" confxml="/usr/local/sersync/alexconf_static.xml" status=$(ps aux |grep'alexconf_static.xml'|grep -v 'grep'|wc -l) if [ $status -eq 0 ]; then $sersync -d -n 20 -o $confxml & else exit 0; fi
E). 加入crontab中 . (每10分钟检查一次)
*/10 * * * */usr/local/sersync/check_sersync.sh >> /usr/local/sersync/ser.log
*/10 * * * */usr/local/sersync/check_sersync_2.sh >> /usr/local/sersync/ser.log
F). 启动sersync
/usr/local/sersync/sersync2-d -n 20 -o /usr/local/sersync/alexconf_index.xml
/usr/local/sersync/sersync2-d -n 20 -o /usr/local/sersync/ alexconf_static.xml
# 参数-d:启用守护进程模式
# 参数-n: 指定开启守护线程的数量,默认为10个
# 参数-o:指定配置文件,默认使用confxml.xml文件
相关文章推荐
- Xcode7 免证书真机调试
- MYSQL中limit的使用
- java入门 第三季3
- 。鸟哥私房菜
- AFNetWork 简单实用demo
- CentOS yum安装redis(转)
- java中的路径
- php四种基础算法:冒泡,选择,插入和快速排序法
- 你爱我吗?如何利用BRAT进行中文情感分析语料标注掌握玩家心声
- 较好的类名命名规则
- hive使用技巧(二)——共享中间结果集
- 树、森林及二叉树的相互转换 – 数据结构和算法50
- Java如何判断socket是否已经断开
- 指针遇到的问题,请指教
- Centos下彻底删除oracle
- java入门 第三季2
- Android App监听软键盘按键的三种方式
- 「价值」我真不是买不起,而是要把钱花在了更有意义的地方
- [置顶] 谷歌安卓UI自动化测试策略
- 搭建redis单机集群