CentOS7下部署rsync服務
阿新 • • 發佈:2019-02-11
max nor dha only lin ystemd sel dbo ack
說明:
在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/ [email protected]::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
CentOS7下部署rsync服務