Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7111643
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类:

2013-01-12 21:33:13

原文地址:sersync2 实时同步 作者:icucstone

              sersync2 实时同步配置

自动同步文件或者是目录

实现的方式:

在同步服务器上开启sersync,将监控路径中的文件同步到目标服务器,因此需要在同步服务器配置sersync,在同步目标服务器配置rsync

实验机器的地址分配:

Rsync 服务器:   192.168.1.112

Sersync2 服务器:192.168.1.110

系统环境

[root@liyao home]# uname -a
       Linux liyao 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux
       [root@liyao home]#

一、     rsync 服务器的配置

1.       先查看下是否安装了 rsync 软件包

[root@liyao ~]# rpm -qa | grep rsync

rsync-2.6.8-3.1

[root@liyao ~]#

2.     如果系统默认安装了 rsync 软件包,我们可以使用 yum 命令将其卸载

[root@liyao ~]# yum remove -y rsync

Loaded plugins: fastestmirror

Setting up Remove Process

Resolving Dependencies

--> Running transaction check

---> Package rsync.i386 0:2.6.8-3.1 set to be erased

--> Finished Dependency Resolution

 

Dependencies Resolved

 

================================================================================

 Package         Arch           Version               Repository           Size

================================================================================

Removing:

 rsync           i386           2.6.8-3.1             installed           392 k

 

Transaction Summary

================================================================================

Remove        1 Package(s)

Reinstall     0 Package(s)

Downgrade     0 Package(s)

 

Downloading Packages:

Running rpm_check_debug

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

  Erasing        : rsync                                                    1/1

 

Removed:

  rsync.i386 0:2.6.8-3.1                                                       

 

Complete!

[root@liyao ~]#

3.     下载 rsync 3.0 的源码包

[root@liyao~]#wget-c

--2011-08-20 08:05:05-- 

Resolving rsync.samba.org... 216.83.154.106, 2001:470:1f05:1a07::1

Connecting to rsync.samba.org|216.83.154.106|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 790722 (772K) [application/x-gzip]

Saving to: `rsync-3.0.8.tar.gz'

 

100%[======================================>] 790,722      153K/s   in 5.7s   

 

2011-08-20 08:05:11 (135 KB/s) - `rsync-3.0.8.tar.gz' saved [790722/790722]

4.     将该软件包解压缩,并且进行编译安装

[root@liyao ~]# tar zxf rsync-3.0.8.tar.gz

[root@liyao ~]# cd rsync-3.0.8

[root@liyao rsync-3.0.8]# ./configure --prefix=/usr/ && make && make install

5.     建立 rsync 服务器的配置文件

uid = nobody

gid = nobody

use chroot = no

strict modes = yes

max connections = 200

pid file = /var/run/rsyncd.pid

lock file = /var/run/rsync.lock

log file = /var/log/rsyncd.log 

[test]

path = /home/

comment = test

read only = no

write only = no

ignore errors = yes

list = yes

uid = root

gid = root

6.     启动 rsync 的服务

  [root@liyao ~]# rsync --daemon

[root@liyao ~]# netstat -npl | grep 873

tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      7731/rsync         

tcp        0      0 :::873                      :::*                        LISTEN      7731/rsync 

 

二、     配置Sersync2 服务器

二进制直接可运行

wget

1、将该软件包下载下来之后解压缩,并进行安装

[root@liyao ~]# tar zxf sersync2.5_32bit_binary_stable_final.tar.gz

[root@liyao ~]# ls

anaconda-ks.cfg  install.log.syslog

GNU-Linux-x86    sersync2.5_32bit_binary_stable_final.tar.gz

install.log

[root@liyao ~]# cd GNU-Linux-x86/

[root@liyao GNU-Linux-x86]# ls

confxml.xml  sersync2

[root@liyao GNU-Linux-x86]# mkdir /etc/sersync2

[root@liyao GNU-Linux-x86]# cp confxml.xml /etc/sersync2/

[root@liyao GNU-Linux-x86]# cp sersync2 /usr/bin/

# 安装该软件只要把软件中的文件拷贝到相应的目录即可

2. 修改 Sersync2 的配置文件

[root@liyao ~]# cat /etc/sersync2/confxml.xml

   

   

   

   

       

       

       

       

   

   

       

       

       

       

       

       

       

       

   

 

   

       

           

            # 指定 rsyncd 服务器的地址和备份的模块名称

           

           

       

       

           

           

           

           

           

       

       

# 指定日志存放的路径

       

           

               

               

           

       

       

   

 

   

         

       

           

           

       

   

 

   

       

           

       

   

   

       

           

           

           

       

    

[root@liyao ~]#

3. 我们来运行如下的备份命令

在运行备份命令之前我们先看下 /home 这个目录下面有文件或者是目录

[root@liyao home]# ls -l

total 4

drwxr-xr-x 2 root root 4096 Aug 20 08:51 liyao

[root@liyao home]#

[root@liyao ~]# sersync2 -r -d -o /etc/sersync2/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:  /etc/sersync2/confxml.xml

daemon thread num: 10

parse xml config file

host ip : localhost     host port: 8008

daemon start,sersync run behind the console

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 /home && rsync -artuz -R --delete ./ 192.168.1.112::test >/dev/null 2>&1

run the sersync:

watch path is: /home

4. 我们到 rsyncd 服务器(1.112)的 /home 目录下看看是否有我在 1.110 /home/liyao 这个目录

[root@liyao home]# ls

liyao

[root@liyao home]#

 

那我们在从 1.110 的 /home 目录下创建 abc 目录,不用执行任何命令他会自动同步到 1.112 上

[root@liyao home]# mkdir abc

[root@liyao home]# ls

abc  liyao

[root@liyao home]#

 

我们在去 1.112 上去看下,abc 目录已经同步过来了

[root@liyao home]# ll

total 8

drwxr-xr-x 2 root root 4096 Aug 21 04:12 abc

drwxr-xr-x 2 root root 4096 Aug 21 04:05 liyao

[root@liyao home]#

 

OK ,这样我们就大功告成了。

阅读(424) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~