高性能高可用(4)文件自动同步rsync+sersync

Master机器地址为192.168.6.31
Slave机器地址为192.168.6.58

备服务器(192.168.6.58)配置

使用root用户在shell执行以下命令
创建配置文件

touch /etc/rsyncd.conf

编辑配置文件

vi /etc/rsyncd.conf

添加以下内容,其中的hosts allow的值请修改为主服务器的IP,path的值请修改为要同步的目的目录

uid = root              
gid = root              
use chroot = no                         
max connections = 2000                  
timeout = 600                           
pid file =/var/run/rsyncd.pid           
lock file =/var/run/rsync.lock          
log file = /var/log/rsyncd.log          
ignore errors                           
read only = false                       
write only = false                      
list = false                            
hosts allow = 192.168.6.31          
hosts deny = 0.0.0.0/32                 
auth users = rsync                      
secrets file =/etc/rsync.password       
 [HTZP]                                  
comment = htzp                  
path = /data/HTZP/

创建密码文件

touch /etc/rsync.password

添加rsync用户和密码

echo "rsync:rsync">/etc/rsync.password

密码文件授权

chmod 600 vi /etc/rsync.password

启动rsync服务

rsync --daemon

查询端口监听情况,查询rsync是否正常启动

netstat -nulpt| grep rsync

设置开机自启动
在文件/etc/rc.local添加下行

/usr/bin/rsync  --daemon

开放防火墙rsync端口,默认为873,可用命令netstat -nulpt| grep rsync查询

vi /etc/sysconfig/iptables

添加下行,需放在reject之前

-A INPUT -m state --state NEW -m tcp -p tcp --dport 873 -j ACCEPT

保存后,重启防火墙

service iptables restart

主服务器(192.168.6.31)部署

配置rsync密码文件
创建密码文件

touch /etc/rsync.password

添加rsync用户和密码

echo "rsync">/etc/rsync.password

密码文件授权

chmod 600 /etc/rsync.password

运行同步命令,实验能否正常同步文件夹,请将下文的/data/HTZP/修改为要实验的文件夹路径,192.168.6.58修改为备服务器IP,如果同步成功,表示主备服务器的rsync配置正确。

rsync -avzP /data/HTZP/ rsync@192.168.6.58::HTZP --password-file=/etc/rsync.password
安装sersync

将sersync安装文件拷贝到主服务器的/usr/local/src下

cd /usr/local/src
tar zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
cp -r GNU-Linux-x86 /usr/local/sersync
cd /usr/local/sersync/

按标准规范sersync目录结构方便日后管理

mkdir conf bin logs
mv confxml.xml conf
mv sersync2 bin/sersync
配置sersync

打开文件confxml_htzp.xml

修改24行的/usr/src/apache-tomcat-7.0.70/webapps/HTZP/uploadFile修改为本机(主服务器)招聘小秘书简历文件的上传目录

修改25行的192.168.6.58为备服务器IP

将上面的文件放到/usr/local/sersync/conf目录下

启动sersync

在shell中运行,指定配置文件

/usr/local/sersync/bin/sersync -r -d -o /usr/local/sersync/conf/confxml_htzp.xml

参数-d:启用守护进程模式

参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍

参数-n: 指定开启守护线程的数量,默认为10个

参数-o:指定配置文件,默认使用confxml.xml文件

参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块

参数-m:单独启用其他模块,使用 -m socket 开启socket模块

参数-m:单独启用其他模块,使用 -m https 开启https模块

不加-m参数,则默认执行同步程序

验证

在主服务器目录中依次新增文件、修改该文件、删除该文件,查看从服务器是否也对应自动新增文件、修改该文件、删除该文件(可能存在几秒的延迟)。

如果成功,则表示复制正常运行。

如果失败,请检查sersync日志(位于/usr/local/sersync/logs/rsync_fail.log)查找失败原因

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值