1. 安装rsync
yum install rsync
2. #touch /etc/rsyncd.conf #创建rsyncd.conf,这是rsync服务器的配置文件。
#touch /etc/rsyncd.secrets #创建rsyncd.secrets ,这是用户密码文件。
#chmod 600 /etc/rsyncd.secrets #将rsyncd.secrets这个密码文件的文件属性设为root拥有, 且权限要设为600, 否则无法备份成功!
#touch /etc/rsyncd.motd
3. rsyncd.conf配置文件
# Distributed under the terms of the GNU General Public License v2
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = 157.7.220.237
#uid = nobody
#gid = nobody
uid = root
gid = root
use chroot = yes
read only = yes
#limit access to private LANs
hosts allow=157.7.130.144
hosts deny=*
max connections = 5
#欢迎信息
motd file = /etc/rsyncd.motd
#This will give you a separate log file
#log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
#模块
[henniufiles]
path = /mnt/data
list=yes
ignore errors
auth users = root
secrets file = /etc/rsyncd.secrets
comment = This is RHEL 4 data
exclude = easylife/ samba/
4. 添加密码
vi /etc/rsyncd.secrets
输入密码:
root:mima
5. 修改文件属性
chown root.root /etc/rsyncd.secrets #修改属主
chmod 600 /etc/rsyncd.secrets #修改权限
6. 编辑欢迎信息
vi /etc/rsyncd.motd
输入:
++++++++++++++++++++++++++++++++++++++++++++++
Welcome to use the
www.xxxxxxxx.com
rsync services!
++++++++++++++++++++++++++++++++++++++++++++++
7. 设置服务端防火墙
两种方法:
a) service iptables stop
b) iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT
8. 启动服务
rsync --daemon --config=/etc/rsyncd.conf
在客户端同步服务端内容
新建密码文件touch password.pwd
在文件中输入密码mima
设置文件属性chmod 600 password.pwd (必须设置, 否则无法同步)
rsync -zrtopg --progress --delete --password-file=/data/password.pwd
[email protected]::henniufiles /mnt/data &
rsync -zrtopg --progress --delete --password-file=/data/www/pwd
[email protected]::henniufiles /data/www/xxxx.com &