- 自鯖の状況
- 1st Server
- 1st@Apps::Apache
- 1st@Apps::MYSQL
- 1st@Apps::PostgreSQL
- 1st@Apps::W2Ch利用状況
- 1st@Apps::W2Chセッション数
- 1st@Apps::iptables
- 1st@Sensor::CPU温度
- 1st@Sensor::FAN回転数
- 1st@System::CPU
- 1st@System::CPU-0
- 1st@System::CPU-1
- 1st@System::CPU-2
- 1st@System::CPU-3
- 1st@System::LoadAvg
- 1st@System::Memory
- 1st@System::Process
- 1st@System::SWAP
- 1st@System::Uptime
- 1st@System::Users
- 1st@Traffic::Ether0
- 1st@Traffic::PPP0
- 1st@Traffic::Wlan
- iptables::ログ集計
- 1st Server
PostgreSQL::Slony
postgresでのレプリケーション
今回は、postgresのレプリケーションの勉強を行うに当たり、このブログのDBを2台のサーバで、同期を取ることにしました。
今回の教科書は、PCWEB(http://pcweb.mycom.co.jp/column/yetanother/030/)です
材料:
サーバ:1号機(SuseLinux:10.8.136.37)~このサーバ
ソフト:
postgresql-8.1.2(インストール済み)
Slony-1.1.5
サーバ:2号機(SuseLinux:10.8.136.16)~別途用意しました(昔の1号機)
ソフト:
postgresql-8.1.2
Slony-1.1.5
DB:
mt32
Table:対象は、以下の通り
mt32=# \dt List of relations Schema | Name | Type | Owner --------+-----------------+-------+---------- public | mt_author | table | postgres public | mt_blog | table | postgres public | mt_category | table | postgres public | mt_comment | table | postgres public | mt_config | table | postgres public | mt_entry | table | postgres public | mt_fileinfo | table | postgres public | mt_ipbanlist | table | postgres public | mt_log | table | postgres public | mt_notification | table | postgres public | mt_permission | table | postgres public | mt_placement | table | postgres public | mt_plugindata | table | postgres public | mt_session | table | postgres public | mt_tbping | table | postgres public | mt_template | table | postgres public | mt_templatemap | table | postgres public | mt_trackback | table | postgres
■インストール
2号機にpostgresql-8.1.2をインストールします
Download: http://www.postgresql.org/
# cd /usr/local/src # wget http://wwwmaster.postgresql.org/redir?ftp%3A%2F%2Fftp2.jp.postgresql.org%2Fpub%2Fpostgresql%2Fsource%2Fv8.1.2%2Fpostgresql-8.1.2.tar.gz # tar zxvf postgresql-8.1.2.tar.gz # cd postgresql-8.1.2 # useradd postgres # su - postgres $ ./configure --enable-multibyte=UTF-8 --without-readline $ make $ make install $ cd /usr/local/pgsql $ mkdir data $ initdb -no-locale $ createdb --encoding=UTF-8 mt32
次に1号機から、DBを持ってきます。
$ pg_dump -C -f mt32.dmp mt32 $ scp mt32.dmp root@10.8.136.16:/usr/local/src/ </block> そして、2号機で取り込みます。 <blockcode language='bash'> $ psql mt32 < mt32.dmp
DBがちゃんと取り込めていることを確認しら、slonyのインストールです
Download: http://gborg.postgresql.org/project/slony1/projdisplay.php
# cd /usr/local/src # wget http://developer.postgresql.org/~wieck/slony1/download/slony1-1.1.5.tar.bz2 # bzip2 -d slony1-1.1.5.tar.bz2 # su - postgres $ ./configure --with-pgsourcedir=../postgresql-8.1.2 $ make $make install
これでインストール完了です
続いて、設定を行います。
ここでは、1号機をマスター、2号機をスレーブとして扱います。
まずは、両方にSlonyで必要な手続き言語を登録します。
$ createlang plpgsql mt32
続いて、slonikコマンド経由で、マスターの設定を行います。
以下のファイルを作成して、実行します。
#!/bin/sh CLUSTERNAME=mt32 DB1=mt32 DB2=mt32 HOST1=10.8.136.37 HOST2=10.8.136.16 RUSER=postgres slonik <<_EOF_ cluster name = $CLUSTERNAME; node 1 admin conninfo = 'dbname=$DB1 host=$HOST1 user=$RUSER'; node 2 admin conninfo = 'dbname=$DB2 host=$HOST2 user=$RUSER'; init cluster ( id=1, comment = 'Master'); create set (id=1, origin=1, comment='All tables'); set add table (set id=1, origin=1, id=1, fully qualified name = 'public.mt_author', comment='mt_author'); set add table (set id=1, origin=1, id=2, fully qualified name = 'public.mt_blog', comment='mt_blog'); set add table (set id=1, origin=1, id=3, fully qualified name = 'public.mt_category', comment='mt_category'); set add table (set id=1, origin=1, id=4, fully qualified name = 'public.mt_comment', comment='mt_comment'); set add table (set id=1, origin=1, id=5, fully qualified name = 'public.mt_config', comment='mt_config'); set add table (set id=1, origin=1, id=6, fully qualified name = 'public.mt_entry', comment='mt_entry'); set add table (set id=1, origin=1, id=7, fully qualified name = 'public.mt_fileinfo', comment='mt_fileinfo'); set add table (set id=1, origin=1, id=8, fully qualified name = 'public.mt_ipbanlist', comment='mt_ipbanlist'); set add table (set id=1, origin=1, id=9, fully qualified name = 'public.mt_log', comment='mt_log'); set add table (set id=1, origin=1, id=10, fully qualified name = 'public.mt_notification', comment='mt_notification'); set add table (set id=1, origin=1, id=11, fully qualified name = 'public.mt_permission', comment='mt_permission'); set add table (set id=1, origin=1, id=12, fully qualified name = 'public.mt_placement', comment='mt_placement'); set add table (set id=1, origin=1, id=13, fully qualified name = 'public.mt_plugindata', comment='mt_plugindata'); set add table (set id=1, origin=1, id=14, fully qualified name = 'public.mt_session', comment='mt_session'); set add table (set id=1, origin=1, id=15, fully qualified name = 'public.mt_tbping', comment='mt_tbping'); set add table (set id=1, origin=1, id=16, fully qualified name = 'public.mt_template', comment='mt_template'); set add table (set id=1, origin=1, id=17, fully qualified name = 'public.mt_templatemap', comment='mt_templatemap'); set add table (set id=1, origin=1, id=18, fully qualified name = 'public.mt_trackback', comment='mt_trackback'); store node (id=2, comment = 'Slave'); store path (server = 1, client = 2, conninfo='dbname=$DB1 host=$HOST1 user=$RUSER'); store path (server = 2, client = 1, conninfo='dbname=$DB2 host=$HOST2 user=$RUSER'); store listen (origin=1, provider = 1, receiver =2); store listen (origin=2, provider = 2, receiver =1); _EOF_
マスター上でレプリケーションデーモンを起動します
$ slon mt32 "dbname=mt32 user=postgres host=10.8.136.37" &
続いて、スレーブ上でレプリケーションデーモンを起動します
$ slon mt32 "dbname=mt32 user=postgres host=10.8.136.16" &
これで、同期の準備が整いましたので、後は、スレーブ側で、同期の受けを作ります。
マスターと同じように下記のファイルを作成して実行します。
※実行すると同時に同期が始まります。
#!/bin/sh CLUSTERNAME=mt32 DB1=mt32 DB2=mt32 HOST1=10.8.136.37 HOST2=10.8.136.16 RUSER=postgres slonik <<_EOF_ cluster name = $CLUSTERNAME; node 1 admin conninfo = 'dbname=$DB1 host=$HOST1 user=$RUSER'; node 2 admin conninfo = 'dbname=$DB2 host=$HOST2 user=$RUSER'; subscribe set ( id = 1, provider = 1, receiver = 2, forward = no); _EOF_

