Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

62.5. csync2 - cluster synchronization tool

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

62.5.1. server

过程 62.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			
    			

62.5.2. node

过程 62.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
    			

62.5.3. test

过程 62.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				
    				

62.5.4. Advanced Configuration

例 62.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;
}			
			

62.5.5. 编译安装

过程 62.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