5.1 ドキュメントで想定している環境
このドキュメントで想定しているネットワークの環境は次です。
● ゲートウェイのIPアドレス192.168.1.1
● サブネットマスク 255.255.255.0
● 主サーバのIPアドレス192.168.1.11
● 従サーバのIPアドレス192.168.1.12
● プリンタのIPアドレス192.168.1.111
5.2 IP アドレスの固定
IPアドレスを固定するには/etc/network/interfacesを次のように編集します。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface auto lo
iface lo inet loopback
# The primary network interface
auto eth0 # イーサネットデバイス(eth1やeth2となる事も有り) iface eth0 inet static
address 192.168.1.11 # マシンのIPアドレス
netmask 255.255.255.0 # 参加するネットワークのネットマスク gateway 192.168.1.1 # 参加するネットワークのゲートウェイ
5.3 2 台運用の設定
主従サーバは新規にセットアップされているとしています。
5.3.1 従サーバでの作業
jma-receiptのセットアップにより追加されたPostgreSQLのorcaユーザにパスワード
を設定します。ここではパスワードをorca123として以下のように設定しますが、実際 には別のパスワードを設定して下さい。
続いて主サーバから接続できるように/etc/postgresql/8.1/main/postgresql.conf と/etc/postgresql/8.1/main/pg_hba.confを書き換えて下さい。
48
#---
# FILE LOCATIONS
# CONNECTIONS AND AUTHENTICATION
#---
# - Connection Settings -
listen_addresses = '*' #シャープを取り外してlocalhostを*に変更 # comma-separated list of addresses;
# defaults to 'localhost', '*'
= all
port = 5432
max_connections = 100
# note: increasing max_connections costs ~400 bytes of shared memory per
/etc/postgresql/8.1/main/postgresql.conf
# sudo -u postgres psql template1
template1=# ALTER USER orca WITH PASSWORD 'orca123';
ALTER ROLE template1=# \q
# gedit /etc/postgresql/8.1/main/postgresql.conf
最後に設定を反映させるためにPostgreSQLを再起動します。
5.3.2 主サーバでの作業
次のコマンドで主サーバから従サーバへの接続を試します。
# Database administrative login by UNIX sockets
local all postgres ident sameuser
# TYPE DATABASE USER CIDR-ADDRESS METHOD host orca orca 192.168.1.11/32 password
# "local" is for Unix domain socket connections only
local all all ident sameuser
# IPv4 local connections:
host all all 127.0.0.1/32 md5 /etc/postgresql/8.1/main/pg_hba.conf
# sudo -u orca psql -h 192.168.1.12 -W orca
> Password: orca orca=> \q
#
# gedit /etc/postgresql/8.1/main/pg_hba.conf
# /etc/init.d/postgresql-8.1 restart
/etc/jma-receipt/dbgroup.incのlogセクションを次のように書き換えます。
dbredirectorを有効にするためにdpkg-reconfigureを行いdbredirectorを有効にして
ください。その後日レセを再起動します。
5.3.3 二台運用の確認
従サーバ側で次のコマンドを実行し、主サーバからの接続があることを確認してくださ い
次のように表示されて、192.168.1.11からの接続がある事を確認して下さい。
50 db_group "log" {
priority 100;
type "PostgreSQL";
port "192.168.1.12";
name "orca";
user "orca";
password "orca123";
file "/var/lib/jma-receipt/dbredirector/orca.log";
redirect_port "localhost";
};
$ ps ax | grep pos
23101 ? S 0:00 /usr/lib/postgresql/bin/postmaster -D/dbdata/data
23104 ? S 0:01 postgres: stats buffer process 23106 ? S 0:02 postgres: stats collector process 23734 ? S 0:01 postgres: orca orca 192.168.1.11 idle
5.4 主従データベースの同期の取り方
次のコマンドを主サーバーで入力して下さい。`date`を括っている`はバッククォート です。
このコマンドで従サーバーのDBが主サーバーのDBと同じ内容になります。また/tmp
に今日の日付でデータベースのダンプが作成されます。どのようなSQLが流れたか確認 したい場合にはそちらを確認して下さい。
pg_dumpの-cオプションは最初にTABLEを消すためのオプションです。従側が
dropdb orca->createdb orcaの後の状態などテーブルが無い場合には付ける必要はあ
りません。
# /etc/init.d/jma-receipt stop
# sudo -u orca pg_dump -c -O orca | \
tee /tmp/orca_db_`date +%Y%m%d`.dump | \ sudo -u orca psql -h 192.168.1.12 -W orca
# /etc/init.d/jma-receipt start