Postgresql Master/Slaver

來源:互聯網
上載者:User

標籤:

1.Install PostgreSql9.3

a:yum install

copy repository to: /etc/yum/yum.repos.d

yum -y install postgresql93-server postgresql93-contrib --skip-broken

yum install http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-redhat95-9.5-2.noarch.rpm

sudo yum install postgresql95-server postgresql95-contrib

2.Install postgres

yum  -y install postgresql93-server postgresql93-contrib
3.Master 配置
1.建立PG Data Dir
mkdir –p  /opt/PostgreSQL/datamkdir –p  /opt/PostgreSQL/data/archivechmod 700 /opt/PostgreSQL/datasudo chown postgres:postgres /opt/PostgreSQL/data

2.設定profile

sudo vi /etc/profileexport PATH=/usr/pgsql-9.3/bin:$PATHexport PGDATA=/opt/PostgreSQL/data/su – postgresvi ~/.bash_profileexport PATH=/usr/pgsql-9.3/bin:$PATHexport PGDATA=/opt/PostgreSQL/data/

 

3.InitDB For master

su  -postgresinitdb --encoding=UTF-8  --username=postgres --pwprompt --pgdata=/opt/PostgreSQL/data/

4.設定檔

vi  $PGDATA_HOME/pg_hba.conf
(replace "ident" with "md5")(#IPv4 local connections)host    all         all         192.168.1.1/16        md5(replace ident or peer with trust)(#"local" is for Unix domain socket connections only)local   all             all                                     trust# Allow replication connections from localhost, by a user with the# replication privilege.#local   replication     postgres                                peer#host    replication     postgres        127.0.0.1/32            identhost    replication     postgres         192.168.1.1/16          trust

vi $PGDATA_HOME/postgresql.conf

listen_addresses = ‘*‘
port = 5432

wal_level = hot_standby

max_wal_senders = 5

wal_keep_segments = 32

archive_mode = on

archive_command = ‘cp %p /opt/PostgreSQL/data/%f < /dev/null‘

checkpoint_segments = 8

5.啟動Master DB

su  -postgrespg_ctl -D /opt/PostgreSQL/data/ -l logfile start
pg_ctl –D /var/lib/pgsql/9.3/data -l logfile start psql -c "CREATE USER postgres REPLICATION LOGIN ENCRYPTED PASSWORD ‘conversant‘;"

$psql
postgres=# alter user postgres with password ‘conversant‘;

4.Slave
4.1 Install Postgres
4.2 Configure Profile
4.3 Copy master data
su –postgrespg_basebackup -h 192.168.1.12 -D /opt/PostgreSQL/data -U replicator -P -v -x

4.4 配置

vi $PGDATA_HOME/postgresql.conf

listen_addresses = ‘*‘hot_standby = onwal_level = hot_standbymax_wal_senders = 3wal_keep_segments = 8checkpoint_segments = 8

vi $PGDATA_HOME/recovery.conf

sudo su -cp /usr/pgsql-9.3/share/recovery.conf.sample  /opt/PostgreSQL/data/chown postgres:postgres  recovery.conf.sample  mv recovery.conf.sample   recovery.conf
vi recovery.confprimary_conninfo = ‘host=192.168.1.12 port=5432 user=replicator password=conversant‘trigger_file = ‘/opt/PostgresSql/data/trigger‘standby_mode = ‘on‘

 

5.開啟防火牆 5432連接埠

 



$sudo /sbin/iptables -I INPUT -p tcp --dport 5432 –j ACCEPT
$sudo /etc/rc.d/init.d/iptables save
$sudo /etc/init.d/iptables status

 

6.啟動Slave

su  -postgrespg_ctl -D /opt/PostgreSQL/data/ -l logfile start
 
1. startpg_ctl -D /opt/PostgreSQL/data/ -l /opt/PostgreSQL/data/logfile start2. stoppg_ctl -D /opt/PostgreSQL/data/ -l /opt/PostgreSQL/data/logfile --mode=fast stop3. restartpg_ctl -D /opt/PostgreSQL/data/ -l /opt/PostgreSQL/data/logfile restart

 

7.問題列表:

1.error check sum:

Fix error: yum primary.sqlite.bz2: [Errno -3] Error performing checksum Trying other mirror.

enabled=0

2.GPG key retrieval failed: [Errno 5] OSError

[Errno 2] No such file or directory: ‘/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG-93‘

gpgcheck=0

Postgresql Master/Slaver

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.