[linux怎么读]linux下Sersync 数据同步的配置教程

更新时间:2020-05-03    来源:php安装    手机版     字体:

【www.bbyears.com--php安装】

 一、规划:
 
数据同步源: nfs-s1 IP:172.16.1.10 目录:/data/images
 
数据同步目的:nfs-s2 IP:172.16.1.20 目录:/data/images
 
二、配置步骤:
 
1、在 nfs-s2 配置 rsync daemon ,并启动。nfs-s1 配置 rsync client。
 
2、在 nfs-s1 配置 sersync 。
 
三、nfs-s2 配置 rsync daemon :(注意目录对于相应其他程序的读写权限)
 [root@nfs-s2 ~]# ifconfig eth0|awk -F "[ :]+" "NR==2{print $4}"
172.16.1.20
[root@nfs-s2 ~]# uname -r
2.6.32-504.el6.x86_64
[root@nfs-s2 ~]#
 [root@nfs-s2 ~]# useradd -s /sbin/nologin -M www
[root@nfs-s2 ~]# mkdir /data/images -p
[root@nfs-s2 ~]# chown -R www.www /data/images/
 
编辑 /etc/rsyncd.conf
 [root@nfs-s2 ~]# cat /etc/rsyncd.conf
uid=www
gid=www
use chroot=true
read only=false
list=false
ignore errors=true
hosts allow=172.16.1.0/24
hosts deny=0.0.0.0/0
max connections=1000
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsyncd.lock
log file=/var/log/rsyncd.log
auth users=sersync
secrets file=/etc/rsync.passwd
[images]
comment=images from nfs-s1
path=/data/images
[root@nfs-s2 ~]#
 
编辑 rsync daemon 用户密码文件 :
 [root@nfs-s2 ~]# echo "sersync:123456">/etc/rsync.passwd
[root@nfs-s2 ~]# cat /etc/rsync.passwd
sersync:123456
[root@nfs-s2 ~]# chmod 700 /etc/rsync.passwd
 
启动 rsync daemon :
 [root@nfs-s2 ~]# rsync --daemon
 
在 nfs-s1 创建 rsync daemon 密码文件 :
 [root@nfs-s1 ~]# ifconfig eth0|awk -F "[ :]+" "NR==2{print $4}"
172.16.1.10
[root@nfs-s1 ~]# uname -r
2.6.32-504.el6.x86_64
[root@nfs-s1 ~]#
 [root@nfs-s1 ~]# echo "123456">/etc/rsync.passwd
[root@nfs-s1 ~]# chmod 700 /etc/rsync.passwd
[root@nfs-s1 ~]#
 
测试 :
 [root@nfs-s1 ~]# echo "test rsync daemon from nfs-s1">rsync.test
[root@nfs-s1 ~]# rsync -avz rsync.test sersync@172.16.1.20::images --password-file /etc/rsync.passwd
sending incremental file list
rsync.test

sent 68 bytes  received 33 bytes  40.40 bytes/sec
total size is 30  speedup is 0.30
[root@nfs-s1 ~]#
 
rsync daemon 配置成功。
 [root@nfs-s2 ~]# echo "rsync --daemon">>/etc/rc.local
[root@nfs-s2 ~]# tail -1 /etc/rc.local
rsync --daemon
[root@nfs-s2 ~]#

 
四、在 nfs-s1 安装配置 sersync :(目录权限根据实际情况设置)
 [root@nfs-s1 ~]# useradd -s /sbin/nologin -M www
[root@nfs-s1 ~]# mkdir -p /data/images
[root@nfs-s1 ~]# chown -R www.www /data/images/
[root@nfs-s1 ~]#
 
下载 sersync :
 [root@nfs-s1 src]# wget -q http://www.z-dig.com/repos/sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs-s1 src]# ls
sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs-s1 src]# tar xf sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs-s1 src]# ls
GNU-Linux-x86  sersync2.5.4_64bit_binary_stable_final.tar.gz
[root@nfs-s1 src]#
 [root@nfs-s1 src]# mv GNU-Linux-x86 /usr/local/sersync
[root@nfs-s1 src]# cd /usr/local/sersync/
[root@nfs-s1 sersync]# ls
confxml.xml  sersync2
[root@nfs-s1 sersync]# mkdir {bin,conf,log}
[root@nfs-s1 sersync]# ls
bin  conf  confxml.xml  log  sersync2
[root@nfs-s1 sersync]# mv confxml.xml conf
[root@nfs-s1 sersync]# mv sersync2 bin/sersync
[root@nfs-s1 sersync]# tree .
.
├── bin
│   └── sersync
├── conf
│   └── confxml.xml
└── log

3 directories, 2 files
[root@nfs-s1 sersync]#
 
编辑 confxml.xml :(可根据实际需求进行细粒度的配置)
 [root@nfs-s1 sersync]# cat conf/confxml.xml



   
   
   
   
       
   

   
       
       
       
       
       
       
       
       
   

   
       
           
       

       
           
           
           
           
           
       

       
       
           
               
           

       

        
   

[root@nfs-s1 sersync]#
 
启动 sersync :
 [root@nfs-s1 sersync]# /usr/local/sersync/bin/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
host ip : localhost     host port: 8008
daemon start,sersync run behind the console
use rsync password-file :
user is sersync
passwordfile is         /etc/rsync.passwd
config xml parse success
please set /etc/rsyncd.conf max connections=0 Manually
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 remote servers once
working please wait...
execute command: cd /data/images && rsync -artuz -R --delete ./ sersync@172.16.1.20::images --password-file=/etc/rsync.passwd >/dev/null 2>&1
run the sersync:
watch path is: /data/images
[root@nfs-s1 sersync]#
 
测试 :
 [root@nfs-s1 sersync]# touch /data/images/{1..100}.png
 [root@nfs-s2 ~]# ls /data/images/
100.png  19.png  28.png  37.png  46.png  55.png  64.png  73.png  82.png  91.png
10.png   1.png   29.png  38.png  47.png  56.png  65.png  74.png  83.png  92.png
11.png   20.png  2.png   39.png  48.png  57.png  66.png  75.png  84.png  93.png
12.png   21.png  30.png  3.png   49.png  58.png  67.png  76.png  85.png  94.png
13.png   22.png  31.png  40.png  4.png   59.png  68.png  77.png  86.png  95.png
14.png   23.png  32.png  41.png  50.png  5.png   69.png  78.png  87.png  96.png
15.png   24.png  33.png  42.png  51.png  60.png  6.png   79.png  88.png  97.png
16.png   25.png  34.png  43.png  52.png  61.png  70.png  7.png   89.png  98.png
17.png   26.png  35.png  44.png  53.png  62.png  71.png  80.png  8.png   99.png
18.png   27.png  36.png  45.png  54.png  63.png  72.png  81.png  90.png  9.png
[root@nfs-s2 ~]#
 [root@nfs-s1 sersync]# rm -f /data/images/*.png
[root@nfs-s1 sersync]# mkdir /data/images/{png,jpeg,jpg}
[root@nfs-s1 sersync]#
 [root@nfs-s2 ~]# ls /data/images/
jpeg  jpg  png
[root@nfs-s2 ~]#
 
测试成功
 [root@nfs-s1 sersync]# echo "/usr/local/sersync/bin/sersync -d -o /usr/local/sersync/conf/confxml.xml">>/etc/rc.local   
[root@nfs-s1 sersync]# tail -1 /etc/rc.local
/usr/local/sersync/bin/sersync -d -o /usr/local/sersync/conf/confxml.xml
[root@nfs-s1 sersync]#

本文来源:http://www.bbyears.com/jiaocheng/93305.html

热门标签

更多>>

本类排行