Centos+Sersync+inotify实时同步数据文件(一)
公司有需要做线上设备的主备数据实时同步,其中有些注意事项,详细信息如下:
http://qiuyt.blog.51cto.com/1229789/1742977
1,Rsync:873
2,注意需要关闭iptables
3,实时查看sersync进程及rsync进程 是否正常运行
4,使用Sersync自动同步之前 使用rsync手动同步测试
5,rsync version 3.0.6system:Centos2.6.32-279.el6.x86_64
6,Master:192.168.1.202 ,Slave:192.168.1.206
1,检测系统环境是否支持
[root@Nagiosinotify-tools-3.14]#uname-mx86_64[root@Nagiosinotify-tools-3.14]#uname-r2.6.32-279.el6.x86_64
一、RSYNC Client Configuration
2,创建rsyncd.conf 配置文件,如果存在需要CP进行备份。
syncserver#createdbyqyt20160218#rsyncd.confstart#uid=rootgid=rootuserchroot=nomaxconnections=2000timeout=600podfile=/var/run/rsyncd.pidlockfile=/var/run/rsync.locklogfile=/var/log/rsyncd.logignoreerrorsreadonly=falselist=falsehostsallow=192.168.1.202/24hostsdeny=0.0.0.0/32authusers=rsync_backupsecretsfile=/etc/rsync.password###############################################[cfgs]comment=wwwbyqyt20160218path=/usr/local/nagios/etc/cfgs#################################################3[objects]comment=bbsbyqyt20160218path=/usr/local/nagios/etc/objects#################################################3EOF
3,创建相关待同步目录
mkdir-p/data0/www/bbs//data0/www/www//data0/www/blog/
(同时创建多个目录,也就是需要同步的目录,如果目录存在请忽略)
推送用户要有对被同步目录的写入更新的权限
3,认证
配置Password ,自行定义,[[ 但需要与/etc/rsyncd.conf 配置文件中secrets= * 定义内容相同 ]]
echo"rsync_backup:123">/etc/rsync.passwordchmod600/etc/rsync.password#forcheckcat/etc/rsync.passwordll/etc/rsync.password
4,配置好后,使用如下命令,开启rsync守护进程
rsync--daemonps-ef|greprsyncnetstat-lnt|grep873lsof-i:873
[root@Nagios/etc]$ps-ef|greprsyncroot20481017:52?00:00:00/usr/bin/rsync--daemonroot35442237019:24pts/000:00:00greprsync[root@Nagios/etc]$netstat-lnt|grep873tcp000.0.0.0:8730.0.0.0:*LISTENtcp00:::873:::*
5,设置开机自启动
echo"##rsyncservicedaemonbyqyt20160218">>/etc/rc.localecho"/usr/local/bin/rsync--daemon">>/etc/rc.localgrepdaemon/etc/rc.local
6,重启服务
pkillrsyncrsync--daemonps-ef|greprsync
二、Rsync Master Configuration
1,手动测试同步rsync(测试之前停掉防火墙 否则会引起失败)
2,在Master上配置rsync权限,只需要配置密码就OK了。
echo"123">/etc/rsync.passwordchmod600/etc/rsync.password#forcheckcat/etc/rsync.passwordll/etc/rsync.password
3,创建测试文件
touch/usr/local/nagios/etc/cfgs/cfgs.log/usr/local/nagios/etc/objects/objects.log
tree/usr/local/nagios/etc/├──cfgs│├──cfgs.log├──objects│├──objects.log
3,执行同步,手动执行
rsync -avzP /usr/local/nagios/etc/cfgs/ rsync_backup@192.168.1.206::cfgs/ --password-file=/etc/rsync.password
rsync -avzP /usr/local/nagios/etc/objects/ rsync_backup@192.168.1.206::objects/ --password-file=/etc/rsync.password
[root@Nagiosetc]#rsync-avzP/usr/local/nagios/etc/cfgs/rsync_backup@192.168.1.206::cfgs/--password-file=/etc/rsync.passwordsendingincrementalfilelist./cfgs.log0100%0.00kB/s0:00:00(xfer#1,to-check=4/11)sent312bytesreceived30bytes684.00bytes/sectotalsizeis87568speedupis256.05
4,然后去backup server(nagios02)上去验证,是否有同步过去的文件
[root@Nagios02/usr/local/nagios/etc]$tree├──cfgs│├──cfgs.log├──objects│├──objects.log成功
三、Sersync Configuration
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。