1. rysnc安装部署
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
服务端配置 [root@web2 ~] # rpm -qa rsync 查询是否安装 [root@web2 ~] # yum install rsync 安装rsync [root@web2 ~] # useradd rsync -s /sbin/nologin -M 建立rsync用户 [root@web2 ~] # mkdir /backup 建立同步文件目录 [root@web2 ~] # chown -R rsync.rsync /backup backup目录属主为rsync [root@web2 ~] # touch /etc/rsync.password 建立密码文件 [root@web2 ~] # vim /etc/rsync.password 编辑密码文件 rsync_backup:123456 [root@web2 ~] # chmod 600 /etc/rsync.password 密码文件权限设置 [root@web2 ~] # echo "rsync --daemon">>/etc/rc.local 让开机自启动 [root@web2 ~] # vim /etc/rsyncd.conf 默认是没有配置文件,新建上去 sync server #sync server conif________________________________start #created by xiaoyi 00:00 2015-07-24 uid = rsync ##连接用户,客户端连接的用户权限 gid = rsync ##连接用户 use chroot = no ##安全目录 max connections = 2000 ##同时连接的最低用户数 timeout = 600 ##超时时间 pid file = /var/run/rsyncd .pid ##pid文件,进程号 lock file = /var/run/rsync .lock ##锁文件 log file = /var/lob/rsyncd .log ##日志文件 ignore errors ##忽略错误 read only = false ##可读写,远程客户端可以读写 list = false ##远程客户端不能列表, hosts allow = 192.168.1.0 /24 ##允许的网段 hosts deny = 0.0.0.0 /32 ##一般不用==== auth users = rsync_backup #远程连接的虚拟的用户, secrets file = /etc/rsync .password ##存放用户密码的文件 comment = backup server by xiaoyi ##comment 注释的意思 [backup] ##模块,共享一个目录 path = /backup/ ##共享的目录 #rsync server config__________________________________end |
2.rsyncd.conf配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
sync server # rsync start uid = root gid = root use chroot = no max connections = 200 port = 873 timeout = 600 pid file = /var/run/rsyncd .pid lock file = /var/run/rsync .lock log file = /var/log/rsyncd .log auth users = ph_rsync secrets file = /etc/rsync .pas # /data/wwwroot/ [data] comment = pinhui001 v2.5 ignore errors read only = false hosts allow = 10.1.8.0 /24 hosts deny = * path = /data/wwwroot/ # end |
3.客户端配置
1
2
3
4
|
[root@nginx ~] # yum install rsync 安装服务 [root@nginx ~] # echo "123456">/etc/rsync.password 建立密码文件 [root@nginx ~] # chmod 600 /etc/rsync.password 权限更改 [root@nginx ~] # rsync -avz /etc/ rsync_backup@192.168.1.101::backup --password-file=/etc/rsync.password 客户端文件推送到rsync服务器 |
4.防火墙配置
1
2
3
4
|
Iptables -A INPUT –s 192.168.1.2 /24 –p tcp –m tcp –dport 873 –j ACCEPT 允许固定的办公室网发布程序传输同步 -A INPUT –s 192.168.1.2 /255 .255.255.O –p tcp –m tcp –dport 873 –j ACCEPT |
#.sersync优点:
1.c++编写,可以对临时文件和重复文件操作进行过滤
2.配置简单
3.使用多线程进行同步
4.自带出错处理机制,通过失败队列对出错的文件重新同步,如果还失败,配置若干小时再传
5.sersync自带crotab功能,只需在xml配置文件中开启
6.sersync自带socket与http的协议扩展,可以满足有特殊需求的二次开发
#处理机制
inotify–过滤队列–线程组–调用rsync线程—远程服务器
1.sersync安装
1
2
3
4
5
|
mkdir /server/tools -p wget https: //storage .googleapis.com /google-code-archive-downloads/v2/code .google.com /sersync/sersync2 .5.4_64bit_binary_stable_final. tar .gz tar -zxvf sersync2.5.4_64bit_binary_stable_final. tar .gz -C /usr/local cd /usr/local mv GNU-Linux-x86 sersync |
2.sersync配置
1
2
3
4
5
|
[root@s sersync] # cd /usr/local/sersync/ [root@s sersync] # mkdir conf bin logs [root@s sersync] # mv confxml.xml conf [root@s sersync] # mv sersync2 bin/sersync [root@s conf] # cp /usr/local/sersync/conf/confxml.xml confxml.xml.bak |
3.sersync文件配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<?xml version= "1.0" encoding= "ISO-8859-1" ?> <headversion= "2.5" > <hosthostip= "localhost" port= "8008" >< /host > <debugstart= "false" /> <--!调试模式是否打开--> <fileSystemxfs= "false" /> <filterstart= "true" > <--!文件过滤,定义哪些文件不同步--> # false不开启过滤功能,true开启功能 <exclude expression= "(.*)/runtime/*" >< /exclude > # 定义所以目录runtime下的文件不同步 <!--<excludeexpression= "(.*)\.svn" >< /exclude >--> <!--<excludeexpression= "(.*)\.gz" >< /exclude >--> <!--<excludeexpression= "^info/*" >< /exclude >--> <!--<excludeexpression= "^static/*" >< /exclude >--> < /filter > <inotify> <--!定义监控哪些事件--> <deletestart= "true" /> <createFolderstart= "true" /> <createFilestart= "false" /> <closeWritestart= "true" /> <moveFromstart= "true" /> <moveTostart= "true" /> <attribstart= "false" /> <modifystart= "false" /> < /inotify > <sersync> <localpathwatch= "/data/www" > # <--!本地需要推送到rsync服务器的目录--> <remoteip= "192.168.1.161" name= "backup" /> # <--!需要同步到远端服务器的主机及rsync模块--> <!--<remote ip= "192.168.8.39" name= "tongbu" />--> <!--<remote ip= "192.168.8.40" name= "tongbu" />--> < /localpath > < rsync > <commonParamsparams= "-artuz" /> <--!同步的参数 --> <authstart= "true" users = "root" passwordfile= "/etc/rsync.pas" /> # <--!同步认证,同步用户名,同步密码文件--> <userDefinedPortstart= "false" port= "874" /><!-- port=874 --> <--!同步端口号--> <timeoutstart= "false" time = "100" /><!-- timeout=100 --> <--!同步超时时间,一般打开--> <sshstart= "false" /> <--! ssh 隧道是否开启,一般不开启--> < /rsync > <failLogpath= "/usr/local/sersync/logs/rsync_fail_log.sh" timeToExecute= "60" /><!--default every 60mins execute once--> <--!传输失败队列,没60分钟执行一次--> <crontabstart= "false" schedule= "600" ><!--600mins--> <--!定时传--> <crontabfilterstart= "false" > <excludeexpression= "*.php" >< /exclude > <excludeexpression= "info/*" >< /exclude > < /crontabfilter > < /crontab > <pluginstart= "false" name= "command" /> < /sersync > <pluginname= "command" > <paramprefix= "/bin/sh" suffix= "" ignoreError= "true" /><!--prefix /opt/tongbu/mmm .sh suffix--> <filterstart= "false" > <includeexpression= "(.*)\.php" /> <includeexpression= "(.*)\.sh" /> < /filter > < /plugin > <pluginname= "socket" > <localpathwatch= "/opt/tongbu" > <deshostip= "192.168.138.20" port= "8009" /> < /localpath > < /plugin > <pluginname= "refreshCDN" > <localpathwatch= "/data0/htdocs/cms.xoyo.com/site/" > <cdninfodomainname= "ccms.chinacache.com" port= "80" username= "xxxx" passwd = "xxxx" /> <sendurlbase= "http://pic.xoyo.com/cms" /> <regexurlregex= "false" match= "cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images" /> < /localpath > < /plugin > < /head > |
4.配置环境变量
1
2
|
[root@s conf] # echo 'export PATH=$PATH:/usr/local/sersync/bin'>>/etc/profile [root@s conf] # source /etc/profile |
5.启动命令,-r第一次全部同步,-d守护进程,-o指定配置文件
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@master www] # sersync -r -d -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 rsync all the local files to the remote servers before the sersync work option: -d run as a daemon option: -o config xml name: /usr/local/sersync/conf/confxml .xml daemon thread num: 10 parse xml config file XML Parsing error inside file '/usr/local/sersync/conf/confxml.xml' . Warning: Unmatched end tag At line 52, column 15. |
6.sersync参数说明
1
2
3
4
5
|
sersync -r 第一次全部同步 -o 指定配置文件 -n 指定线程总数 -d 后台服务 --help 帮助 |
7.sersync插件(开启插件设置),plugin设置为true时才生效,name为调用的插件,目前支持command refreshCDN socket http四中插件,http插件去除了
1
2
|
<plugin start= "true" name= "command" /> |
8.sersync压力测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@LB02 ~] # dmidecode | grep "Product Name" ProductName: IBM System x3650 M4:-[7915K3G]- ProductName:00MV214 [root@LB02 ~] # grep name /proc/cpuinfo model name :Intel(R)Xeon(R) CPU E5-2609 v2 @2.50GHz model name :Intel(R)Xeon(R) CPU E5-2609 v2 @2.50GHz model name :Intel(R)Xeon(R) CPU E5-2609 v2 @2.50GHz model name :Intel(R)Xeon(R) CPU E5-2609 v2 @2.50GHz [root@LB02 ~] # grep MemTotal/proc/meminfo MemTotal:32688332 kB tar -zxvf webbench-1.5. tar .gz cd webbench-1.5 make make install /usr/local/bin/webbench -t 100-c 1000 http: //blog .xiaoyi.com/ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
#!/bin/sh count=80 while true do for ((i=1;i<=$count;i++)) do /bin/cp 10k.jpg /backup/test/ $i /10k_ ` echo $( date )$RANDOM|md5sum | cut -c 1-8`.jpg done sleep 1 for ((i=1;i<=$count;i++)) do /bin/cp 30k.jpg /backup/test/ $i /30k_ ` echo $( date )$RANDOM|md5sum | cut -c 1-8`.jpg done sleep 1 for ((i=1;i<=$count;i++)) do /bin/cp 50k.jpg /backup/test/ $i /50k ` echo $( date )$RANDOM|md5sum | cut -c 1-8`.jpg done sleep 1 done |