server1:192.168.10.1
server2:192.168.10.2
实现server2实时同步server1的数据!
###############server1###############
1.安装rsync和xinetd,并创建目录:
yum install rsync xinetd
mkdir -p /home/rsync/
mkdir -p /home/rsync/log/
mkdir -p /home/rsync/pid/
mkdir -p /home/rsync/run/
2.配置xinetd:
vi /etc/xinetd.d/rsync
#disable = yes修改为
disable = no
3.启动xinetd服务:
service xinetd start
4.编辑rsyncd.conf配置文件:
vim /etc/rsyncd.conf
uid = root
gid = root
port=873
use chroot = no
read only = no
list = no
max connections = 0
timeout = 600
log file = /home/rsync/log/rsyncd.log
pidfile = /home/rsync/pid/rsyncd.pid
lock file = /home/rsync/run/rsync.lock
[rsync]
path = /alidata/www/xu/
comment = rsync
ignore errors
auth users = rsync
secrets file = /home/rsync/rsync.pass
hosts allow = 192.168.10.2
hosts deny = *
5.创建用户认证文件:
vim /home/rsync/rsync.pass
ruanqin/ruanqin
6.设置文件权限:
chmod 600 /home/rsync/rsyncd.conf
chmod 600 /home/rsync/rsync.pass
7.配置rsyncd.conf软链接:
ln -s /home/rsync/rsyncd.conf /etc/rsyncd.conf
8.重启xinetd服务:
service xinetd restart
###############server2###############
1.安装rsync和xinetd,并创建目录:
yum install rsync xinetd
mkdir -p /home/rsync/
mkdir -p /home/rsync/log/
mkdir -p /home/rsync/pid/
mkdir -p /home/rsync/run/
2.配置xinetd:
vi /etc/xinetd.d/rsync
#disable = yes修改为
disable = no
3.启动xinetd服务:
service xinetd start
4.创建认证密码文件:
vi /home/rsync/passwd.txt
ruanqin
5.执行同步脚本:
6.
7.任务计划每分钟执行一次:
crontab -e
*/1 * * * * /usr/bin/rsync -vzrtopg --progress --delete --password-file=/home/rsync/passwd.txt rsync@192.168.10.1::rsync /home/www/html