服务端
[root@junwu_server /]# cat rsync_server.sh #!/bin/bash yum install rsync -y echo \ "uid = rsync gid = rsync fake super = yes use chroot = no max connections = 200 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsyncd.log ignore errors read only = false list = false hosts allow = 10.0.0.15/24 auth users = rsync_user secrets file = /etc/rsync.password [backup] comment = This is rsync backup! path = /backback/ " \ >> /etc/rsyncd.conf useradd -s /sbin/nologin -M rsync mkdir /backback chown -R rsync.rsync /backback echo "rsync_user:123456" > /etc/rsync.password chmod 600 /etc/rsync.password systemctl restart rsyncd && systemctl enable rsyncd
客户端
[root@junwu_client /]# cat rsync_client.sh #!/bin/bash yum install rsync -y echo "123456" > /etc/rsync.password echo "export RSYNC_PASSWORD=123456" >> /etc/bashrc systemctl start rsyncd touch /tmp/rsync部署成功.txt rsync -acz /tmp/rsync部署成功.txt rsync_user@10.0.0.10::backup
遇到的问题:
1)bind() failed: Address already in use (address-family 2)
此问题是因为在脚本中启动rsync服务时的命令:systemctl start rsyncd 该服务已经启动了,便不能再启动
脚本中应改成:systemctl restart rsyncd
2)echo "export RSYNC_PASSWORD=123456" >> /etc/bashrc 该变量的作用是什么? 客户端写入该变量RSYNC_PASSWORD后,为什么rsync传输文件时不需要输入密码了?