系統環境: rhel6 x86_64 iptables and selinux disablednode
主機:192.168.122.160 server60.example.comlinux
192.168.122.154 server54.example.comc++
相關網址: rpm.pbone.netsql
ftp://ftp.gnutls.org/pub/gnutls/libtasn1/libtasn1-2.1.tar.gz apache
http://www.sqlite.org/sqlite-2.8.17.tar.gz vim
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 socket
http://oss.linbit.com/csync2/csync2-1.34.tar.gz tcp
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
如下步驟在server60和server54上實施:
[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/
如下步驟在server60和server54上實施:
[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處理.