1、网络拓扑图
2、 环境部署准备
192.169.59.17 M-server
192.168.59.14 s1-server
192.168.59.15 s2-server
1、检查系统环境变量
[root@M-server ~]# cat /etc/redhat-release CentOS release 6.6 (Final) [root@M-server ~]# uname -r2.6.32-504.el6.x86_64 [root@M-server ~]# uname -mx86_64
2、在S1和S2服务器创建rsyncd.conf配置文件
vim /etc/rsyncd.conf
#Rsync server#created by lx 15:01 2009-6-5##rsyncd.conf start##uid = root gid = root use chroot = no max connections = 2000timeout = 600pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.log ignore errors read only = false list = false hosts allow = 10.0.0.0/24 hosts deny = 0.0.0.0/32 auth users = rsync_backup secrets file = /etc/rsync.password ##################################### [www] comment = www by lx 14:18 2012-1-13 path = /data0/www/www/ ##################################### [bbs] comment = bbs by lx 14:18 2012-1-13 path = /data0/www/bbs/ ##################################### [blog] comment = blog by lx 14:18 2012-1-13 path = /data0/www/blog/
3、创建目录
mkdir -p /data0/www/{www,bbs,blog}
4、设置相关权限认证
echo "rsync_backup:oldboy" >/etc/rsync.password chmod 600 /etc/rsync.password 检查权限是否正确 cat /etc/rsync.password ll /etc/rsync.password
5、开启rsync守护进程
rsync --daemonps -ef|grep rsync lsof -i tcp:873
6、将rsync服务加入开机自启动
echo "/usr/local/bin/rsync --daemon" >>/etc/rc.local
7、重启rsync
pkill rsync rsync --daemon
8、 在Master上配置rsync权限
echo “oldboy” >/etc/rsync.password chmod 600 /etc/rsync.password 检查 cat /etc/rsync.password ll /etc/rsync.password
9、 在Master上手工测试rsync同步情况
mkdir -p /data0/www/{www,bbs,blog} touch /data0/www/www/www.log /data0/www/bbs/bbs.log /data0/www/blog/blog.log 手动测试,执行同步命令 rsync -avzP /data0/www/www/ rsync_backup@192.168.59.14::www/ --password-file=/etc/rsync.password rsync -avzP /data0/www/www/ rsync_backup@192.168.59.15::www/ --password-file=/etc/rsync.password rsync -avzP /data0/www/bbs/ rsync_backup@192.168.59.14::bbs/ --password-file=/etc/rsync.password rsync -avzP /data0/www/bbs/ rsync_backup@192.168.59.15::bbs/ --password-file=/etc/rsync.password rsync -avzP /data0/www/blog/ rsync_backup@192.168.59.14::blog/ --password-file=/etc/rsync.password rsync -avzP /data0/www/blog/ rsync_backup@192.168.59.15::blog/ --password-file=/etc/rsync.password
10. 在Master安装sersync
cd /server/tools tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/localcd /usr/local/ mv GNU-Linux-x86/ sersyncmkdir -p bin config logs mv confxml.xml conf/ mv sersync2 bin/sersync /bin/cp conf/confxml.xml conf/confxml.xml$(date +%F) #备份配置文件cd conf/
11、 修改配置文件,将第24-28行内容删除掉,换成下面内容
<localpath watch="/data0/www/www"> <remote ip="192.168.59.14" name="www"/> <remote ip="192.168.59.15" name="www"/> </localpath> <!-- ################################### --> <localpath watch="/data0/www/bbs"> <remote ip="192.168.59.14" name="bbs"/> <remote ip="192.168.59.15" name="bbs"/> </localpath> <!-- ################################### --> <localpath watch="/data0/www/blog"> <remote ip="192.168.59.14" name="blog"/> <remote ip="192.168.59.15" name="blog"/> </localpath> 修改38-44行,认证部分 将<auth start="false" users="root" passwordfile="/etc/rsync.pas"/> 修改为<auth start="true" users="rsync_backup" passwordfile="/etc/rsync.password"/> 将<timeout start="false" time="100"/><!-- timeout=100 --> 修改为<timeout start="true" time="100"/><!-- timeout=100 --> 修改45行 将<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once--> 修改为<failLog path="/usr/local/sersync/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->保存退出 wq!
12、 开启sersync守护进程同步数据
先配置sersync环境变量
echo 'export PATH=$PATH:/usr/local/sersync/bin' >>/etc/profile
tail -1 /etc/profile
source /etc/profile
启动命令:
sersync -r -d -o /usr/local/sersync/conf/confxml.xml
参数:
-o:指定配置文件,如果不指定他默认是二进制下的配置文件
-d:后台运行
-r:主服务器和备服务器可能两边数据不一致,-r表示数据初始化一次,保证数据一致
启动的过程及结果
set the system param execute:echo 50000000 > /proc/sys/fs/inotify/max_user_watches execute:echo 327679 > /proc/sys/fs/inotify/max_queued_events parse the command paramoption: -r rsync all the local files to the remote servers before the sersync work option: -d run as a daemon option: -o config xml name: /usr/local/sersync/conf/confxml.xml daemon thread num: 10 parse xml config file host ip : localhost host port: 8008 daemon start,sersync run behind the console config xml parse success please set /etc/rsyncd.conf max connections=0 Manually sersync working thread 12 = 1(primary thread) + 1(fail retry thread) + 10(daemon sub threads) Max threads numbers is: 32 = 12(Thread pool nums) + 20(Sub threads) please according your cpu ,use -n param to adjust the cpu rate ------------------------------------------ rsync the directory recursivly to the remote servers once working please wait... execute command: cd /data0/www/www && rsync -artuz -R --delete ./ 192.168.59.14::www >/dev/null 2>&1
13、 切换到sersync配置文件目录下
cd /usr/local/sersync/conf
cp confxml.xml www_confxml.xml
编辑www_confxml.xml,保留www模块,删除bbs 和 blog模块
cp confxml.xml bbs_confxml.xml
编辑bbs_confxml.xml,保留bbs模块,删除www和blog模块
cp confxml.xml blog_confxml.xml
编辑blog_confxml.xml模块,保留blog模块,删除www和bbs模块
14、多实例初始化同步命令:
sersync -r -d -o /usr/local/sersync/conf/www_confxml.xml sersync -r -d -o /usr/local/sersync/conf/bbs_confxml.xml sersync -r -d -o /usr/local/sersync/conf/blog_confxml.xml cat>>/etc/rc.local<<EOF sersync -d -o /usr/local/sersync/conf/www_confxml.xml sersync -d -o /usr/local/sersync/conf/bbs_confxml.xml sersync -d -o /usr/local/sersync/conf/blog_confxml.xml EOF
参考:http://liubao0312.blog.51cto.com/2213529/1677586
本文转自yzy121403725 51CTO博客,原文链接:http://blog.51cto.com/lookingdream/1826691,如需转载请自行联系原作者