eg:
操作系统:CentOS release 6.5
服务器IP:rsync_server(数据源) 192.168.23.27
rsync_client (目标端)192.168.23.67
同步目录: rsync_server /home/public
rsync_client /home/public
rsync_client (目标端)192.168.23.67
1、安装Rsync服务端
[root@zabbixserver ~]# yum -y xinted rsync^C [root@zabbixserver ~]# cat /etc/xinetd.d/rsync # default: off # description: The rsync server is a good addition to an ftp server, as it \ # allows crc checksumming etc. service rsync { disable = yes flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } [root@zabbixserver ~]# cat /etc/rsyncd.conf uid = root gid = root max connections=4 log file = /var/log/rsyncd.log pid file = /var/run/rsyncd.pid lock file = /var/run/rsyncd.lock secrets file= /etc/rsyncd.passwd hosts allow = 192.168.23.0/24 [www] comment = public path= /home/public read only = no exclude= test auth users= work secrets file= /etc/rsync.passwd 这些是我的配置文件:/etc/xinetd.d/rsync,/etc/rsyncd.conf [root@zabbixserver ~]# cat /etc/rsync.passwd work:123abc [root@zabbixserver ~]# ls -l /etc/rsync.passwd -rw------- 1 root root 12 Sep 27 00:17 /etc/rsync.passwd [root@zabbixserver ~]#service xinetd restart 启动rsync 服务 rsync --daemon --config=/etc/rsyncd.conf
rsync_server(数据源) 192.168.23.27
安装Rsync客户端
[root@localhost rsync_server]# whereis rsync #查看系统是否已安装rsync rsync: /usr/bin/rsync /usr/share/man/man1/rsync.1.gz #说明已经安装 [root@localhost rsync_server]#
yum install xinetd #已安装rsync只安装xinetd即可,CentOS中是以xinetd来管理rsync服务的
yum install rsync xinetd #如果默认没有rsync,运行此命令进行安装rsync和xinetd
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@localhost rsync_server] # vim /etc/xinetd.d/rsync service rsync { disable = no #修改为no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID } [root@localhost rsync_server] # /etc/init.d/xinetd restart [root@localhost rsync_server] # vim /etc/passwd.txt 123456 [root@localhost rsync_server] # chmod 600 /etc/passwd.txt |
测试
在rsync_server的/home/public目录下创建文件testfile,在rsync_server端运行同步命令同步数据:
sync -avH --port=873 --progress --delete /home/public/ work@192.168.23.67::www --password-file=/etc/rsync.passwd
[root@rsync etc]# rsync -avH --port=873 --progress --delete /home/public/ work@192.168.23.67::www --password-file=/etc/rsync.passwd sending incremental file list ./ test.txt 77 100% 0.00kB/s 0:00:00 (xfer#1, to-check=0/2) sent 166 bytes received 36 bytes 404.00 bytes/sec total size is 77 speedup is 0.38
在rsync_server(数据源) 192.168.23.67上安装Inotify-tools工具,实时触发rsync进行同步
1、安装Inotify-tools工
[root@zabbixserver ~]# ll /proc/sys/fs/inotify/max_ max_queued_events max_user_instances max_user_watches
rsync_client
1 2 3 | [root@localhost rsync_client] # ls file [root@localhost rsync_client] # |
在rsync_server(数据源) 10.15.43.100上安装Inotify-tools工具,实时触发rsync进行同步
1、安装Inotify-tools工
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | [root@localhost src] # ll /proc/sys/fs/inotify #查看服务器内核是否支持inotify,出现下面的内容,说明服务器内核支持inotify total 0 -rw-r--r-- 1 root root 0 Jul 27 10:32 max_queued_events -rw-r--r-- 1 root root 0 Jul 27 10:32 max_user_instances -rw-r--r-- 1 root root 0 Jul 27 10:32 max_user_watches [root@localhost src] # uname -r #Linux下支持inotify的内核最小为2.6.13 2.6.32-642.el6.x86_64 [root@localhost src] # tar zxvf inotify-tools-3.14.tar.gz [root@localhost src] # cd inotify-tools-3.14 [root@localhost inotify-tools-3.14] # ./configure --prefix=/app/inotify [root@localhost inotify-tools-3.14] # make && make install [root@localhost inotify-tools-3.14] # vim /etc/profile #设置系统环境变量 export PATH= /app/inotify/bin :$PATH [root@localhost inotify-tools-3.14] # source /etc/profile [root@localhost inotify-tools-3.14] # echo " /app/inotify/lib" > /etc/ld.so.conf.d/inotify.conf [root@localhost inotify-tools-3.14] # ln -s /app/inotify/include /usr/include/inotify [root@localhost inotify-tools-3.14] # sysctl -a|egrep -i "max_queued_events|max_user_watches|max_user_instances" #修改inotify默认参数(inotify默认内核参数值太小) fs.inotify.max_user_instances = 128 fs.inotify.max_user_watches = 8192 fs.inotify.max_queued_events = 16384 fs.epoll.max_user_watches = 201420 [root@localhost inotify-tools-3.14] # vim /etc/sysctl.conf fs.inotify.max_user_instances = 65535 fs.inotify.max_user_watches = 99999999 fs.inotify.max_queued_events = 99999999 [root@localhost inotify-tools-3.14] # cat /proc/sys/fs/inotify/{max_user_instances,max_user_watches,max_queued_events} 65535 99999999 99999999 [root@localhost inotify-tools-3.14] # |
报错:
如果以上测试都通过,说明inotify实时触发rsync同步脚本运行正常。
至此,Linux下Rsync+Inotify-tools实现数据实时同步完成。如果要双向同步可以把以上反过来部署次。
报错:
ps:
本人初次使用rsync,如本文有错误,欢迎联系本人。文中可能出现步骤不完善的情况,具体安装流程可以参考原文博客http://ityunwei2017.blog.51cto.com/7662323/1951362。
本文转载自博客:http://ityunwei2017.blog.51cto.com/7662323/1951362
rsync参考资料:http://man.linuxde.net/rsync
参考文章:rsync实时同步(搭配inotify-tools) http://blog.csdn.net/liyongming1982/article/details/12271869
configure: error: no acceptable C compiler found in $PATH 问题解决
http://blog.csdn.net/duguduchong/article/details/8699774