应用场景:横向扩展Web服务器或者是备份Web服务器相关目录下的数据文件,确保指定目录下的所有文件实时同步。
实验拓补图:
实验环境:
均关闭firewalld和selinux防火墙
操作系统:CentOS7
sersync_01:192.168.199.14
sersync_02:192.168.199.15
sersync_N:192.168.199.16
实验步骤:
一、登录到sersync_01和sersync_02,安装Rsync服务器
01.安装rsync软件
yum install rsync -y
02.启动rsync服务
systemctl start rsyncd.service
03.检查rsync服务状态
systemctl status rsyncd.service
04.将rsync服务加入到开机自动启动
systemctl enable rsyncd.service
05.配置/etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode # See rsyncd.conf man page for more options. # configuration example: # uid = nobody # gid = nobody # use chroot = yes # max connections = 4 # pid file = /var/run/rsyncd.pid # exclude = lost+found/ # transfer logging = yes # timeout = 900 # ignore nonreadable = yes # dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 # [ftp] # path = /home/ftp # comment = ftp export area uid = root gid = root use chroot = yes max connections = 1024 pid file = /var/run/rsyncd.pid exclude = lost+found/ transfer logging = yes timeout = 900 ignore nonreadable = yes dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 [hbgslz] path = /tmp/hbgslz/ comment = ftp export area read only = no write only = no list = yes
二、登录到sersync_N服务器,安装Rsync和sersync
01.安装Rsync软件,步骤和上面完全一样
yum install rsync -y systemctl start rsyncd.service systemctl enable rsyncd.service
02.下载sersync软件(官网下载地址:http://sersync.sourceforge.net/),由于需要×××才可以下载,特提供百度网盘下载:https://pan.baidu.com/s/1kWqfypp 密码:b9g3
03.解压sersync软件包,注意该工具解压后即可使用。
#解压tar包到/usr/local/目录下 tar -zxf /tmp/sersync2.5.4_64bit_binary_stable_final.tar.gz -C /usr/local/ #将解压后的GNU-Linux-x86目录重新命名 mv /usr/local/GNU-Linux-x86/ /usr/local/sersync2.5.4_64bit
04.配置/usr/local/sersync2.5.4_64bit/confxml.xml 文件
<?xml version="1.0" encoding="ISO-8859-1"?> <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> <localpath watch="/tmp/hbgslz/"> <remote ip="192.168.199.14" name="hbgslz"/> <remote ip="192.168.199.15" name="hbgslz"/> <!--<remote ip="192.168.8.39" name="tongbu"/>--> <!--<remote ip="192.168.8.40" name="tongbu"/>--> </localpath> <rsync> <commonParams params="-artuz"/> <auth start="false" users="hbgslz_user" passwordfile="/etc/rsync.passwd"/> <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="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>
05.向/etc/rc.d/rc.local文件中添加如下开机启动脚本,注意给/etc/rc.d/rc.local添加执行权限,并重启服务器
/usr/local/sersync2.5.4_64bit/sersync2 -d -r -o /usr/local/sersync2.5.4_64bit/confxml.xml &
实验目的校验:
01.登录到sersync_N服务器,在/tmp/hbgslz/目录下新建文件hbgslz.txt
touch /tmp/hbgslz/hbgslz.txt
02.分别登录到sersync_01、sersync_02,查看/tmp/hbgslz/目录下面是否存在hbgslz.txt文件
sersync_01:
sersync_02:
转载于:https://blog.51cto.com/hbgslz/2071607