当前位置: 首页 > 工具软件 > Csync2 > 使用案例 >

4.4. csync2 - cluster synchronization tool

狄灵均
2023-12-01

homepage: http://oss.linbit.com/

4.4.1. server

过程 4.3. Install and setup csync2 on Ubuntu

  1. installation

    $ sudo apt-get install csync2 sqlite3 openssl xinetd

    The following line will be added to your /etc/inetd.conf file:

    $ cat /etc/inetd.conf
    csync2          stream  tcp     nowait  root    /usr/sbin/csync2        csync2 -i

    If you are indeed using xinetd, you will have to convert the above into /etc/xinetd.conf format, and add it manually.

    service csync2
    {
    	disable = no
    	protocol = tcp
    	socket_type = stream
    	wait = no
    	user = root
    	server = /usr/sbin/csync2
    	server_args = -i
    }

    /etc/services

    $ cat /etc/services |grep csync2
    csync2          30865/tcp                       # cluster synchronization tool
  2. create a self-signed SSL certificate for csync2

    sudo openssl genrsa -out /etc/csync2_ssl_key.pem 1024
    sudo openssl req -new -key /etc/csync2_ssl_key.pem -out /etc/csync2_ssl_cert.csr
    sudo openssl x509 -req -days 600 -in /etc/csync2_ssl_cert.csr -signkey /etc/csync2_ssl_key.pem -out /etc/csync2_ssl_cert.pem

    $ sudo csync2 -k /etc/csync2_ssl_cert.key
  3. After having done everything, we are now going to configure Csync2 so that we can determine which files are going to be synchronized.

    For this example, we are going to synchronize /etc/apache2 and /etc/mysql. For that we open /etc/csync2.cfg and we configure it like this:

    $ sudo vim /etc/csync2.cfg
    # please see the REAMDE file how to configure csync2
    
    group testing #group name, we can have multiple groups
    {
        host master; #master server
        host (slave); #slave server
        #host (node1);
    
        key /etc/csync2_ssl_cert.key;
    
        include /etc/apache2/;
        include /home/neo;
    
        backup-directory /var/backups/csync2;
        backup-generations 3;
        auto none; #no automatic sync
    }
  4. hosts

    $ sudo vim /etc/hosts			
    192.168.245.131 slave
  5. restart

    $ sudo /etc/init.d/xinetd restart

4.4.2. node

过程 4.4. node

  1. login to slave node

    neo@slave:~$ sudo vim /etc/hosts			
    192.168.245.129 master
  2. install

    $ sudo apt-get install csync2 xinetd
  3. copy config file from master

    neo@slave:~$  sudo scp root@master:/etc/csync2* /etc/
  4. restart

    neo@slave:~$ sudo /etc/init.d/xinetd restart

4.4.3. test

过程 4.5. testing

  1. master

    neo@master:/etc/apache2$ sudo touch test.master
    neo@master:/etc/apache2$ sudo csync2 -x
  2. node

    neo@slave:/etc/apache2$ ls test.master -l
    -rw-r--r-- 1 root root 0 2008-10-31 06:37 test.master

4.4.4. Advanced Configuration

例 4.7. /etc/csync2.cfg

$ sudo cat /etc/csync2.cfg

# please see the REAMDE file how to configure csync2
# group name, we can have multiple groups

group www {
    host master;
    host (slave);

    key /etc/csync2_ssl_cert.key;

    include /etc/apache2/;
    include /etc/csync2.cfg;
    include /var/www;
    include %homedir%/neo;
    exclude %homedir%/neo/temp;
    exclude *~ .*;

action
{
        pattern /etc/apache2/httpd.conf;
        pattern /etc/apache2/sites-available/*;
        exec "/usr/sbin/apache2ctl graceful";
        logfile "/var/log/csync2_action.log";
        do-local;
}

    backup-directory /var/backups/csync2;
    backup-generations 3;
    auto none;
}

prefix homedir
{
        on *: /home;
}

4.4.5. 编译安装

过程 4.6. 

  • # yum install byacc -y
    # tar zxvf librsync-0.9.7.tar.gz
    # cd librsync-0.9.7
    ./configure --prefix=/usr/local/librsync-0.9.7
    # make && make install
    # www.sqlite.org
    # wget http://www.sqlite.org/sqlite-3.7.2.tar.gz
    # tar zxvf sqlite-3.7.2.tar.gz
    # www.gnu.org/software/gnutls/
    # wget http://ftp.gnu.org/pub/gnu/gnutls/gnutls-2.10.1.tar.bz2
    # tar jxvf gnutls-2.10.1.tar.bz2
    # wget http://oss.linbit.com/csync2/csync2-1.34.tar.gz
    # tar csync2-1.34.tar.gz
    # ./configure --prefix=/usr/local/csync2-1.34 --with-librsync-source=/usr/local/src/librsync-0.9.7.tar.gz --with-libsqlite-source=/usr/local/src/sqlite-3.7.2.tar.gz --disable-gnutls




原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

 类似资料: