CentOS7下部署rsync服务

Posted blog-tim

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CentOS7下部署rsync服务相关的知识,希望对你有一定的参考价值。

说明:

在CentOS7下部署rsync服务和在CentOS6上部署基本上是一样的,只是CentOS7自带了rsyncd启动脚本,由systemd管理而已。

rsync服务端配置
[[email protected] ~]# rpm -qa|grep rsync
rsync-3.0.9-17.el7.x86_64
[[email protected] ~]# uname -r
3.10.0-514.el7.x86_64
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# grep -i "selinux=" /etc/selinux/config 
# SELINUX= can take one of these three values:
SELINUX=disabled
[[email protected] ~]# rsync --version
rsync version 3.0.9 protocol version 30
[[email protected] ~]# useradd -M -s /sbin/nologin rsync
[[email protected] ~]# mkdir /data/test -p
[[email protected] ~]# chown -R rsync.rsync /data/test
[[email protected] ~]# 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

[[email protected] ~]# echo ‘rsync_backup:123456‘ >/etc/rsync.password
[[email protected] ~]# chmod 600 /etc/rsync.password
[[email protected] ~]# systemctl restart rsyncd
[[email protected] ~]# 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))

 

客户端配置

[[email protected] ~]# uname -r
3.10.0-862.el7.x86_64
[[email protected] ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core)
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# grep -i "selinux=" /etc/selinux/config 
# SELINUX= can take one of these three values:
SELINUX=disabled
[[email protected] ~]# rsync --version
rsync version 3.1.2 protocol version 31
[[email protected] ~]# echo ‘123456‘ >/etc/rsync.password
[[email protected] ~]# chmod 600 /etc/rsync.password

验证同步成功

[[email protected] ~]# 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

[[email protected] ~]# rsync -avz /tmp/ [email protected]::test --password-file=/etc/rsync.password

[[email protected] ~]# 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脚本内容

[[email protected] ~]# 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服务的主要内容,如果未能解决你的问题,请参考以下文章

CentOS7下rsync服务的基本详解和使用

CentOS7.5下开发systemctl管理的自定义Rsync启动服务程序

Centos7 下 配置 rsync 以及 rsync+inotify 实时同步

CentOS7.5下开发systemctl管理的自定义Rsync启动服务程序

部署nfs高可用rsync+inotify

centos7 inotify与rsync实现实时同步服务搭建