_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › pgpool-II

Contents

1
2 server
3 pgpool-II install
4 postgresql9.4 install
5 master れ
6 slave れ
7 蠍壱
8 pgpool-II れ
9
10 谿瑚


煙...

1 #

  • postgresql, pgpool-II れ
  • replication れ
  • pgpool-II れ

2 server #

  • os: centos7
  • pgpool : 192.168.56.101
  • db1: 192.168.56.102 --> master
  • db2: 192.168.56.103 --> slave

pgpool2.png

3 pgpool-II install #

192.168.56.101 覯 install
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
yum update
yum install pgpool-II-pg94

4 postgresql9.4 install #

192.168.56.102, 192.168.56.103 覯 install
rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-7-x86_64/pgdg-centos94-9.4-1.noarch.rpm
yum update
yum install postgresql94-server postgresql94-contrib


/usr/pgsql-9.4/bin/postgresql94-setup initdb


systemctl enable postgresql-9.4
systemctl start postgresql-9.4


firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload


setsebool -P httpd_can_network_connect_db 1

su - postgres
psql
\password postgres 

5 master れ #

.conf 殊 襴襦 企
#locate pg_hba.conf
#/var/lib/pgsql/9.4/data/pg_hba.conf

cd /var/lib/pgsql/9.4/data/

pg_hba.conf殊 replication 覯ip 焔
{{
vi pg_hba.conf
}}}

host    replication     postgres        192.168.56.102/32          trust
host    replication     postgres        192.168.56.103/32          trust
host    all             all             192.168.56.101/32       trust
host    all             all             192.168.56.1/32         trust


postgesql.conf
vi postgresql.conf

wal_level=host_standby #archive襦 れ覃 slave 蠏殊 
max_wal_senders=10 #multi slave node  れ
listen_addresses = '*'
archive_mode = on
archive_command = 'cp %p /var/lib/pgsql/9.4/ARCHIVE/%f'
# synchronous_standby_names = 'slave1' # 蠍磯逢朱 覲旧 蟆曙

archive 襦蠏 襴
mkdir /var/lib/pgsql/9.4/ARCHIVE

蟠 覲蟆
chown -R postgres.postgres /var/lib/pgsql


postgresql restart
su - postgres
cd /usr/pgsql-9.4/bin

./pg_ctl -D /var/lib/pgsql/9.4/data stop -m fast
./pg_ctl start -l /var/lib/pgsql/9.4/data/pg_log/postgres.log -D /var/lib/pgsql/9.4/data

or

systemctl restart postgresql-9.4
systemctl stop postgresql-9.4

6 slave れ #

master 覲旧
cd /
systemctl stop postgresql-9.4
mv /var/lib/pgsql/9.4/data /var/lib/pgsql/9.4/data_old

su - postgres
pg_basebackup -h 192.168.56.102 -p 5432 -U postgres -D /var/lib/pgsql/9.4/data --xlog --checkpoint=fast --progress
ls /var/lib/pgsql/9.4/data
exit

postgesql.conf

cd /var/lib/pgsql/9.4/data/
vi postgresql.conf

wal_level = minimal
hot_standby = on
#archive_mode = on
#archive_command = 'cp %p /var/lib/pgsql/9.4/ARCHIVE/%f'

recovery.conf
cd /var/lib/pgsql/9.4/data/
vi recovery.conf

restore_command = 'cp /var/lib/pgsql/9.4/ARCHIVE/%f %p'
archive_cleanup_command = 'pg_archivecleanup /var/lib/pgsql/9.4/ARCHIVE/ %r'
recovery_target_timeline = 'latest'
standby_mode = on
primary_conninfo = 'host=192.168.56.102 port=5432'
#application_name=slave1' # 蠍磯逢朱 覲旧 蟆曙

蟠 覲蟆
chown -R postgres.postgres /var/lib/pgsql

postgresql restart
systemctl restart postgresql-9.4

7 蠍壱 #

master 覯..
su - postgres
psql -x -c "create table replication_test(id int)"
psql -x -c "insert into replication_test(id) values(1)"
psql -x -c "select * from replication_test"

slave 覯..
su - postgres
psql -x -c "select * from replication_test"

master 覯..
su - postgres
psql -x -c "Select * From pg_stat_replication"


8 pgpool-II れ #


9 #


蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:52

襭 炎概螻 語 炎概 伎 覓企 谿企 譟伎讌 .