ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 项目背景 [ansible部署][2] 代码发布到master上,slave周期性从master同步代码。 在此种方式下,没办法做到代码实时更新。 ![](http://om4h63cja.bkt.clouddn.com/17-5-13/16108068-file_1494663056132_ba17.png) ## master和slave安装rsync ### yum安装 ~~~ yum install -y rsync ~~~ 也可以在扩展源epel-self中直接安装 **rsync-enhanced** ### 编译安装 [下载][1] ~~~ ./configure && make && make install ~~~ ## master配置 ### 配置文件 /etc/rsyncd.conf ~~~ # 全局设置 strict mood = yes # 是否检查secrete文件权限,若其他人可读,则无法同步 port = 873 # 默认开的端口 uid = root # 用户 gid = root # 用户组 use chroot = no # 不允许改变程序执行时所参考的根目录位置 max connections = 4 # 最大连接数 pid file = /var/run/rsyncd.pid # pid文件路径 lock file = /var/rsyncd.lock # look文件路径 log file = /var/log/rsyncd.log # 日志文件路径 transfer logging = yes # 开启传输日志 timeout = 900 # 连接超时时间 ignore nonreadable = yes # 忽略不可读的文件 ignore errors # I/O错误时,不删除目标文件 dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 # 项目设置 [test] common = # 同步描述 path = /alidata/www/default # 源文件路径 read only = yes # yes不允许上传 write only = no # no允许下载 list = no hosts allow = 10.161.140.46 # 允许客户端地址 auth users = root # 客户端用户 secrets file = /etc/rsyncd.password # 客户端密码文件 ~~~ ### 编辑密码文件,并修改权限 ~~~ # vim /etc/rsyncd.password root:123456 # chmod 600 /etc/rsyncd.password ~~~ ### 开启rsync服务 #### 以daemon方式运行 >[info]若文件传输比较频繁,推荐使用daemon方式 ~~~ /usr/bin/rsync --daemon --config=/etc/rsyncd.conf 或者 systemctl start rsyncd ~~~ 开机自启 ~~~ echo "/usr/bin/rsync --daemon --config=/etc/rsyncd.conf" >> /etc/rc.local ~~~ #### 使用超级守护进程运行 ~~~ yum install -y xinetd ~~~ 开机自启 ~~~ chkconfig --add xinetd chkconfig xinetd on ~~~ 开启rsync ~~~ vim /etc/xinetd.d/rsync disable = no ~~~ --- ## slave配置 ### 添加密码文件,并修改权限 ~~~ # vim /etc/rsyncd.password 123456 # chmod 600 /etc/rsyncd.password ~~~ ### 同步文件参数 ~~~ /usr/bin/rsync -avrP --delete --progress --exclude=Runtime --password-file=/etc/rsyncd.password root@10.171.239.5::test /dest ~~~ ### 设置任务计划 ~~~ 0 */2 * * * /usr/bin/rsync -avrP --delete --exclude=Runtime --password-file=/etc/rsyncd.password root@10.171.239.5::test /dest ~~~ [1]: https://rsync.samba.org/ [2]:https://coding.net/u/echohiyang/p/playbook/git/tree/master/rsync_y