CSYNC双向同步
该服务所需软件包下载地址
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
主机:
server11 192.168.0.111
host11 192.168.0.210
1.安装软件 (以下步骤在每台主机上操作)
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
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
make cert
csync2 -k /etc/csync2.key
scp /etc/csync2.key [email protected]:/etc (host11上不用重新创建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
}
vim /etc/services
csync2 30865/tcp
mkdir /var/csync2
vim /etc/csync2.cfg
# Csync2 Example Configuration File
# ---------------------------------
#
# Please read the documentation:
# http://oss.linbit.com/csync2/paper.pdf
group mygroup
{
host server11.example.com host11.example.com; (每台主机完整的主机名,配置另一台机器时反过来写)
# host host4@host4-eth2;
#
key /etc/csync2.key;
#
include /www; 需要同步的目录
# 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;
# }
service xinetd start
chkconfig xinetd on
3>测试同步是否正常
在两台机器中的任一台创建或者删除一个文件,然后查看其它机器是否创建或删除。
如果遇到问题就用csync2 -xv命令手动调试并根据错误信息作调整。
注:csync2相关命令介绍
csync2 -vvv -T 测试csync配置是否正确,可以看到相关SQL执行过程.
csync2 -xv 执行同步命令
csync2 -xvvv 执行同步命令,并显示出详细的信息.
应该注意的问题.
缓存相关的目录尽量不要用csync2去处理,这个程序目录尽量交给NFS处理.
http://oss.linbit.com/csync2/paper.pdf