rsync服务-部署配置与维护

注意点

  1. 服务器以rsync-daemon是否开启作为判断,该服务器是否为服务端
  2. 搞清楚是以哪个为同步基准(服务端|客户端)

环境

系统 IP 软件 同步路径 备注
服务器centos 7 192.168.153.140 rsync-3.0.9-17.el7.x86_64 /data/images 防火墙关闭或打开相应端口
客户端centos 7 192.168.153.130 rsync-3.0.9-17.el7.x86_64 inotify /data/images 防火墙关闭或打开相应端口

示例搭建:以服务端为基准拉取至客户端

服务器端操作步骤

  1. rsync安装
]# rpm -qa |grep rsync #检查rsync是否安装,有输出则已安装,无则安装
rsync-3.0.9-17.el7.x86_64
]# yum install rsync -y #yum方式安装rsync
  1. 创建备份用户和需要同步的目录
]# vim /etc/rsyncd_users.db
baker:123456
]# chmod 600 /etc/rsyncd_users.db #仅限自己查看
]# mkdir -p /opt/images
  1. 修改rsyncd.conf配置文件
]# vim /etc/rsyncd.conf
 uid = root	#控制传输到目标服务器后文件的属主
 gid = root	#控制传输到目标服务器后文件的属组
 use chroot = yes       #禁锢在源目录
 address = 192.168.153.140  #监听地址,可省略,多块网卡可指定一块启动
 port 873               #监听端口,可省略,默认873
 fake super = yes
 max connections = 200	#最大连接个数
 log file = /var/log/rsyncd.log #日志文件位置
 pid file = /var/run/rsyncd.pid #存放进程ID的文件位置
 hosts allow = 192.168.153.0/24 #允许访问的客户机地址
 dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2  #同步时不再压缩的文件类型

[images]             #共享模块名称
 path = /opt/images #源目录的实际路径
 comment = image 
 read only = false	#是否为只读
 auth users = baker  #授权账户
 secrets file = /etc/rsyncd_users.db  #存放账户信息的数据文件
  1. 启动rsync服务
]# rsync --daemon
]# ss -tnlp |grep 873 #检查端口状态
LISTEN     0      5            *:873                      *:*                   users:(("rsync",pid=22671,fd=4))
LISTEN     0      5         [::]:873                   [::]:*                   users:(("rsync",pid=22671,fd=5))

客户端操作步骤

  1. rsync安装
  2. 创建同步路径
  3. 配置rsync服务同步密码文件
]# vim /etc/baker.pass
123456
]# chmod 600 /etc/baker.pass
  1. 同步
]# rsync -az --delete --password-file=/etc/baker.pass baker@192.168.153.140::images /data/images

centos7使用systemctl start rsyncd和直接使用rsync --daemon启动,会出现权限不一样的问题,暂未查出原因

参考文档:

  1. rsync
posted @ 2020-08-02 18:48  wanwz  阅读(199)  评论(0)    收藏  举报