* 默认873端口,本次修改为8888
* rsync 数据镜像备份工具
* xinetd 网络守护进程服务
#安装软件
yum install rsync xinetd -y
rpm -qa|grep rsync
rsync-3.0.9-18.el7.x86_64
#设置 xindetd 配置文件 开机启动
cat >> /etc/xinetd.d/rsync <<EOF
service rsync
{
disable = no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
port = 8888
}
EOF
vim /etc/services
254 rsync 8888/tcp # rsync
255 rsync 8888/udp # rsync
#设置用户
groupadd rsync
useradd -g rsync rsync
mkdir /home/rsync/backup/
chown -R rsync.rsync /home/rsync/backup/
#设置rsyncd配置文件
cat >> /etc/rsyncd.conf <<EOF
port = 8888
uid = rsync
gid = rsync
use chroot = no
max connections = 40
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsyncd.lock
log file = /home/rsync/backup/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.10.0/24
hosts deny = 0.0.0.0/32
auth users = rsync
secrets file =/etc/rsyncd.passwd
[backup]
path = /home/rsync/backup/
EOF
#设置账户密码
echo rsync:hequan > /etc/rsyncd.passwd
#设置权限
chmod 600 /etc/rsyncd.passwd
chmod 600 /etc/rsyncd.conf
#启动
systemctl start xinetd.service
systemctl start rsyncd
yum install xinetd -y
cat >> /etc/xinetd.d/rsync <<EOF
service rsync
{
disable = no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
port = 8888
}
EOF
vim /etc/services
254 rsync 8888/tcp # rsync
255 rsync 8888/udp # rsync
cat >> /etc/rsyncd.conf <<EOF
[www]
path = /data
port = 8888
comment = file rsync
read only = no
kust = no
auth users = root
secrets file = /etc/rsyncd.passwd
hosts allow = 192.168.10.133
list = no
EOF
echo hequan > /etc/rsyncd.passwd
chmod 600 /etc/rsyncd.passwd
systemctl start xinetd.service
systemctl start rsyncd
测试: 从客户端 备份 到 服务器rsync -avH --port=8888 --progress /data rsync@192.168.10.133::backup --password-file=/etc/rsyncd.passwd
#查看服务器的内核是否支持inotify ,如果有就是支持
ll /proc/sys/fs/inotify
total 0
-rw-r--r-- 1 root root 0 Jan 22 17:39 max_queued_events
-rw-r--r-- 1 root root 0 Jan 22 17:39 max_user_instances
-rw-r--r-- 1 root root 0 Jan 22 17:39 max_user_watches
yum install make gcc gcc-c++ -y
cd /usr/local/src/
wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
tar xf inotify-tools-3.14.tar.gz
cd inotify-tools-3.14
./configure --prefix=/usr/local/inotify
make && make install
echo "PATH=/usr/local/inotify/bin:$PATH" >> /etc/profile.d/inotify.sh
source /etc/profile.d/inotify.sh
echo "/usr/local/inotify/lib" >/etc/ld.so.conf.d/inotify.conf
ln -s /usr/local/inotify/include /usr/include/inotify
sysctl -a | grep max_queued_events
sysctl -a | grep max_user_watches
sysctl -a | grep max_user_instances
echo ‘fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
‘ >> /etc/sysctl.conf
/sbin/sysctl -p
cat >> /usr/local/inotify/rsync.sh << EOF
#!/bin/sh
srcdir=/data/nginx
dstdir=backup
rsyncuser=rsync
rsyncpassdir=/etc/rsyncd.passwd
dstip="192.168.10.133"
rsync -avH --port=8888 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
/usr/local/inotify/bin/inotifywait -mrq --timefmt ‘%d/%m/%y %H:%M‘ --format ‘%T %w%f%e‘ -e close_write,modify,delete,create,attrib,move $srcdir | while read file
do
for ip in $dstip
do
rsync -avH --port=8888 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
echo " ${file} was rsynced" >> /tmp/rsync.log 2>&1
done
done
EOF
chmod +x /usr/local/inotify/rsync.sh
测试:
/usr/local/inotify/rsync.sh`
正式应用:
nohup /usr/local/inotify/rsync.sh > /dev/null 2>&1 &
原文:http://blog.51cto.com/hequan/2063841