Rsync 搭建

介绍:rsync是linux服务器之前做数据同步用的一种工具;


RSYNC配置
系统环境:Centos6.6


IP host
192.168.56.21 server
192.168.56.22 client

配置rsync-server:


[root@salt1 etc] yum install -y rsync

[root@salt1 etc]touch rsyncd.conf

[root@salt1 etc]# vim /etc/rsyncd.conf

pid file = /var/run/rsyncd.pid
port = 873
uid = root
gid = root
usechroot = yes
read only = yes
hosts allow=*
hosts deny=*
max connections = 5
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300

[test_rsync]
path = /tools/test
list=yes
read only = no
auth users = test1
secrets file = /etc/rsyncd.secrets
ignore errors


[update]
path = /tools/push_data_ftp/test
list=yes
read only = no
auth users = test1
secrets file = /etc/rsyncd.secrets
ignore errors

[root@salt1 etc]# touch /etc/rsyncd.secrets
[root@salt1 etc]# echo "test1:test123" > /etc/rsyncd.secrets
[root@salt1 etc]# chmod 600 /etc/rsyncd.secrets

启动服务:


[root@salt1 etc]# /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
或service xinetd restart

[root@salt1 test]# lsof -i:873
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsync 26835 root 4u IPv4 53430 0t0 TCP *:rsync (LISTEN)
rsync 26835 root 5u IPv6 53431 0t0 TCP *:rsync (LISTEN)


Rsync-client:


创建密码文件
[root@salt2 yum.repos.d]# touch /etc/rsyncd.secrets
[root@salt2 yum.repos.d]# echo "test123" > /etc/rsyncd.secrets
[root@salt2 etc]# chmod 600 /etc/rsyncd.secrets

环境测试

Rsync客户端测试:
[root@salt2 /]mkdir -p /zw/test/
[root@salt2 /]# mkdir -p /zw/test/
[root@salt2 /]# cd /zw/test/
[root@salt2 test]# touch aaa.txt
[root@salt2 test]# ls
aaa.txt

[root@salt2 /]rsync -av --password-file=/etc/rsyncd.secrets /zw/test/ [email protected]::test_rsync
[root@salt2 /]rsync -av --password-file=/etc/rsyncd.secrets /zw/test/ [email protected]::update

注释:使用 --password-file=/etc/rsyncd.secrets 密码验证,把/zw/test/ 目录下的文件同步到test1用户下的 192.168.56.21 这台主机的 ,test_rsync目录下

rsync服务端:完成后查看该路径下有没有文件同步过来,如果有,同步成功!
/tools/test
/tools/push_data_ftp/test

你可能感兴趣的:(自动化运维)