系统环境rhel6.0,iptables和selinux关闭状态

desktop52.example.com 192.168.0.52
desktop97.example.com 192.168.0.97
两台主机的时间同步

安装软件
yum install gcc gcc-c++ libgpg-error libgpg-error-devel libgcrypt libgcrypt-devel -y

tar zxf libtasn1-2.1.tar.gz
cd libtasn1-2.1
./configure && make && make install

tar zxf sqlite-2.8.17.tar.gz
cd sqlite-2.8.17
./configure && make && make install

tar zxf librsync-0.9.7.tar.gz
cd librsync-0.9.7
./configure && make && make install

tar jxf gnutls-2.6.6.tar.bz2
cd gnutls-2.6.6
./configure && make && make install

echo "/usr/local/lib"  >> /etc/ld.so.conf
ldconfig /usr/local/lib

tar zxf inotify-tools-3.13.tar.gz
inotify-tools-3.13
./configure && make && make install

yum install byacc flex -y  #编译不会报错,但是安装时候会报错
tar zxf csync2-1.34.tar.gz
cd csync2-1.34
./configure && make && make install
相互同步的主机之间是通过ssl安全连接的
make cert
csync2 -k /etc/csync2.key  #制作密钥文件


2.配置csync2
yum install xinetd -y
vim /etc/xinetd.d/csync2
service csync2
{
        disable = no
        protocol = tcp
        flags = REUSE
        socket_type = stream
        wait = no
        user = root
        group = root
        server = /usr/local/sbin/csync2
        server_args = -i
}
man csync2
-i: Run in inetd server mode #运行在端口检测程序模式
vim /etc/services       #添加下面一行
csync2  30865/tcp

vim /etc/csync2.cfg
group mygroup
{
        host desktop52.example.com desktop97.example.com; (每台主机完整的主机名)
        #host host4@host4-eth2;
        key /etc/csync2.key;指定key文件的路径
        include /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/csync2; 防错备份目录,根据自己的需求设置,每台主机上都要有
backup-generations 3;
#
#auto younger; 同步以最新的文件为标准更新
}
#
# prefix homedir
#{
#on host[12]: /export/users;
#on *:   /home;
#}

scp /etc/csync2.* 192.168.0.97:/etc/    #将在一台主机上的配置和密钥拷贝到另一台上
csync2 -vvv -T 测试csync配置是否正确,

/etc/init.d/xinetd start  #启动服务
chkconfig xinetd on


三、检测
在一台主机上/csync2目录下创建、删除或更改文件
然后执行csyns2  -xv进行同步
查看另外一台主机/csync2目录下文件是否同步