安裝rsync
#yum install -y xinetd
#yum install -y rsync
#vim /etc/xinetd.d/rsync
啓動XINETD
#service xinetd start
Starting xinetd: [ OK ]#chkconfig xinetd on
#netstat -tlunp |grep 873 查看端口
tcp 0 0 :::873 :::* LISTEN 8831/xinetd
配置密碼文件:rsync被同步端配置
A主機上配置 再B上同步
vim /etc/rsyncd.conf
uid=root
gid=root
use chroot=no
max connections=10
log file=/home/logs/rsync/rsyncd.log
pid file=/home/logs/rsync/rsyncd.pid
lock file= /var/run/rsync.lock
[family]
path=/home/mengc
comment=prd
ignore errors
hosts allow = 你要同步到的主機地址
read only=yes
list= no
#vi ~/.ssh/known_hosts 解決ssh 無法登陸的問題
#getenforce(查看selinux狀態)
#setenforce 0(修改爲允許模式)
最後記得修改配置文件/etc/sysconfig/selinux,要不然下次重啓會回退。https://blog.csdn.net/baiwz/article/details/32339049
[root@localhost mengc]# /usr/local/bin/inotifywait -mrp -- timefmt --timefmt '%Y/%m/%d-%H:%M:%S' --format '%T %w %f' -e modify,create,delete,attrib /home/mengc
/usr/local/bin/inotifywait: error while loading shared libraries: libinotifytools.so.0: cannot open shared object file: No such file or directory
有很多的so會存放在/usr/local/lib這個目錄底下,去這個目錄底下找,果然發現自己所需要的.so文件。
所以,在/etc/ld.so.conf中加入/usr/local/lib這一行,保存之後,再運行:/sbin/ldconfig –v更新一下配置即可。
11主機上配置
uid=root
gid=root
use chroot=yes
max connections=10
log file=/home/logs/rsync/rsyncd.log
pid file=/home/logs/rsync/rsyncd.pid
lock file=/var/run/rsync.lock
[family11]
path=/home/work/local/webapps/webapp-family/
comment=family11
ignore errors
hosts allow = IP
read only=false
list=no
在12主機上同步 /usr/bin/rsync -avptgo --delete --progress /home/work/local/webapps/webapp-family root@IP::family11
配置inotify
[root@wcc-vm-family-3711 software]# cd inotify-tools-3.13
[root@wcc-vm-family-3711 inotify-tools-3.13]# ls
aclocal.m4 AUTHORS ChangeLog config.guess config.h.in config.sub configure configure.ac COPYING depcomp INSTALL install-sh libinotifytools ltmain.sh Makefile.am Makefile.in man missing NEWS README src
[root@wcc-vm-family-3711 inotify-tools-3.13]# ./configure
[root@wcc-vm-family-3711 inotify-tools-3.13]# make && make install
#!/bin/sh
/usr/local/bin/inotifywait -mrq --timefmt '%Y/%m/%d-%H:%M:%S' --format '%T %w%f%e' -e modify,create,delete,attrib /home/work/local/webapps/webapp-family | while read date time dir file;do
/usr/bin/rsync -avptgo --delete --progress /home/work/local/webapps/webapp-family root@IP::family12
done
nohup sh /home/work/local/webapps/inotify.sh &
--使用nohup掛起到後臺執行,終端關閉,這個進程也不會被關閉