天天看點

CentOS環境下安裝Postgresql以及配置Slony-i

首先安裝Postgresql資料庫:

然後修改/var/lib/pgsql/data/pg_hba.conf的設定:

啟動postgresql

建立資料庫和加入plpgsql語言支援:

首先安裝perl-DBI.i386,否則,會出現perl dbi is needed的錯誤。

安裝好slony後,開始配置系統環境。

編寫conn.nfo配置檔案

[code]

cp /etc/slon.conf /etc/slony_test.conf

[/code]

将slony_test.conf中的cluster_name、conninfo改為自己的設定

[code]

vi /etc/sysconfig/pgsql/slony_test

//vi 中填寫基本資訊

SLONYCONF=/etc/slony_test.conf

SLONYDIR=/var/db/slony_test

SLONLOG=/var/log/slony_test.log

SLONYOPTS="-d 1"

CONNINFO='user=user_test password=123456 dbname=foo host=192.168.21.129'

CLUSTER=slony_test

[/code]

編寫/etc/init.d/slony_test檔案用以控制slon的啟動,停止

[code]

chmod a+x /etc/init.d/slony_test

slonik

>init cluster ( id = 1,comment='Master Node');

//回車,然後ctrl+d兩次

[/code]

然後,将slave伺服器的slony以及資料庫環境同樣配置好後,[color=red]在從伺服器上執行[/color]

[code]

slonik

>store node ( id = 2,comment = 'Slave Node');

>store path ( server = 1,client =2,conninfo='dbname = foo host = 192.168.21.129 user = user_test password=123456');

>store path ( server = 2,client =1,conninfo='dbname = foo host = 192.168.21.130 user = user_test password=123456');

//回車,然後ctrl+d兩次

/etc/init.d/slony_test start //主從伺服器都要啟動

tail -f /var/log/slony_test.log //檢視日志

[/code]

用pgadmin登陸兩個資料庫,在主資料庫伺服器中建立一個set,然後将表以及序列添加到set中,然後再建立一個subscribe。

重新整理從伺服器,看看是不是資料已經同步過來了。

注意:

1.在建立set之前,要保證兩個資料庫都有相同的資料庫表結構

2.添加到叢集的資料庫表必須有主鍵

3.出現 db_getLocalNodeId() returned 2 - wrong database?錯誤,請檢查配置檔案是否正确設定,以及slonik中的code是否正确

4.在主伺服器初始化叢集後,在從伺服器store node以及建立listisen和path

5.subscribe送出資料集合,在建立subscribe時請選中forward,即可以有子集。

繼續閱讀