bucardo 安裝配置
本文轉自http://blog.osdba.net/?post=52
還沒來得及看,先轉了,有空看看
===============安裝bucardo===========================
bucardo是一個perl腳本,需要一些perl的包,先安裝這些包:
Test-Simple-0.98.tar.gz
ExtUtils-MakeMaker-6.56.tar.gz
DBI-1.616.tar.gz
version-0.91.tar.gz
DBD-Pg-2.18.1.tar.gz
DBIx-Safe-1.2.5.tar.gz
perl包的安裝方法都是到http://search.cpan.org找到這個包,下載下傳下來,一般習慣解壓到/usr/src目錄:
然後:
perl Makefile.PL
make
make install
安裝perl的包
先安裝DBI-1.616
http://search.cpan.org/CPAN/authors/id/T/TI/TIMB/DBI-1.616.tar.gz
安裝DBI前需要安裝:
http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/Test-Simple-0.98.tar.gz
http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/ExtUtils-MakeMaker-6.56.tar.gz
否則會報:
Warning: prerequisite ExtUtils::MakeMaker 6.48 not found. We have 6.30.
Warning: prerequisite Test::Simple 0.90 not found. We have 0.62.
安裝DBD-pg前需要先安裝version-0.91
http://search.cpan.org/CPAN/authors/id/J/JP/JPEACOCK/version-0.91.tar.gz
再安裝DBD-pg:
http://search.cpan.org/CPAN/authors/id/T/TU/TURNSTEP/DBD-Pg-2.18.1.tar.gz
安裝
http://bucardo.org/downloads/DBIx-Safe-1.2.5.tar.gz
安裝Bucardo5.0.0
http://blog.endpoint.com/2011/06/bucardo-multi-master-for-postgresql.html
===================bucardo4.4.4的配置====================================
在使用者的HOME目錄下建立一個.bucardorc檔案,在這個檔案中設定一些參數:
default_email_from = [email protected]
default_email_host = vip-smtp.vip.xyi.cn.alidc.net
default_email_to = [email protected]
log_conflict_file = /home/postgres/log/bucardo_conflict.log
piddir = /home/postgres/run
reason_file = /home/postgres/log/bucardo.restart.reason.log
warning_file = /home/postgres/log/bucardo.warning.log
syslog_facility = LOG_LOCAL1
bucardo會在所需要同步的資料庫中建一個名叫bucardo的資料庫,在其中存一些配置資訊,這個過
程是由bucardo_ctl install指令完成的:
bucardo_ctl install
完成後,我們把bucardo資料庫的搜尋路徑上加上bucardo這個schema名,以便連接配接到這個資料庫
後就可以使用/d看到這些配置表:
alter database bucardo set search_path="$user",public,bucardo;
下面的配置的環境:
主機1: 192.168.1.31
主機2: 192.168.1.32
我們在這兩台機器上的postgresql做雙向同步:
這兩台機器上的postgresql資料庫已經裝好。
操作步驟:
1. 在兩台機器上:
bucardo_ctl install
2. 在兩台機器上,先建我們要同步的資料庫:
createdb mydb
createlang plpgsql
注意需要plpgsql裝到資料庫中。
使用pgbench 建一些測試表。
pgbench -i mydb -s 300
我們同步就在pgbench_accounts pgbench_branches pgbench_tellers上進行:
3. bucardo中增加要同步的資料庫,主要是配置bucardo如何連接配接這些資料庫:
在第一台機器上:
bucardo_ctl add db db1 dbname=mydb sourcelimit=100 targetlimit=100
bucardo_ctl add db db2 dbname=mydb host=192.168.1.32 sourcelimit=100 targetlimit=100
這個指令中可以帶的參數,基本上都是資料庫連接配接參數:
name: the internal name used by Bucardo to refer to this database
port: the port this database runs on. Defaults to 5432.
host: the host this database is on. Defaults to no host (Unix socket)
user: the user to connect as. Defaults to 'bucardo'
pass: the password to connect with. Don't use this, use a .pgpass file instead!
conn: Any additional information add to the connection string, e.g. sslmode=require
sourcelimit: The maximum number of replication events that can run at one time using this database as a source. Defaults to 0 (no limit)
targetlimit: The maximum number of replication events that can run at one time using this database as a target. Defaults to 0 (no limit)
pgpass: Full path and filename of a Bucardo/pgpass file to use for this connection
由于我們是雙向同步,需要指定同步的預設的沖突處理方法:
alter table bucardo.goat alter standard_conflict set default 'latest';
沖突解決方法可為:
source
target
skip
random
latest
abort
4. 增加哪些表要同步:
在第一台機器上:
bucardo_ctl add table pgbench_accounts pgbench_branches pgbench_tellers db=db1 --herd=herd1 --verbose
這個步驟其實是在表上建觸發器,做完這個步驟後所産生的變化都會被同步
5. 增加群,群是為了便于管理同步中表的一個集合。
在第一台機器上:
bucardo_ctl add herd herd1 pgbench_accounts pgbench_branches pgbench_tellers
6. 增加同步
在第一台機器上:
bucardo_ctl add sync sync1 source=herd1 targetdb=db2 type=swap ping=yes
加同步的時候,實際上是把源資料庫上的群(群中包含了一些表)同步到目标資料庫中。
type為swap,就是兩個資料庫做雙向同步。
type 還可以有的值為:
pushdelta: master/slave模式,隻有主庫把資料同步到備庫
fullcopy: master/slave模式,全量同步
7. 如果初始時,源資料庫上有資料,而目标資料庫上沒有資料,需要開始時做一次全量同步,這種
方式在bucardo中叫onetimecopy,要執行ontimecopy,需要源資料中的表至少有一條資料,而
目标資料庫中的表不能有資料:
bucardo_ctl update sync sync onetimecopy=2
這可我們把同步的onetimecopy屬性設定為2,這樣當同步啟動後,會自動做一次全量同步,然後再
慢慢增量同步。
全量同步完後,會自動把狀态改為0。
8. 啟動同步:
bucardo_ctl start
9. 檢視同步狀态:
bucardo_ctl status
bucardo_ctl status sync1
============================= 日常維護操作 ===============================
1. bucardo使用觸發器把變化行的主鍵記到一張表中,是以這張表會變得越來越大,我們需要做一
個定時任務來清理這個表的内容:
0 2 * * * /usr/local/bin/psql -X -q -d mydb -U postgres -c "SELECT bucardo.bucardo_purge_delta('24 hours'::interval)"
2. 臨時停止和啟動同步的方法:
bucardo_ctl activate <syncname>
bucardo_ctl deactivate <syncname>
bucardo.sync中有:track_rates
設定為true。
3. onetimecopy:
bucardo_ctl update sync <syncname> onetimecopy=2
重新開機bucardo_ctl可以讓其開始複制
bucardo_ctl reload sync1好象也可以
4. 新增表的步驟:
bucardo_ctl add all tables
bucardo_ctl update sync <syncname> add table <tab1> <tab2> ...
bucardo_ctl validate <syncname>
bucardo_ctl update sync onetimecopy=2
bucardo_ctl update sync onetimecopy=2 rebuild_index=1
bucardo_ctl reload <syncname>
5. 移除表:
bucardo_ctl update sync <syncname> remove table foobar
bucardo_ctl update sync <syncname> remove sequence foobar_seq
bucardo_ctl reload <syncname>