说明:
在CentOS7下部署rsync服务和在CentOS6上部署基本上是一样的,只是CentOS7自带了rsyncd启动脚本,由systemd管理而已。
rsync服务端配置
[root@SERVER1 ~]# rpm -qa|grep rsync
rsync-3.0.9-17.el7.x86_64
[root@SERVER1 ~]# uname -r
3.10.0-514.el7.x86_64
[root@SERVER1 ~]# systemctl stop firewalld
[root@SERVER1 ~]# grep -i "selinux=" /etc/selinux/config
# SELINUX= can take one of these three values:
SELINUX=disabled
[root@SERVER1 ~]# rsync --version
rsync version 3.0.9 protocol version 30
[root@SERVER1 ~]# useradd -M -s /sbin/nologin rsync
[root@SERVER1 ~]# mkdir /data/test -p
[root@SERVER1 ~]# chown -R rsync.rsync /data/test
[root@SERVER1 ~]# vim /etc/rsyncd.conf
#rsync_configuration
##rsyncd.conf start##
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[test]
path = /data/test
ignore errors
read only = false
list = false
hosts allow = *
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#rsync_config_______________end
[root@SERVER1 ~]# echo 'rsync_backup:123456' >/etc/rsync.password
[root@SERVER1 ~]# chmod 600 /etc/rsync.password
[root@SERVER1 ~]# systemctl restart rsyncd
[root@SERVER1 ~]# ss -lntup|grep rsync
tcp LISTEN 0 5 *:873 *:* users:(("rsync",pid=7631,fd=4))
tcp LISTEN 0 5 :::873 :::* users:(("rsync",pid=7631,fd=5))
客户端配置
[root@opvnserver ~]# uname -r 3.10.0-862.el7.x86_64 [root@opvnserver ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@opvnserver ~]# systemctl stop firewalld [root@opvnserver ~]# grep -i "selinux=" /etc/selinux/config # SELINUX= can take one of these three values: SELINUX=disabled [root@opvnserver ~]# rsync --version rsync version 3.1.2 protocol version 31 [root@opvnserver ~]# echo '123456' >/etc/rsync.password [root@opvnserver ~]# chmod 600 /etc/rsync.password
验证同步成功
[root@opvnserver ~]# ll /tmp/ 总用量 8 drwx------ 2 oldboy oldboy 24 1月 25 19:31 ssh-i8u7DI17TF drwx------ 2 oldboy oldboy 24 1月 24 17:33 ssh-Q7DZur3rIP drwx------ 2 root root 6 1月 25 20:04 vmware-root -rw------- 1 root root 8054 1月 24 17:35 yum_save_tx.2019-01-24.17-35.v9YeIo.yumtx [root@opvnserver ~]# rsync -avz /tmp/ rsync_backup@14.18.36.97::test --password-file=/etc/rsync.password [root@SERVER1 ~]# ll /data/test/ 总用量 20 drwx------ 2 rsync rsync 4096 1月 25 19:31 ssh-i8u7DI17TF drwx------ 2 rsync rsync 4096 1月 24 17:33 ssh-Q7DZur3rIP drwx------ 2 rsync rsync 4096 1月 25 20:04 vmware-root -rw------- 1 rsync rsync 8054 1月 24 17:35 yum_save_tx.2019-01-24.17-35.v9YeIo.yumtx
CentOS7中由systemd管理的rsyncd脚本内容
[root@SERVER1 ~]# cat /usr/lib/systemd/system/rsyncd.service
[Unit]
Description=fast remote file copy program daemon
ConditionPathExists=/etc/rsyncd.conf
[Service]
EnvironmentFile=/etc/sysconfig/rsyncd
ExecStart=/usr/bin/rsync --daemon --no-detach "$OPTIONS" #<===此选项意思是rsync不将自己从终端上剥离
[Install]
WantedBy=multi-user.target