Chinaunix首页 | 论坛 | 博客
  • 博客访问: 523480
  • 博文数量: 235
  • 博客积分: 1209
  • 博客等级: 少尉
  • 技术积分: 1417
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-19 19:59
文章分类

全部博文(235)

文章存档

2012年(107)

2011年(128)

分类:

2011-12-01 00:10:36

原文地址:csync2安装 作者:badb0y

源码编译的时候错误多多呀,改成yum了,很简单的OK了!!!!

yum install xinetd libgpg-error libgpg-error-devel libgcrypt libgcrypt-devel libtasn1 libtasn1-devel sqlite sqlite-devel librsync librsync-devel nettle nettle-devel gnutls-devel gnutls gnutls-utils  bison bison-devel bison-runtime flex -y

wget
tar zxvf sqlite-2.8.17.tar.gz
cd sqlite-2.8.17
./configure && make && make install
cd ..
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig

wget
tar zxvf csync2-1.34.tar.gz
cd csync2-1.34
./configure
make && make install
make cert
echo "csync2 30865/tcp" >> /etc/services
cd ..

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
 #only_from = 192.168.169.112 192.168.169.113 192.168.169.114
}

chkconfig xinetd on
service xinetd start

生成密钥
csync2 -k /etc/csync2.key

将key复制到另一台机器
scp -P22 /etc/csync2.key
scp -P22 /etc/csync2.cfg

/etc/hosts
192.168.2.11 server1
192.168.2.12 server2

hostname server1


vim /etc/csync2.cfg
..
group server
{
 host server1 server2; //定义组成员
 #
 key /etc/csync2.key;
 #
 include /opt; //需要同步的目录
 
 exclude /opt/attachments; //需要排除的目录。
 exclude /optforumdata; //需要排除同步的缓存目录。
 # include /etc/apache;
 # 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 /data/csync_backup; //防错备份目录,根据自己的需求设置。
 backup-generations 3;
 auto younger; //同步以最新的文件为标准更新.
 }
 #
 # prefix homedir
 # {
 # on host[12]: /export/users;
 # on *: /home;
# }


group server
{
        host server1 server2;
        key /etc/csync2.key;
        include /opt;
        exclude /opt/tmp;
        exclude *` .*;
        backup-directory /backup/csync_backup;
        backup-generations 3;
        auto younger;
}

 

csync2 -vvv -T 测试配置是否正解
csync2 -xv 执行同步命令
csync2 -xvvv 执行同步命令,并显示详细信息


wget
tar zxvf inotify-tools-3.13.tar.gz
cd inotify-tools-3.13
./configure && make && make install
cd ..

ldconfig


vim sync.sh

#!/bin/bash
src=/opt
/usr/local/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f' \
--exclude "\.swp$" \
-e close_write,modify,delete,create,attrib \
${src} \
| while read file
do
#csync2 -x >/dev/null 2>&1
csync2 -xv
echo "${src} was csynced....."
done

阅读(1446) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~