1)检查系统是否已经安装rsync和xinetd超级守护进程,CentOS6.4默认已经安装rsync,但未安装xinetd
[root@nmshuishui www]# rpm -qa | grep rsyncrsync-3.0.6-9.el6.x86_64
vim /etc/rsyncd.conf
#Global Settings 全局配置uid = nobody#运行rsync的用户gid = nobody#运行rsync的用户组use chroot = no#是否让进程离开工作目录max connections = 5#最大并发连接数,0为不限制timeout = 600#超时时间pid file = /var/run/rsyncd.pid#指定rsync的pid存放路径lockfile = /var/run/rsyncd.lock#指定rsync的锁文件存放路径log file = /var/log/rsyncd.log#指定rsync的日志存放路径#模块配置[web1]path = /var/www#认证的模块名,在client端需要指定ignore errors = yes#忽略一些无关的I/O错误read only = no#客户端是否能拉(PULL)write only = no#客户端是否能推(PUSH)hosts allow = 172.16.150.150#白名单,可以访问此模块的主机hosts deny = *#黑名单,*表示任何主机list = yes#客户端请求是否可以列出模块列表uid = root#以root的身份去获取文件gid = rootauth users = web#认证此模块的用户名secrets file = /etc/web.passwd#指定存放“用户名:密码”格式的文件
3)创建同步目录
[root@nmshuishui ~]# mkdir /var/www
4)配置rsync认证文件/etc/web.passwd
[root@nmshuishui ~]# echo “web:web” > /etc/web.passwd[root@nmshuishui ~]# cat /etc/web.passwdweb:web
5)修改/etc/web.passwd的权限为600
[root@nmshuishui ~]# chmod 600 /etc/web.passwd[root@nmshuishui ~]# ll /etc/web.passwd-rw——- 1 root root 10 Mar 27 22:31 /etc/web.passwd
6)配置服务能够启动
[root@nmshuishui ~]# chkconfig rsync on[root@nmshuishui ~]# service xinetd startStarting xinetd:[ OK ]
步骤同上
1)检查系统是否已经安装rsync和xinetd超级守护进程
2)为rsync服务提供配置文件
vim /etc/rsyncd.conf
#Global Settingsuid = nobodygid = nobodyuse chroot = nomax connections = 5timeout = 600pid file = /var/run/rsyncd.pidlockfile = /var/run/rsyncd.locklog file = /var/log/rsyncd.log[web2]path = /var/wwwignore errors = yesread only = nowrite only = nohosts allow = 172.16.150.150hosts deny = *list = yesuid = rootgid = rootauth users = websecrets file = /etc/web.passwd
[root@shuishui ~]# echo “web:web” > /etc/web.passwd[root@shuishui ~]# cat /etc/web.passwdweb:web
5)修改/etc/web.passwd的权限为600
[root@shuishui ~]# chmod 600 /etc/web.passwd[root@shuishui ~]# ll /etc/web.passwd-rw——- 1 root root 10 Mar 29 15:21 /etc/web.passwd
6)配置服务能够启动
[root@nmshuishui ~]# chkconfig rsync on[root@nmshuishui ~]# service xinetd startStarting xinetd:[ OK ]
1、设置 rsync 客户端的密码文件,客户端只需要设置 rsync 同步的密码即可,,不用设置用户名(默认已经安装了rsync)
[root@shuishui ~]# echo web > /etc/web.passwd[root@shuishui ~]# cat /etc/web.passwdweb
2、修改/etc/rsyncd.passwd的权限为600
[root@shuishui www]# chmod 600 /etc/web.passwd[root@shuishui www]# ll /etc/web.passwd-rw——- 1 root root 10 Mar 26 21:28 /etc/web.passwd
3、安装inotify-tools
# tar xf inotify-tools-3.13.tar.gz# cd inotify-tools-3.13# ./configure# make && make install
[root@shuishui www]# rsync –password-file=/etc/web.passwd /etc/fstab web@172.16.251.93::web1#PUSH[root@shuishui www]# rsync –password-file=/etc/web.passwd web@172.16.251.93::web1/123 /var/www/#PULL
编写rsync脚本
vim /var/www/rsync.sh
#!/bin/bashsrc=/var/www/des1=web1des2=web2host1=172.16.251.93host2=172.16.251.194user1=webuser2=web/usr/local/bin/inotifywait -mrq –timefmt ‘%d/%m/%y %H:%M’ –format ‘%T %w %f’ -e modify,delete,create,attrib $src | while read file DATE TIME DIR;do/usr/bin/rsync -vzrtopg –delete –progress $src $user1@$host1::$des1 –password-file=/etc/web.passwd/usr/bin/rsync -vzrtopg –delete –progress $src $user2@$host2::$des2 –password-file=/etc/web.passwdecho “${files} was rsynced” >> /var/log/rsync.log 2>&1done
2、给rsync.sh执行权限
[root@shuishui www]# chmod +x rsync.sh[root@shuishui www]# ll rsync.sh-rwxr-xr-x 1 root root 523 Mar 27 00:46 rsync.sh
本文出自 “nmshuishui的博客” 博客,请务必保留此出处
可你仍然感谢天地和人世所带来的这些变化和发生。