首页 > 代码库 > sersync的服务设置
sersync的服务设置
sersync可以理解为建立在inotify基础上的加强版,它可以更加细腻和完美的实现inotify和rsync的能力.
使用sersync就必须安装inotify和rsync.
1.1 环境nfs客户端和backup服务端
默认iptables,xelinux已经关闭
1.1.1 nfs客户端
[root@nfs01 ~]# uname -a
Linux nfs01 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017x86_64 x86_64 x86_64 GNU/Linux
查看是否有inotify,如果没有下载
[root@nfs01 ~]# rpm -qa inotify-tools
inotify-tools-3.14-1.el6.x86_64
下载方法
yum install inotify-tools -y
设置nfs客户端的推送目录
mkdir -p /nfsbackup/
设置rsync的密码文件,权限,查看
echo "密码" >/etc/rsync.password
chmod 600 /etc/rsync.password
[root@nfs01 ~]# ll /etc/rsync.password
-rw------- 1 root root 7 Jun 28 11:21/etc/rsync.password
1.1.2 backup服务端
[root@backup ~]# uname -a
Linux backup 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017x86_64 x86_64 x86_64 GNU/Linux
查看rsync是否启动(默认已经安装rsync,如果没有安装请看之前发的rsync服务设置)
[root@backup ~]# ss -lntup|grep rsyn
tcp LISTEN 0 5 :::873 :::* users:(("rsync",1294,5))
tcp LISTEN 0 5 *:873 *:* users:(("rsync",1294,3))
如果没有启动请启动
rsync --daemon
查看rsync的配置文件找到虚拟用户,用户密码,用户路径
[root@backup ~]# cat /etc/rsyncd.conf
######rsync_config_______________start
#created by oldboy 15:01 2007-6-22
#QQ 31333741 blog:http://oldboy.blog.51cto.com
##rsyncd.conf start##
uid=rsync
gid=rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
list = false
hosts allow = 172.16.1.0/24
#hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
#rsync_config_______________end
read only = false
[backup]
path = /backup/
[nfsbackup] #模块的名字
path = /nfsbackup/ #模块的路径
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
#hosts deny = 0.0.0.0/32
auth users = rsync_backup #虚拟用户的用户名
secrets file = /etc/rsync.password #用户密码的路径
1.2 安装sersync
1.2.1 去网站下载sersync包
1.2.2 传输到nfs服务器
输入sz选择sersync包
如果没有,安装上传下载命令
yum install -y lrzsz
解压sersync包,需要unzip命令
unzip sersync_installdir_64bit.zip
将sersync文件包移动到/usr/local/sersync
mv sersync_installdir_64bit /usr/local/sersync
查看
[root@nfs01 ~]# tree /usr/local/sersync/
/usr/local/sersync/
├── bin
│ └── sersync
├── conf
│ └── confxml.xml
├── logs
└── sersync
4 directories, 2 files
1.3 设置sersync的配置文件
vim /usr/local/sersync/conf/confxml.xml
<?xml version="1.0"encoding="ISO-8859-1"?>
<head version="2.5">
<hosthostip="localhost" port="8008"></host>
<debugstart="false"/>
<fileSystem xfs="false"/>
<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"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/nfsbackup"> ###填写nfs客户端的目录
<remote ip="172.16.1.41"name="nfsbackup"/>###填写backup服务端的IP地址和模块名字
<!--<remote ip="192.168.8.39"name="tongbu"/>-->
<!--<remote ip="192.168.8.40"name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-az"/> ###选择rsync执行的命令参数
<auth start="true" users="rsync_backup"passwordfile="/etc/rsync.password"/>
#####选择开启,名字就是rsync的虚拟用户名,虚拟用户密码目录
<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/">
<cdninfodomainname="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>
1.4 查看使用说明
[root@nfs01 ~]# sersync -h
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 param
_______________________________________________________
参数-d:启用守护进程模式
参数-r:在监控前,将监控目录与远程主机用rsync命令推送一遍
c参数-n: 指定开启守护线程的数量,默认为10个
参数-o:指定配置文件,默认使用confxml.xml文件
参数-m:单独启用其他模块,使用 -m refreshCDN 开启刷新CDN模块
参数-m:单独启用其他模块,使用 -m socket 开启socket模块
参数-m:单独启用其他模块,使用 -m http 开启http模块
不加-m参数,则默认执行同步程序
________________________________________________________________
1.5 启动sersync服务
[root@nfs01 conf]# sersync -rd -o /usr/local/sersync/conf/confxml.xml
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 param
option: -r rsyncall the local files to the remote servers before the sersync work
option: -d runas a daemon
option: -o configxml name: /usr/local/sersync/conf/confxml.xml
daemon thread num: 10
parse xml config file
host ip : localhost hostport: 8008
daemon start,sersync run behind the console
use rsync password-file :
useris rsync_backup
passwordfileis /etc/rsync.password
config xml parse success
please set /etc/rsyncd.conf max connections=0Manually
sersync working thread 12 = 1(primary thread) + 1(fail retry thread) +10(daemon sub threads)
Max threads numbers is: 22 = 12(Thread pool nums) +10(Sub threads)
please according your cpu ,use -n param to adjust the cpu rate
------------------------------------------
rsync the directory recursivly to the remoteservers once
working please wait...
execute command: cd /nfsbackup && rsync -az -R --delete ./rsync_backup@172.16.1.41::nfsbackup --password-file=/etc/rsync.password>/dev/null 2>&1
run the sersync:
watch path is: /nfsbackup
1.6 测试
nfs客户端
添加
root@nfs01 nfsbackup]# touch {1..5}.log
[root@nfs01 nfsbackup]# ll
total 0
-rw-r--r-- 1 root root 0 Jun 29 18:46 1.log
-rw-r--r-- 1 root root 0 Jun 29 18:46 2.log
-rw-r--r-- 1 root root 0 Jun 29 18:46 3.log
-rw-r--r-- 1 root root 0 Jun 29 18:46 4.log
-rw-r--r-- 1 root root 0 Jun 29 18:46 5.log
删除
[root@nfs01 nfsbackup]# rm -f *
[root@nfs01 nfsbackup]# ll
total 0
1.6.1 backup服务端
添加
[root@backup nfsbackup]# ll
total 0
-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 1.log
-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 2.log
-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 3.log
-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 4.log
-rw-r--r-- 1 rsync rsync 0 Jun 29 18:46 5.log
删除
[root@backup nfsbackup]# ll
total 0
本文出自 “一直向前的河” 博客,请务必保留此出处http://csl19881016.blog.51cto.com/12855437/1943256
sersync的服务设置