Rsync+sersyncWord格式.docx
《Rsync+sersyncWord格式.docx》由会员分享,可在线阅读,更多相关《Rsync+sersyncWord格式.docx(9页珍藏版)》请在冰豆网上搜索。
#只安装xinetd即可,CentOS中是以xinetd来管理rsync服务的
yuminstallrsyncxinetd
#如果默认没有rsync,运行此命令进行安装rsync和xinetd
vi/etc/xinetd.d/rsync
#编辑配置文件,设置开机启动rsync
disable=no
#修改为no
/etc/init.d/xinetdstart
#启动(CentOS中是以xinetd来管理rsync服务的)
4、创建认证密码文件
vi/etc/passwd.rsync#编辑文件,添加以下内容
123456
#密码
chmod600/etc/passwd.rsync#设置文件权限,只设置文件所有者具有读取、写入权限即可
一、在172.16.0.230目标服务器安装Rsync服务端
1、关闭SELINUX
vi/etc/selinux/config
#SELINUX=enforcing
#SELINUXTYPE=targeted
SELINUX=disabled
#保存,退出
setenforce0
2、开启防火墙tcp873端口(Rsync默认端口)
vi/etc/sysconfig/iptables
3、安装Rsync服务端软件
#安装
#启动(CentOS中是以xinetd来管理Rsync服务的)
4、创建rsyncd.conf配置文件
vi/etc/rsyncd.conf
#创建配置文件,添加以下代码
logfile=/var/log/rsyncd.log
#日志文件位置,启动rsync后自动产生这个文件,无需提前创建
pidfile=/var/run/rsyncd.pid
#pid文件的存放位置
lockfile=/var/run/rsync.lock
#支持maxconnections参数的锁文件
secretsfile=/etc/rsync.pass
#用户认证配置文件,里面保存用户名称和密码,后面会创建这个文件
motdfile=/etc/rsyncd.Motd
#rsync启动时欢迎信息页面文件位置(文件内容自定义)
[rsyncdata]
#自定义名称
path=/data/software
#rsync服务端数据目录路径
comment=rsyncdata
#模块名称与[rsyncdata]自定义名称相同
uid=root
#设置rsync运行权限为root
gid=root
port=873
#默认端口
usechroot=no
#默认为true,修改为no,增加对目录文件软连接的备份
readonly=no
#设置rsync服务端文件为读写权限
list=no
#不显示rsync服务端资源列表
maxconnections=200
#最大连接数
timeout=600
#设置超时时间
authusers=root#执行数据同步的用户名,可以设置多个,用英文状态下逗号隔开
hostsallow=172.16.0.229
#允许进行数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
hostsdeny=192.168.21.254
#禁止数据同步的客户端IP地址,可以设置多个,用英文状态下逗号隔开
#保存,退出
5、创建用户认证文件
vi/etc/rsync.pass
#配置文件,添加以下内容
root:
#格式,用户名:
密码,可以设置多个,每行一个用户名:
密码
6、设置文件权限
chmod600/etc/rsyncd.conf
#设置文件所有者读取、写入权限
chmod600/etc/rsync.pass
7、启动rsync
#启动
servicexinetdstop
#停止
servicexinetdrestart
#重新启动
5、测试源服务器172.16.0.229到目标服务器172.16.0.230之间的数据同步
mkdir/data/software
#在源服务器上创建测试文件夹,然后在源服务器运行下面2行命令
rsync-auzv--port=873--progress--delete/data/software/***********.0.230:
rsyncdata--password-file=/etc/passwd.txt
运行完成后,在目标服务器172.16.0.230上查看,在/data/software目录下有文件夹,说明数据同步成功。
二、安装sersync工具,实时触发rsync进行同步在源服务器安装并配置(0.229)
1、查看服务器内核是否支持inotify
ll/proc/sys/fs/inotify
#列出文件目录,出现下面的内容,说明服务器内核支持inotify
-rw-r--r--1rootroot0Mar
702:
17max_queued_events
17max_user_instances
17max_user_watches
备注:
Linux下支持inotify的内核最小为2.6.13,可以输入命令:
uname-a查看内核
默认已经支持inotify
2、修改inotify默认参数(inotify默认内核参数值太小)
查看系统默认参数值:
sysctl-a|grepmax_queued_events
结果是:
fs.inotify.max_queued_events=16384
sysctl-a|grepmax_user_watches
fs.inotify.max_user_watches=8192
sysctl-a|grepmax_user_instances
fs.inotify.max_user_instances=128
修改参数:
sysctl-wfs.inotify.max_queued_events="
99999999"
sysctl-wfs.inotify.max_user_watches="
sysctl-wfs.inotify.max_user_instances="
65535"
vi/etc/sysctl.conf
#添加以下代码
fs.inotify.max_queued_events=99999999
fs.inotify.max_user_watches=99999999
fs.inotify.max_user_instances=65535
3、安装sersync
sersync下载地址:
上传sersync2.5.4_64bit_binary_stable_final.tar.gz到/usr/local/src目录下
cd/usr/local/src
tarzxvfsersync2.5.4_64bit_binary_stable_final.tar.gz
#解压
mvGNU-Linux-x86
/usr/local/sersync
#移动目录到/usr/local/sersync
4、配置sersync
cd
#进入sersync安装目录
cpconfxml.xmlconfxml.xml-bak
#备份原文件
viconfxml.xml
#编辑,修改下面的代码
<
?
xmlversion="
1.0"
encoding="
ISO-8859-1"
>
headversion="
2.5"
hosthostip="
localhost"
port="
8008"
/host>
debugstart="
false"
/>
fileSystemxfs="
filterstart="
excludeexpression="
(.*)\.svn"
/exclude>
(.*)\.gz"
^info/*"
^static/*"
/filter>
inotify>
deletestart="
true"
createFolderstart="
createFilestart="
closeWritestart="
moveFromstart="
moveTostart="
attribstart="
modifystart="
/inotify>
sersync>
localpathwatch="
/data/software"
remoteip="
172.16.0.230"
name="
rsyncdata"
!
--<
192.168.8.40"
tongbu"
-->
/localpath>
rsync>
commonParamsparams="
-artuz"
authstart="
users="
root"
passwordfile="
/etc/rsync.pass"
userDefinedPortstart="
874"
--port=874-->
timeoutstart="
time="
100"
--timeout=100-->
sshstart="
/rsync>
failLogpath="
/tmp/rsync_fail_log.sh"
timeToExecute="
60"
--defaultevery60minsexecuteonce-->
crontabstart="
schedule="
600"
--600mins-->
crontabfilterstart="
*.php"
info/*"
/crontabfilter>
/crontab>
pluginstart="
command"
/sersync>
pluginname="
paramprefix="
/bin/sh"
suffix="
"
ignoreError="
<
--prefix/opt/tongbu/mmm.shsuffix-->
includeexpression="
(.*)\.php"
(.*)\.sh"
/plugin>
socket"
/opt/tongbu"
deshostip="
192.168.138.20"
8009"
refreshCDN"
/data0/htdocs/
cdninfodomainname="
80"
username="
xxxx"
passwd="
sendurlbase="
regexurlregex="
match="
/head>
参数说明:
:
#源服务器同步目录
172.16.0.230:
#目标服务器IP地址
name="
rsyncdata”目标服务器rsync同步目录模块名称
users="
#目标服务器rsync同步用户名
passwordfile="
/etc/sync.pass目标服务器rsync同步用户的密码在源服务器的存放路径
172.16.0.230,每行一个
#脚本运行失败日志记录
start="
#设置为true,每隔600分钟执行一次全盘同步
5、设置sersync监控开机自动执行
vi/etc/rc.d/rc.local
#编辑,在最后添加一行
/usr/local/sersync/sersync2-d-r-o
/usr/local/sersync/confxml.xml
#设置开机自动运行脚本
6、添加脚本监控sersync是否正常运行
vi
/home/crontab/check_sersync.sh
#编辑,添加以下代码
#!
/bin/sh
sersync="
/usr/local/sersync/sersync2"
confxml="
/usr/local/sersync/confxml.xml"
status=$(psaux|grep'
sersync2'
|grep-v'
grep'
|wc-l)
if[$status-eq0];
then
$sersync-d-r-o$confxml&
else
exit0;
fi
chmod+x/home/crontab/check_sersync.sh
#添加脚本执行权限
vi/etc/crontab
#编辑,在最后添加下面一行
*/5****root/home/crontab/check_sersync.sh>
/dev/null2>
&
1
#每隔5分钟执行一次脚本
servicecrondreload
#重新加载服务
6、测试sersync实时触发rsync同步脚本是否正常运行
在源服务器172.16.0.229上创建文件
mkdir/data/softwar/tongbu
重新启动源服务器:
等系统启动之后,查看目标服务器172.16.0.230/data/software下是否有tongbu文件夹
然后再在源服务器172.16.0.229创建文件夹test.txt
Touch/data/softwate/test.txt
继续查看目标服务器172.16.0.230下是否有test.txt
如果以上测试都通过,说明inotify实时触发rsync同步脚本运行正常。
至此,Linux下Rsync+sersync实现数据实时同步完成。