系统环境: rhel6 x86_64 iptables and selinux disabled

主机:192.168.122.160 server60.example.com

192.168.122.154 server54.example.com

相关网址: rpm.pbone.net

ftp://ftp.gnutls.org/pub/gnutls/libtasn1/libtasn1-2.1.tar.gz

http://www.sqlite.org/sqlite-2.8.17.tar.gz

http://internode.dl.sourceforge.net/sourceforge/librsync/librsync-0.9.7.tar.gz

ftp://ftp.gnu.org/pub/gnu/gnutls/gnutls-2.6.6.tar.bz2

http://oss.linbit.com/csync2/csync2-1.34.tar.gz

http://jaist.dl.sourceforge.net/sourceforge/inotify-tools/inotify-tools-3.13.tar.gz


所需的包:librsync-0.9.7-15.el6.x86_64.rpm librsync-devel-0.9.7-15.el6.x86_64.rpm sqlite-2.8.17.tar.gz gnutls-2.6.6.tar.bz2 csync2-1.34.tar.gz


以下步骤在server60server54上实施:

[root@server60 kernel]# yum install libtasn1-devel make xinetd -y

[root@server60 kernel]# rpm -ivh librsync-0.9.7-15.el6.x86_64.rpm

[root@server60 kernel]# rpm -ivh librsync-devel-0.9.7-15.el6.x86_64.rpm

[root@server60 kernel]# tar zxf sqlite-2.8.17.tar.gz

[root@server60 kernel]# cd sqlite-2.8.17

[root@server60 sqlite-2.8.17]# ./configure

此时会出现如下错误:

(1)configure: error: no acceptable C compiler found in $PATH

(2)configure: error: C++ preprocessor "/lib/cpp" fails sanity check

 

解决方法如下:

(1)[root@server60 sqlite-2.8.17]# yum install gcc -y

(2)[root@server60 sqlite-2.8.17]# yum install gcc-c++ -y

 

[root@server60 sqlite-2.8.17]# make && make install

[root@server60 sqlite-2.8.17]# ldconfig

 

[root@server60 kernel]# tar jxf gnutls-2.6.6.tar.bz2

[root@server60 kernel]# cd gnutls-2.6.6

[root@server60 gnutls-2.6.6]# ./configure

此时会出现如下错误:

(1)*** libgcrypt was not found. You may want to get it from


解决方法如下:

[root@server60 gnutls-2.6.6]# yum install libgcrypt-devel -y

 

[root@server60 gnutls-2.6.6]# make && make install


[root@server60 kernel]# tar zxf csync2-1.34.tar.gz

[root@server60 kernel]# cd csync2-1.34

[root@server60 csync2-1.34]# yum install byacc flex -y

[root@server60 csync2-1.34]# ./configure

此时会出现如下错误:

(1)configure: error: gnutls not found; install gnutls, gnutls-openssl and libtasn1 packages for your system or run configure with --disable-gnutls


解决方法如下:

(2)[root@server60 csync2-1.34]# echo /usr/local/lib >> /etc/ld.so.conf

[root@server60 csync2-1.34]# ldconfig


[root@server60 csync2-1.34]# make && make install

 

以下步骤在server60上实施:

[root@server60 csync2-1.34]# make cert

[root@server60 csync2-1.34]# csync2 -k /etc/csync2.key (server54不用重新创建key,并且生成key时需要不断地移动鼠标或敲击键盘)

[root@server60 csync2-1.34]# vim /etc/csync2.cfg

group mygroup

{

host server60.example.com server54.example.com; (每台主机完整主机名)

# host host4@host4-eth2;

#

key /etc/csync2.key;

#

include /opt/csync2; (同步目录)

# include %homedir%/bob;

# exclude %homedir%/bob/temp;

# exclude *~ .*;

#

# action

# {

# pattern /etc/apache/httpd.conf;

# pattern /etc/apache/sites-available/*;

# exec "/usr/sbin/apache2ctl graceful";

# logfile "/var/log/csync2_action.log";

# do-local;

# }

#

# backup-directory /var/backups/csync2; (防错备份目录,根据自己的需求设置,每台主机上都要有)

# backup-generations 3;

#

auto younger; (同步以最新的文件为标准更新)

}

[root@server60 ~]# scp /etc/csync2* root@192.168.122.154:/etc/

[root@server60 ~]# cd /etc/xinetd.d/

[root@server60 xinetd.d]# cp rsync csync2

[root@server60 xinetd.d]# vim csync2

service csync2

{

disable = no

protocol = tcp

flags = REUSE

socket_type = stream

wait = no

user = root

server = /usr/local/sbin/csync2

server_args = -i

}

[root@server60 xinetd.d]# vim /etc/services

csync2 30865/tcp

[root@server60 xinetd.d]# scp /etc/xinetd.d/csync2 root@192.168.122.154:/etc/xinetd.d/

[root@server60 xinetd.d]# scp /etc/services root@192.168.122.154:/etc/


以下步骤在server60server54上实施:

[root@server60 ~]# mkdir /opt/csync2

[root@server60 xinetd.d]# /etc/init.d/xinetd start

[root@server60 xinetd.d]# netstat -antple

tcp 0 0 :::30865 :::* LISTEN 0 28973 24162/xinetd

能查看到30865端口说明启动成功.


测试同步是否正常:

注:所有机子上要有所有主机的解析

在两台机器中的任一台创建或者删除一个文件,然后查看其它机器是否创建或删除。

如果遇到问题就用csync2 -xv命令手动调试并,根据错误信息作调整。

:csync2相关命令介绍

csync2 -vvv -T 测试csync配置是否正确,可以看到相关SQL执行过程.

csync2 -xv 执行同步命令

csync2 -xvvv 执行同步命令,并显示出详细的信息.

应该注意的问题.

缓存相关的目录尽量不要用csync2去处理,这个程序目录尽量交给NFS处理.

posted on 2015-03-31 16:37  ↗℡.Koen↘  阅读(310)  评论(0编辑  收藏  举报