1.部署rsync=inotify同步/etc目标服务器的/wzy/下。
实验环境:
主机名称 | 操作系统 | 角色 | ip地址 |
---|---|---|---|
@bogon | RHEL 7 | 源服务器 | 192.168.168.37 |
@client | RHEL 7 | 目标服务器 | 192.168.43.199 |
*关闭防火墙和selinux
[[email protected] ~]# systemctl start firewalld.service
[[email protected] ~]# systemctl enable firewalld.service
[[email protected] ~]# setenforce 0
[[email protected] ~]# systemctl start firewalld.service
[[email protected] ~]# systemctl enable firewalld.service
[[email protected] ~]# setenforce 0
#目标服务端操作:
1.安装rsync服务端软件:
[[email protected] ~]# yum -y install rsync
2配置rsyncd.conf配置文件
[[email protected] ~]# cat >> /etc/rsyncd.conf << EOF
log file = /var/log/rsyncd.log
pidfile = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
secrets file = /etc/users
[wuzhiyong]
path = /tmp/wzy
comment = sync etc from server
uid = root
gid = root
port = 873
ignore errors
use chroot = no
read only = no
list = no
max connections = 200
timeout = 600
auth users = wzy
EOF
3创建用户认证文件,并设置文件权限:
[[email protected] ~]# echo ‘wzy:123456’ > /etc/users
[[email protected] ~]# cat /etc/users
wzy:123456
[[email protected] ~]# chmod 600 /etc/users
[[email protected] ~]# ll /etc/users
-rw-------. 1 root root 11 Sep 18 23:57 /etc/users
4.启动rsync服务并设置开机自动启动:
[[email protected] ~]# systemctl start rsyncd
[[email protected] ~]# systemctl enable rsyncd
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :22 :
LISTEN 0 100 127.0.0.1:25 :
LISTEN 0 5 :873 :
LISTEN 0 128 :::22 :::
LISTEN 0 100 ::1:25 :::
LISTEN 0 5 :::873 :::
*源服务器上进行的操作:
1.安装rsync,inotify-tools。只需要安装不需要启动和配置
[[email protected] ~]# yum -y install rsync inotify-tools
2配置yum源
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2018-09-18 10:41:58-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
正在解析主机 mirrors.163.com (mirrors.163.com)... 59.111.0.251
正在连接 mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1572 (1.5K) [application/octet-stream]
正在保存至: “CentOS7-Base-163.repo”
100%[================================>] 1,572 --.-K/s 用时 0s
2018-09-18 10:41:59 (52.8 MB/s) - 已保存 “CentOS7-Base-163.repo” [1572/1572])
[[email protected] yum.repos.d]# echo $?
0
[[email protected] yum.repos.d]# ls
CentOS7-Base-163.repo CentOS-Base.repo epel.repo redhat.repo
[[email protected] yum.repos.d]# sed -i ‘s/\$releaserver/7/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo
[[email protected] yum.repos.d]# sed -i ‘s/^enabled=.*/enabled=1/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo
[[email protected] yum.repos.d]# yum -y install epel-release
3创建认证密码文件,并设置其权限为600:
[[email protected] ~]# cat /etc/rsync.pass
123456
[email protected] ~]# chmod 600 /etc/rsync.pass
[[email protected] ~]#
4.在服务端创建测试目录:
[[email protected] yum.repos.d]# mkdir /wzy
[ro
[email protected] tmp]# mkdir /wzy/haha
*进行数据同步:
[[email protected] wzy]# rsync -avH --port 873 --progress --delete /wzy [email protected]::wuzhiyong --password-file=/etc/rsync.pass
sending incremental file list
wzy/
wzy/haha/
sent 81 bytes received 27 bytes 72.00 bytes/sec
total size is 0 speedup is 0.00
*在目标服务器验证查看:
[[email protected] wzy]# cd /tmp/wzy
[[email protected] wzy]# ls
ha
ha wzy
[[email protected] wzy]#
原文地址:http://blog.51cto.com/13945839/2177951
时间: 2024-10-09 18:06:46