Centos7.5搭建rsync同步工具

rsync服务端:172.31.97.106

rsync客户端:172.31.97.28

 

 

一、服务端安装配置

1、安装rsync服务

rpm -qa |grep rsync  #查看是否已安装rsync

yum -y install rsync

#启动rsync服务

systemctl start rsyncd.service    #rsync –daemon 这种方式启动也可
systemctl enable rsyncd.service       #echo "rsync --daemon" >> /etc/rc.local加入开机自启

#检查是否已经成功启动

netstat -lnp|grep :873    #默认是873端口,我这里把服务端改成878

 

2、配置rsync服务

[root@master-1 video]# cat /etc/rsyncd.conf

# /etc/rsyncd: configuration file for rsync daemon mode

# See rsyncd.conf man page for more options.

# configuration example:

# uid = nobody

# gid = nobody

# use chroot = yes

# max connections = 4

# pid file = /var/run/rsyncd.pid

# exclude = lost+found/

# transfer logging = yes

# timeout = 900

# ignore nonreadable = yes

# dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2

# [ftp]

#        path = /home/ftp

#        comment = ftp export area

port = 878     #修改默认端口

uid = root

gid = root

use chroot = no

max connections = 200

timeout = 300

motd file = /var/rsyncd/rsync.motd

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log

dont compress = *.gz *.tgz *.z *.Z *.rpm *.deb *.bz2 *.zip   #这类文件不做二次压缩

[ats]

path = /data/ats/video    #需要同步资源的存放目录

ignore errors

read only = false

write only = false

list = false

hosts allow = 172.31.97.0/24

hosts deny = 0.0.0.0/32

auth users = root  #增加同步时用户认证,需要输入密码

secrets file = /etc/rsyncd.passwd

[root@master-1 video]#

3、给rsync定义身份

如下:

echo 'root:123456'>/etc/rsyncd.passwd   //文件用户名和路径为上面定义,别写错,密码自己定

chmod 600 /etc/rsyncd.passwd        //修改权限

最后重启:

systemctl restart rsyncd.service

 

二、客户端配置

yum -y install rsync  
#启动rsync服务
systemctl start rsyncd.service     # rsync –daemon 这种方式启动也可
systemctl enable rsyncd.service   # echo "rsync --daemon" >> /etc/rc.local加入开机自启
#检查是否已经成功启动
netstat -lnp|grep :873
创建密码
echo '123456' >>/etc/rsyncd.passwd     //注意这里只需要服务器rsyncd.passwd 中的密码
chmod 600 /etc/rsyncd.passwd

三、测试验证

1、在客户端上进行验证

rsync -rlptD /root/bethune.zip rsync://root@172.31.97.106:878/ats/

 

在服务端进行查看,已同步完成

 

2、如果想同步时不加鉴权可在服务端/etc/rsyncd.conf将截图中注释然后重启rsync即可。

 

3、最后可将同步命令写成一个脚本,在添加到crontab定时任务中,让他定时同步就行

 

crontab -e

至此rsync同步工具部署完毕。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值