设为首页 收藏本站
查看: 401|回复: 0

[经验分享] linux多服务器之间的目录文件同步

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-3-28 11:06:28 | 显示全部楼层 |阅读模式
web1:10.80.11.243
web2:10.80.11.244
code:10.80.11.245
更新code服务器的代码后,自动同步到web1和web2,删除code服务器文件,web1和web2也删除
服务器端的安装(N台WEB都这样配置)
1、首先要求Linux内核在2.6以上,才支持inotify
[iyunv@web1 html]# uname -a
Linux web1 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux
2、检查是否安装rsync软件
[iyunv@web1 html]# rpm -qa |grep rsync
rsync-2.6.8-3.1
如果没有的话,通过yum –y install rsync安装
3、新建rsync配置文件,该软件安装默认没有配置文件
#vim /etc/rsyncd.conf
motd file = /etc/rsyncd.motd
uid=root
gid=root
max connections=36000
use chroot=no
log file=/var/log/rsyncd.log
log format =  %t %a %m %f %b
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
timeout = 300


[tongbu]
path=/var/www/html
list=yes
comment = this is comment
ignore errors = yes
read only = no
hosts allow = 10.80.11.245
hosts deny = *
auth users backup
secrets file = /etc/rsyncd.secrets
注:tongbu为发布模块,相当于路径的别名
hosts allow是只允许连接的IP
secrets file = /etc/rsyncd.secrets
这是密码文件,同步的用户为backup,下面创建同步用户
#useradd backup
#passwd backup
#vim /etc/rsyncd.secrets
backup:123456
格式为
用户名:密码
#chmod 600 /etc/rsyncd.secrets
设置只有root用户才能查看这个文件
4、启动服务
/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
其他的WEB服务器配置和上面是一样的。如果需要开机启动,加入到/etc/rc.local


发布端的配置
1、发布端主要利用开源软件sersync,网站为:http://code.google.com/p/sersync/
#cd /usr/local/
#wget http://sersync.googlecode.com/fi ... 32bit_binary.tar.gz
#tar –zxvf sersync2.5RC1_32bit_binary.tar.gz
#cd GNU-Linux-x86
2、修改配置文件
#vim confxml.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <filter start="false">
         <exclude expression="(.*)\.gz"></exclude>
         <exclude expression="^info/*"></exclude>
    </filter>
    <inotify>
         <delete start="true"/>
         <create start="true"/>
    </inotify>
    <debug start="false"/>
    <sersync>
         <localpath watch="/var/www/html">
             <remote ip="10.80.11.243" name="tongbu"/>
             <remote ip="10.80.11.244" name="tongbu"/>
         </localpath>
         <rsync>
             <auth start="true" users="backup" passwordfile="/etc/rsync.pas"/>
             <userDefinedPort start="false" port="874"/><!-- port=874 -->
             <timeout start="false" time="100"/><!-- timeout=100 -->
             <ssh start="false"/>
         </rsync>
         <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60min execute once-->
         <crontab start="false" schedule="600"><!--600mins-->
             <crontabfilter start="false">
                   <exclude expression="*.php"></exclude>
                   <exclude expression="info/*"></exclude>
             </crontabfilter>
         </crontab>
         <plugin start="false" name="command"/>
    </sersync>

    <plugin name="command">
         <param prefix="/bin/sh" suffix="" ignoreError="true"/>        <!--prefix /opt/tongbu/mmm.sh suffix-->
         <filter start="false">
             <include expression="(.*)\.php"/>
             <include expression="(.*)\.sh"/>
         </filter>
    </plugin>

    <plugin name="socket">
         <localpath watch="/opt/tongbu">
             <deshost ip="192.168.138.20" port="8009"/>
         </localpath>
    </plugin>
    <plugin name="refreshCDN">
         <localpath watch="/data0/htdocs/cms.xoyo.com/site/">
             <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
             <sendurl base="http://pic.xoyo.com/cms"/>
             <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
         </localpath>
    </plugin>

</head>
/var/www/html为发布服务器的源码发布目录
主要修改红色标记部分,密码文件为/etc/rsync.pas
#vim /etc/rsync.pas
123456#
解释:123456代表的是Rsync server端的密码,并且要以"#"做结尾。如果有多个密码,增加多行就行。
#chmod 600 /etc/rsync.pas
3、启动服务
#./sersync2 -d –r
这种方式常驻进程,如果需要开机启动,加入到/etc/rc.local

这样只要修改发布服务器/var/www/html的文件,web服务器就会自动同步。


**********************************************************************************************************
附录二:rsyncd.onf文件注释
全局参数
uid = root//运行RSYNC守护进程的用户
gid = root//运行RSYNC守护进程的组
use chroot = no //不使用chroot
max connections = 4 // 最大连接数为4
strict modes =yes//是否检查口令文件的权限
port = 873//默认端口873

模块参数
[backup] //这里是认证的模块名,在client端需要指定
path = /home/backup///需要做镜像的目录,不可缺少!
comment = This is a test //这个模块的注释信息
ignore errors//可以忽略一些无关的IO错误
read only = yes// 只读
list = no //不允许列文件
auth users = hening //认证的用户名,如果没有这行则表明是匿名,此用户与系统无关
secrets file = /etc/rsync.pas //密码和用户名对比表,密码文件自己生成
hosts allow = 192.168.1.1, 10.10.10 .10//允许主机
hosts deny = 0.0.0 .0/0 //禁止主机
#transfer logging = yes

注释:下面这些绿色文件是安装完RSYNC服务后自动生成的文件
pid file = /var/run/rsyncd.pid//pid文件的存放位置
lock file = /var/run/rsync.lock //锁文件的存放位置
log file = /var/log/rsyncd.log//日志记录文件的存放位置


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-16405-1-1.html 上篇帖子: linux shell 删除重复文件只保留一份 下篇帖子: Linux虚拟机文件系统突然变成只读 服务器 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表