使用root用户安装配置,10.58.2.4、10.158.2.4安装配置方式一样,其中rsync为centos默认安装过了,可以先行检查,如果没有安装则使用如下方式进行安装,已经安装则跳过安装步骤进行配置即可。
1、安装配置rsync用于同步
shell>
yum install -y rsync
2、创建rsyncd.conf配置文件
shell>
vim /etc/rsyncd.conf
输入如下内容:
uid = xxxx #备份以什么身份进行,用户ID
gid = root #备份以什么身份进行,组ID
use chroot = no #禁锢在源目录
max connections = 36000
#最大连接数,0代表没有限制
strict modes = yes #是否检查口令文件的权限
log file =/var/log/rsyncd.log #日志记录文件
pid file =/var/run/rsyncd.pid #运行进程的PID文件
lock file =/var/run/rsyncd.lock #运行进程的LOCK文件
[tongbu] #指定认证的备份模块名,后续sersync配置中会用到
comment = web files
path =/app/xxxx/tomcat8.0.24/webapps/xxxx-portal/upload #需要备份的目录的路径
ignore errors = yes #忽略一些无关的IO错误
read only = no #设置为no,即可以传至服务器的相应目录
write only = no #设置为no,表示客户端可以下载文件
auth users = xxxx #连接模块的用户名
secrets file =/etc/rsyncd.pwd #连接模块用户名的密码文件存储路径
3、创建用户认证文件
shell>
vim /etc/rsyncd.pwd
输入如下内容:
用户名:密码#注意:该用户名密码为:本机的用户名密码
4、设置文件权限
shell>
chmod 600 /etc/rsyncd.conf #设置文件所有者读取、写入权限
chmod 600 /etc/rsyncd.pwd #设置文件所有者读取、写入权限
2 安装配置sersync用于监控指定目录文件变化并触发同步
使用root用户安装配置sersync用于监控指定目录文件变化并触发同步
1、上传sersync安装包
shell>
cd /usr/local/src
rz #上传sersync2.5.4_64bit_binary_stable_final.tar.gz
tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
cd /usr/local
mkdir sersync
mv GNU-Linux-x86 /usr/local/sersync
2、配置sersync的confxml.xml文件
shell>
cd /usr/local/sersync/GNU-Linux-x86
cp confxml.xml confxml.xmlbak
vim confxml.xml #编辑写入如下内容:
<head
version="2.5">
<host
hostip="localhost" port="8008"></host>
<debug
start="false"/>
<fileSystem
xfs="false"/>
<filter
start="false">
<exclude
expression="(.*)\.svn"></exclude>
<exclude
expression="(.*)\.gz"></exclude>
<exclude
expression="^info/*"></exclude>
<exclude
expression="^static/*"></exclude>
</filter>
<inotify>
<delete
start="true"/>
<createFolder
start="true"/>
<createFile
start="false"/>
<closeWrite
start="true"/>
<moveFrom
start="true"/>
<moveTo
start="true"/>
<attrib
start="false"/>
<modify
start="false"/>
</inotify>
<sersync>
<!--此处的IP为待同步的机器的IP地址及rsyncd.conf中指定认证的备份模块名,例如我们现在配置的机器为10.58.2.4,则此处IP需要配置为10.158.2.4-->
</localpath>
<rsync>
<commonParams
params="-artuz"/>
<!--此处一定要设定为true才会自动同步,/etc/sersync.secrets为待同步机器密码文件,例如我们现在配置的机器为10.58.2.4,则此处sersync.secrets文件中需要配置10.158.2.4的xxxx用户的密码-->
<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 60mins execute once-->
<crontab
start="true" 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">
<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/p_w_picpaths"/>
</localpath>
</plugin>
</head>
3、创建用户认证文件
shell>
vim /etc/sersync.secrets
输入如下内容:
待同步机器xxxx用户对应密码
#例如:我们现在配置的机器为10.58.2.4,
#则此处sersync.secrets文件中需要配置10.158.2.4的xxxx用户的密码
4、设置文件权限
shell>
chmod 600 /etc/sersync.secrets #设置文件所有者读取、写入权限
1、启动rsync
shell>
/usr/bin/rsync --daemon
--config=/etc/rsyncd.conf
2、检查rsync是否启动
shell>
lsof -i:873
3、加入开机自启动
shell>
echo “/usr/bin/rsync
--daemon --config=/etc/rsyncd.conf” >> /etc/rc.local
1、启动sersync
shell>
/usr/local/sersync/GNU-Linux-x86/sersync2
-d -r -o /usr/local/sersync/GNU-Linux-x86/confxml.xml
2、检查sersync是否启动
shell>
ps -ef|grep sersync
3、加入开机自启动
shell>
vim /etc/rc.d/rc.local #编辑,在最后一行添加
/usr/local/sersync/GNU-Linux-x86/sersync2 -d -r -o
/usr/local/sersync/GNU-Linux-x86/confxml.xml
#设置开机自动启动脚本
:wq! #保存退出
[if !supportLists]1、 [endif]在10.58.2.4的/app/xxxx/tomcat8.0.24/webapps/xxxx-portal/upload下新建、删除、修改测试文件,然后到10.158.2.4中查看是否已经同步。
在10.158.2.4的/app/xxxx/tomcat8.0.24/webapps/xxxx-portal/upload下新建、删除、修改测试文件,然后到10.58.2.4中查看是否已经同步。