上接前文,前文提到web服务器附件不同步的问题,这里补上文件同步的配置。
安装同步软件
# 安装同步服务所需的软件
yum -y install rsync
配置密码本
mkdir -p /etc/rsyncfg/
# 注意:下面的两个SyncPwd必须一致
echo ‘SyncName:SyncPwd’ > /etc/rsyncfg/server.pwd
echo ‘SyncPwd’ > /etc/rsyncfg/client.pwd
# 密码文件配置权限
chmod 600 /etc/rsyncfg/server.pwd
chmod 600 /etc/rsyncfg/client.pwd
配置防火墙端口
# 开启防火墙端口
firewall-cmd –zone=public –add-port=873/tcp –permanent
firewall-cmd –reload
配置同步软件
# 编辑配置文件
vim /etc/rsyncd.conf
# 配置文件内容
uid = root
gid = root
use chroot = yes
max connections = 4
exclude = lost+found/
transfer logging = yes
timeout = 900
ignore nonreadable = yes
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
[uploads]
path = /home/wwwroot/PublishPath/uploads
comment = Host:192.168.6.100 uploads files
ignore errors
read only = yes
write only = no
list = no
auth users = syncer
secrets file = /etc/rsyncfg/server.pwd
hosts allow = 192.168.6.110
重启服务
service rsyncd restart && service rsyncd status
执行同步操作
echo ” > /etc/rsyncfg/sync.log
echo ‘rsync -auv –password-file=/etc/rsyncfg/client.pwd SyncName@192.168.6.100::uploads /home/wwwroot/PublishPath/uploads/’ > /etc/rsyncfg/sync.sh
chmod +x /etc/rsyncfg/sync.sh
cp /etc/rsyncfg/sync.sh /usr/sbin/
配置计划任务
crontab -e
# 添加任务
# * * * * * /etc/rsyncfg/sync.sh # 取消前面的注释即可
# 重启定时任务服务
service crond restart && service crond status
问题汇总
ERROR: auth failed on module XXX
@ERROR: auth failed on module XXX
rsync error: error starting client-server protocol (code 5) at main.c(xxx) [Receiver=x.x.x]
1、密码输入错误:
请再次确认你登录用户的密码无误
2、secrets file格式错误:
secrets file的文件格式是 upload:123456
表示upload用户的rsync密码是123456
3、配置文件写错:
最坑爹的一个,看看自己模块配置下面的auth users、secrets file有没写错
4、secrets file权限问题
服务端的secrets file权限必须是600,
可以使用chmod 600 /home/user/test/rsync/etc/test.pass
5、secrets file文件拥有者与rsync运行者
服务端rsync服务是以什么用户运行,则必须保证secrets file文件拥有者必须是同一个
假设root运行rsync –daemon,则secrets file的owner也必须是root
6、如果是以–password-file=file的方式附带密码
确保客户端密码文件格式无误,与服务端的密码文件不同,
客户端的不用加上用户名,即直接是 123456
rsync: failed to connect to X.X.X.X Connection timed out (110)
rsync: failed to connect to 192.168.6.100 (192.168.6.100): Connection timed out (110)
rsync error: error in socket IO (code 10) at clientserver.c(125) [Receiver=3.1.2]
端口不通,开启防火墙的873端口:
firewall-cmd –zone=public –add-port=873/tcp –permanent
firewall-cmd –reload
ERROR: password file must not be other-accessible
ERROR: password file must not be other-accessible
rsync error: syntax or usage error (code 1) at authenticate.c(196) [Receiver=3.1.2]
密码本权限不对:
chmod 600 /etc/rsyncfg/server.pwd
chmod 600 /etc/rsyncfg/client.pwd
发表回复