公司有需要做线上设备的主备数据实时同步 1,Rsync:873 2,注意需要关闭iptables 3,实时查看sersync进程及rsync进程 是否正常运行 4,使用Sersync自动同步之前 使用rsync手动同步测试 5,rsync version 3.0.6 system:Centos 2.6.32-279.el6.x86_64 6,Master:192.168.1.202 ,Slave:192.168.1.206
1,检测系统环境是否支持 1
2
3
4
| [iyunv@Nagios inotify-tools-3.14]# uname -m
x86_64
[iyunv@Nagios inotify-tools-3.14]# uname -r
2.6.32-279.el6.x86_64
|
一、RSYNC Client Configuration
2,创建rsyncd.conf 配置文件,如果存在需要CP进行备份。 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
| sync server
#created by qyt 20160218
#rsyncd.conf start#
uid = root
gid = root
user chroot = no
max connections = 2000
timeout = 600
pod file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 192.168.1.202/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
###############################################
[cfgs]
comment = www by qyt 20160218
path = /usr/local/nagios/etc/cfgs
#################################################3
[objects]
comment = bbs by qyt 20160218
path = /usr/local/nagios/etc/objects
#################################################3
EOF
|
3,创建相关待同步目录 1
| mkdir -p /data0/www/bbs/ /data0/www/www/ /data0/www/blog/
|
(同时创建多个目录,也就是需要同步的目录,如果目录存在请忽略)
推送用户要有对被同步目录的写入更新的权限
3,认证 配置Password ,自行定义,[[ 但需要与/etc/rsyncd.conf 配置文件中secrets= * 定义内容相同 ]] 1
2
3
4
5
| echo "rsync_backup:123" > /etc/rsync.password
chmod 600 /etc/rsync.password
#for check
cat /etc/rsync.password
ll /etc/rsync.password
|
4,配置好后,使用如下命令,开启rsync守护进程 1
2
3
4
| rsync --daemon
ps -ef|grep rsync
netstat -lnt|grep 873
lsof -i :873
|
1
2
3
4
5
6
| [iyunv@Nagios /etc]$ps -ef|grep rsync
root 2048 1 0 17:52 ? 00:00:00 /usr/bin/rsync --daemon
root 3544 2237 0 19:24 pts/0 00:00:00 grep rsync
[iyunv@Nagios /etc]$netstat -lnt|grep 873
tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN
tcp 0 0 :::873 :::*
|
5,设置开机自启动 1
2
3
| echo "##rsync service daemon by qyt 20160218" >>/etc/rc.local
echo "/usr/local/bin/rsync--daemon" >>/etc/rc.local
grep daemon /etc/rc.local
|
6,重启服务 1
2
3
| pkill rsync
rsync --daemon
ps -ef|grep rsync
|
二、Rsync Master Configuration
1,手动测试同步rsync(测试之前停掉防火墙 否则会引起失败)
2,在Master上配置rsync权限,只需要配置密码就OK了。 1
2
3
4
5
| echo "123" > /etc/rsync.password
chmod 600 /etc/rsync.password
#for check
cat /etc/rsync.password
ll /etc/rsync.password
|
3,创建测试文件 1
| touch /usr/local/nagios/etc/cfgs/cfgs.log /usr/local/nagios/etc/objects/objects.log
|
1
2
3
4
5
| tree /usr/local/nagios/etc/
├── cfgs
│ ├── cfgs.log
├── objects
│ ├── objects.log
|
3,执行同步,手动执行 rsync -avzP /usr/local/nagios/etc/objects/ rsync_backup@192.168.1.206::objects/ --password-file=/etc/rsync.password
1
2
3
4
5
6
7
| [iyunv@Nagios etc]# rsync -avzP /usr/local/nagios/etc/cfgs/ rsync_backup@192.168.1.206::cfgs/ --password-file=/etc/rsync.password
sending incremental file list
./
cfgs.log
0 100% 0.00kB/s 0:00:00 (xfer#1, to-check=4/11)
sent 312 bytes received 30 bytes 684.00 bytes/sec
total size is 87568 speedup is 256.05
|
4,然后去backup server(nagios02)上去验证,是否有同步过去的文件 1
2
3
4
5
6
| [iyunv@Nagios02 /usr/local/nagios/etc]$tree
├── cfgs
│ ├── cfgs.log
├── objects
│ ├── objects.log
成功
|
三、Sersync Configuration
|