<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>16hot 的博客 &#187; csync2</title>
	<atom:link href="http://www.16hot.com/tag/csync2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.16hot.com</link>
	<description>技术、工作、生活，坚持一种信念，一切皆有可能……</description>
	<lastBuildDate>Sat, 07 Jan 2012 11:09:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>FreeBSD下使用csync2分布同步</title>
		<link>http://www.16hot.com/2010/07/1003/</link>
		<comments>http://www.16hot.com/2010/07/1003/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 02:53:35 +0000</pubDate>
		<dc:creator>16hot</dc:creator>
				<category><![CDATA[BSD/linux]]></category>
		<category><![CDATA[csync2]]></category>
		<category><![CDATA[freebsd]]></category>

		<guid isPermaLink="false">http://blog.isyi.com/?p=1003</guid>
		<description><![CDATA[1、简述 最近因项目需要，找了相关的开源同步解决方案。由于采用FreeBSD系统，有些Linux专用的程序，是不能使用的了。即使可以使用，配置起来太 麻烦，需要Linux虚拟环境。这样代价太高。rsync，mrsync，等都看了遍，最终选择了csync2。 官方网站： http://oss.linbit.com/csync2/ 使用手册： http://oss.linbit.com/csync2/paper.pdf 官方发布的正式版是1.34，需要sqlite2的支持。如果想用sqlite3，就需要从他们svn更新最新源码回来。SVN里的版本已经支持 sqlite3了。 使用SVN获取最新源码： $ svn co  http://svn.linbit.com/csync2/trunk csync2-trunk 由于SVN的源码文件里，没有configure文件，需要自己手工生成。源码目录里有个autogen.sh文件，需要修改下，才能执行。 $ cd csync2-trunk $ vi autogen.sh 将 aclocal-1.7 autoheader automake-1.7 &#8211;add-missing &#8211;copy autoconf 改为 aclocal-1.9 autoheader automake-1.9 &#8211;add-missing &#8211;copy autoconf 具体版本号，视里面已经安装的aclocal和automake版本来设置。 然后执行： $ autogen.sh 执行过程中，会提示一些信息，基本不用管它。这时候生成configure文件了。不过如果现在就执行./configure，还会报4437行错误。将那行注释掉就好了。 #AM_PATH_LIBGNUTLS(1.0.0,0 ,  AC_MSG_ERROR([[gnutls not found; install gnutls, gnutls-openssl and libtasn1 packages for your system [...]]]></description>
			<content:encoded><![CDATA[<p>1、简述</p>
<p>最近因项目需要，找了相关的开源同步解决方案。由于采用FreeBSD系统，有些Linux专用的程序，是不能使用的了。即使可以使用，配置起来太 麻烦，需要Linux虚拟环境。这样代价太高。rsync，mrsync，等都看了遍，最终选择了csync2。</p>
<blockquote><p>官方网站： http://oss.linbit.com/csync2/</p>
<p>使用手册： http://oss.linbit.com/csync2/paper.pdf</p></blockquote>
<p>官方发布的正式版是1.34，需要sqlite2的支持。如果想用sqlite3，就需要从他们svn更新最新源码回来。SVN里的版本已经支持 sqlite3了。</p>
<p>使用SVN获取最新源码：</p>
<blockquote><p>$ svn co  http://svn.linbit.com/csync2/trunk csync2-trunk</p></blockquote>
<p>由于SVN的源码文件里，没有configure文件，需要自己手工生成。源码目录里有个autogen.sh文件，需要修改下，才能执行。</p>
<blockquote><p>$ cd csync2-trunk<br />
$ vi autogen.sh</p></blockquote>
<p>将</p>
<blockquote><p>aclocal-1.7<br />
autoheader<br />
automake-1.7 &#8211;add-missing &#8211;copy<br />
autoconf</p></blockquote>
<p>改为</p>
<blockquote><p>aclocal-1.9<br />
autoheader<br />
automake-1.9 &#8211;add-missing &#8211;copy<br />
autoconf</p></blockquote>
<p>具体版本号，视里面已经安装的aclocal和automake版本来设置。</p>
<p>然后执行：</p>
<blockquote><p>$ autogen.sh</p></blockquote>
<p>执行过程中，会提示一些信息，基本不用管它。这时候生成configure文件了。不过如果现在就执行./configure，还会报4437行错误。将那行注释掉就好了。</p>
<blockquote><p>#AM_PATH_LIBGNUTLS(1.0.0,0 ,  AC_MSG_ERROR([[gnutls not found; install gnutls, gnutls-openssl and libtasn1 packages for your system or run configure with --disable-gnutls]]) )</p></blockquote>
<p>2、安装</p>
<p>在安装之前先安装相关的依赖包。下面时我用ports安装csync2-1.34时自动安装上的依赖包：</p>
<blockquote><p>$pkg_info -r csync2-1.34_8<br />
Information for csync2-1.34_8:</p>
<p>Depends on:<br />
Dependency: pkg-config-0.23_1<br />
Dependency: libtasn1-2.6<br />
Dependency: sqlite-2.8.17_1<br />
Dependency: libiconv-1.13.1_1<br />
Dependency: gettext-0.18_1<br />
Dependency: popt-1.14_1<br />
Dependency: librsync-0.9.7_2<br />
Dependency: libgpg-error-1.7_1<br />
Dependency: libgcrypt-1.4.5<br />
Dependency: gnutls-2.8.6_1</p></blockquote>
<p>由于SVN版本使用的是sqlite3，所以还需要安装sqlite3-3.6.23.1_1。这些软件包，在/usr/ports 中安装就可以了。</p>
<blockquote><p># setenv LOCALBASE /usr/local/<br />
# env CPPFLAGS=&#8221;-I${LOCALBASE}/include&#8221; LDFLAGS=&#8221;-L${LOCALBASE}/lib&#8221; LIBGNUTLS_CONFIG=&#8221;${LOCALBASE}/bin/pkg-config gnutls&#8221; ./configure<br />
# make<br />
# make install</p></blockquote>
<p>没有什么意外的话，就OK了。如果提示缺什么软件包，到ports里安装。</p>
<p>3、配置</p>
<p>下面是源码包里带的配置文件范例：</p>
<blockquote><p>% cat csync2.cfg<br />
# Csync2 Example Configuration File<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
#<br />
# Please read the documentation:<br />
# http://oss.linbit.com/csync2/paper.pdf</p>
<p># group mygroup<br />
# {<br />
#     host host1 host2 (host3);<br />
#     host host4@host4-eth2;<br />
#<br />
#     key /etc/csync2.key_mygroup;<br />
#<br />
#     #<br />
#     # WARNING:<br />
#     # You CANNOT use paths containing a symlink<br />
#     # component in include/exclude options!<br />
#     #<br />
#     # Here is a real-life example:<br />
#     # Suppose you have some 64bit Linux systems<br />
#     # and /usr/lib/ocf is what you want to keep<br />
#    # in sync. On 64bit Linux systems, /usr/lib<br />
#     # is usually a symlink to /usr/lib64.<br />
#     # This does not work:<br />
#     #   include /usr/lib/ocf;<br />
#     # But this does work:<br />
#     #   include /usr/lib64/ocf;<br />
#     #<br />
#<br />
#     include /etc/apache;<br />
#     include %homedir%/bob;<br />
#     exclude %homedir%/bob/temp;<br />
#     exclude *~ .*;<br />
#<br />
#     action<br />
#     {<br />
#         pattern /etc/apache/httpd.conf;<br />
#         pattern /etc/apache/sites-available/*;<br />
#         exec &#8220;/usr/sbin/apache2ctl graceful&#8221;;<br />
#         logfile &#8220;/var/log/csync2_action.log&#8221;;<br />
#         do-local;<br />
#        # you can use do-local-only if the execution<br />
#        # should be done locally only<br />
#        # do-local-only;<br />
#     }<br />
#<br />
#     # The backup-directory needs to be created first!<br />
#     backup-directory /var/backups/csync2;<br />
#     backup-generations 3;<br />
#<br />
#     auto none;<br />
# }<br />
#<br />
# prefix homedir<br />
# {<br />
#     on host[12]: /export/users;<br />
#     on *:        /home;<br />
# }</p></blockquote>
<p>下面是我的配置：</p>
<blockquote><p># vi /usr/local/etc/csync2.cfg</p>
<p># Csync2 Example Configuration File<br />
# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
#<br />
# Please read the documentation:<br />
# http://oss.linbit.com/csync2/paper.pdf</p>
<p>group mygroup<br />
{<br />
host fb1.isyi.com fb50.isyi.com fb51.isyi.com;</p>
<p>key /opt/etc/isyi.key;<br />
include /opt/www/test;</p>
<p>action<br />
{<br />
pattern /opt/www/test/*;<br />
exec &#8220;echo ok &gt;&gt; /tmp/csync2.log&#8221;;<br />
}<br />
auto younger;<br />
}</p></blockquote>
<p>配置好后，还需要修改/etc/hosts文件，将主机名和IP设置好。这个配置，三台服务器都需要配置一样。</p>
<blockquote><p>192.168.56.1  fb1.isyi.com<br />
192.168.56.50 fb50.isyi.com<br />
192.168.56.51 fb51.isyi.com</p></blockquote>
<p>生成key文件，这个key文件，需要复制到三台服务器，保证一样，否则不能同步：</p>
<blockquote><p># cd /opt/etc/<br />
# csync2 -k isyi.key</p></blockquote>
<p>生成CERT文件，需要在三台服务器分别生成：</p>
<blockquote><p>setenv etc_path &#8220;/usr/local/etc&#8221;<br />
openssl genrsa -out ${etc_path}/csync2_ssl_key.pem 1024<br />
openssl req -batch -new -key ${etc_path}/csync2_ssl_key.pem -out ${etc_path}/csync2_ssl_cert.csr<br />
openssl x509 -req -days 2000 -in ${etc_path}/csync2_ssl_cert.csr -signkey ${etc_path}/csync2_ssl_key.pem -out ${etc_path}/csync2_ssl_cert.pem</p></blockquote>
<p>4、启动服务</p>
<p>分别在三台服务器执行：</p>
<blockquote><p># /usr/local/sbin/csync2 -ii -vv&amp;</p></blockquote>
<p>5、执行同步</p>
<p>在主服务器，需要向其他服务器同步的服务器执行：</p>
<blockquote><p># /usr/local/sbin/csync2 -xvv</p></blockquote>
<p>6、附录</p>
<p>6.1、csync2的help</p>
<blockquote><p>% ./csync2</p>
<p>csync2 SNAPSHOT &#8211; cluster synchronization tool, 2nd generation<br />
LINBIT Information Technologies GmbH &lt;http://www.linbit.com&gt;<br />
Copyright (C) 2004, 2005  Clifford Wolf &lt;clifford@clifford.at&gt;<br />
This program is free software under the terms of the GNU GPL.</p>
<p>Usage: ./csync2 [-v..] [-C config-name] \<br />
[-D database-dir] [-N hostname] [-p port] ..</p>
<p>With file parameters:<br />
-h [-r] file..      Add (recursive) hints for check to db<br />
-c [-r] file..      Check files and maybe add to dirty db<br />
-u [-d] [-r] file.. Updates files if listed in dirty db<br />
-o [-r] file..      Create list of files in compare-mode<br />
-f [-r] file..      Force this file in sync (resolve conflict)<br />
-m file..       Mark files in database as dirty</p>
<p>Simple mode:<br />
-x [-d] [[-r] file..]   Run checks for all given files and update<br />
remote hosts.</p>
<p>Without file parameters:<br />
-c  Check all hints in db and eventually mark files as dirty<br />
-u [-d] Update (transfer dirty files to peers and mark as clear)</p>
<p>-H  List all pending hints from status db<br />
-L  List all file-entries from status db<br />
-M  List all dirty files from status db</p>
<p>-S myname peername  List file-entries from status db for this<br />
synchronization pair.</p>
<p>-T              Test if everything is in sync with all peers.</p>
<p>-T filename         Test if this file is in sync with all peers.</p>
<p>-T myname peername  Test if this synchronization pair is in sync.</p>
<p>-T myname peer file Test only this file in this sync pair.</p>
<p>-TT As -T, but print the unified diffs.</p>
<p>The modes -H, -L, -M and -S return 2 if the requested db is empty.<br />
The mode -T returns 2 if both hosts are in sync.</p>
<p>-i  Run in inetd server mode.<br />
-ii Run in stand-alone server mode.<br />
-iii    Run in stand-alone server mode (one connect only).</p>
<p>-R  Remove files from database which do not match config entries.</p>
<p>Modifiers:<br />
-r  Recursive operation over subdirectories<br />
-d  Dry-run on all remote update operations</p>
<p>-B  Do not block everything into big SQL transactions. This<br />
slows down csync2 but allows multiple csync2 processes to<br />
access the database at the same time. Use e.g. when slow<br />
lines are used or huge files are transferred.</p>
<p>-A  Open database in asynchronous mode. This will cause data<br />
corruption if the operating system crashes or the computer<br />
loses power.</p>
<p>-I  Init-run. Use with care and read the documentation first!<br />
You usually do not need this option unless you are<br />
initializing groups with really large file lists.</p>
<p>-X  Also add removals to dirty db when doing a -TI run.<br />
-U  Don&#8217;t mark all other peers as dirty when doing a -TI run.</p>
<p>-G Group1,Group2,Group3,&#8230;<br />
Only use this groups from config-file.</p>
<p>-P peer1,peer1,&#8230;<br />
Only update this peers (still mark all as dirty).<br />
Only show files for this peers in -o (compare) mode.</p>
<p>-F  Add new entries to dirty database with force flag set.</p>
<p>-t  Print timestamps to debug output (e.g. for profiling).</p>
<p>-s filename<br />
Print timestamps also to this file.</p>
<p>-W fd   Write a list of directories in which relevant files can be<br />
found to the specified file descriptor (when doing a -c run).<br />
The directory names in this output are zero-terminated.</p>
<p>Creating key file:<br />
./csync2 -k filename</p>
<p>Csync2 will refuse to do anything when a /var/etc/csync2.lock file is found.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.16hot.com/2010/07/1003/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

