pgpool安装使用
生活随笔
收集整理的這篇文章主要介紹了
pgpool安装使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下載地址:http://pgpool.net/mediawiki/index.php/Downloads
環境:
兩臺redhat linux 6.5 兩臺機器上均安裝好pg(本機postgresql9.4.4)
ip:
data1 192.168.1.10 (主) pgpool安裝在此機器上
data2 192.168.1.11 (備)
1、源碼安裝
[root@localhost ~]# tar xvf pgpool-II-3.3.3.tar.gz
[root@localhost ~]# mkdir /opt/pgpool
[root@localhost ~]# chown -R postgres:postgres /opt/*
[root@localhost ~]# su - postgres
[postgres@localhost~]$ cd /tmp/pgpool-II-3.3.3
[postgres@localhost pgpool-II-3.3.3]$ ./configure --prefix=/opt/pgpool
[postgres@localhost pgpool-II-3.3.3]# configure: error: libpq is not installed or libpq is old
缺少軟件包,掛載鏡像,配置yum源
[postgres@localhost pgpool-II-3.3.3]# yum install postgresql* -y
[postgres@localhost pgpool-II-3.3.3]$ ./configure --prefix=/opt/pgpool
[postgres@localhost pgpool-II-3.3.3]$ make
[postgres@localhost pgpool-II-3.3.3]$ make install2、安裝pgpool_regclass 和pgpool-recovery
[postgres@localhost pgpool-II-3.3.3]$ cd /tmp/pgpool-II-3.3.3/sql/pgpool-regclass
[postgres@localhost pgpool_regclass]$ make && make install
[postgres@localhost pgpool_regclass]$ psql -f pgpool-regclass.sql template1
[postgres@localhost pgpool_regclass]$ cd /tmp/pgpool-II-3.3.3/sql/pgpool-recovery
[postgres@localhost pgpool-recovery]$ make && make install
[postgres@localhost pgpool-recovery]$ psql -f pgpool-recovery.sql template1
3、建立inert_lock表
[postgres@localhost pgpool-recovery]$ cd /tmp/pgpool-II-3.3.3/sql/
[postgres@localhost sql]$ psql -f insert_lock.sql template1
4、配置即使用
查看配置文件
[postgres@localhost pgpool-II-3.3.3]$ cd /opt/pgpool/etc/
[postgres@localhost etc]$ ll
total 180
-rw-r--r--. 1 postgres postgres 858 Dec 19 13:28 pcp.conf.sample
-rw-r--r--. 1 postgres postgres 30979 Dec 19 13:28 pgpool.conf.sample
-rw-r--r--. 1 postgres postgres 30669 Dec 19 13:28 pgpool.conf.sample-master-slave
-rw-r--r--. 1 postgres postgres 30651 Dec 19 13:28 pgpool.conf.sample-replication
-rw-r--r--. 1 postgres postgres 30690 Dec 19 13:28 pgpool.conf.sample-stream
-rw-r--r--. 1 postgres postgres 3200 Dec 19 13:28 pool_hba.conf.sample
-rw-rw-r--. 1 postgres postgres 43 Dec 19 13:53 pool_passwd
切換到root用戶下z
[root@localhost etc]chown postgres:postgres -R /opt/
[root@localhost etc]su - postgres
[postgres@localhost ]cd /opt/pgpool/etc/
[postgres@localhost etc]$ cp pgpool.conf.sample pgpool.conf
[postgres@localhost etc]$ cp pcp.conf.sample pcp.conf
[postgres@localhost etc]$ cp pool_hba.conf.sample pool_hba.conf
pg_pool默認只接受端口的本地連接。如果想從其他主機接受連接,請設置listen_address='*' ,相對應在pgpool.conf中配置修改如下:
listen_address='*'
port =9999
因為不是安裝在默認的“/usr/local/”目錄下的,所以要指定目錄的配置項,
pid_file_name ='/opt/pgpool/run/pgpool.pid'
創建相對應目錄的命令
[postgres@localhost etc]$mkdir /opt/pgpool/run
配置后端數據庫,pgpool.conf
# - Backend Connection Settings - 這一部分用來配置后臺連接的數據庫
backend_hostname0 = '192.168.1.10'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = '/opt/pgsql-9.4.4/data'
backend_flag0 = 'ALLOW_TO_FAILOVER'
backend_hostname1 = '192.168.1.11'
backend_port1 = 5432
backend_weight1 = 1
backend_data_directory1 = '/opt/pgsql-9.4.4/data'
backend_flag1 = 'ALLOW_TO_FAILOVER'
一般使用hba的方式進行登錄認證。所以要在pgpool.conf中打開如下選項:
enable_pool_nba=on
通常會把訪問pgpool的用戶名和密碼的MD5值記錄在/opt/pgpool/etc/pool_passwd中
修改.bash_profile文件, PATH=/opt/pgsql-9.4.4/bin:$PATH:/opt/pgpool/bin
[postgres@localhost etc]$ pg_md5 -m -p -u postgres pool_passwd
passwd:
這樣就生成了pool_passwd文件,使用cat查看文件內容:
postgres:md5279d84d3239474da07235e5a6555c73b
啟動pgpool
[postgres@localhost etc]$ pgpool
如果想讓pgpool在前臺運行,可以加“-n”參數
[postgres@localhost etc]$ pgpool -n
如果想讓日志打印到一個文件。使用一下命令
[postgres@localhost etc]$ pgpool -n> /tmp/pgpool.log 2>&1 &
如果想打印調度信息,加上參數“-d”
[postgres@localhost etc]$ pgpool -n -d > /tmp/pgpool.log 2>&1 &
停止pgpool
[postgres@localhost etc]$ pgpool stop
也可以加上參數
[postgres@localhost etc]$ pgpool -m fast stop5、復制和負載均衡的示例
192.168.1.10 為安裝pgpool的服務器
192.168.1.11 為后端數據節點在pgpool.conf中配置以下內容:
replication_mode = true
load_balance_mode = true backend_hostname0 = '192.168.1.10'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = '/opt/pgsql-9.4.4/data'
backend_flag0 = 'ALLOW_TO_FAILOVER'
backend_hostname1 = '192.168.1.11'
backend_port1 = 5432
backend_weight1 = 1
backend_data_directory1 = '/opt/pgsql-9.4.4/data'
backend_flag1 = 'ALLOW_TO_FAILOVER'啟動pgpool
pgpool -n -d > /tmp/pgpool.log 2>&1 &
在data1上連接pgpool的端口9999,然后創建一張表。并插入數據
[postgres@localhost etc]$ psql -h 192.168.1.10 -d postgres -p 9999 -U postgres
psql (9.4.4)
Type "help" for help. postgres=# \d
List of relations
Schema | Name | Type | Owner
----------------+------+------+--------
oracle_catalog | dual | view | postgres
(1 row) postgres=# create table aaa (a int);
CREATE TABLE
highgo=# \d
List of relations
Schema | Name | Type | Owner
----------------+------+-------+--------
oracle_catalog | dual | view | postgres
public | aaa | table | postgres
(2 rows) postgres=# insert into aaa values (1);
INSERT 0 1
postgres=# insert into aaa values (2);
INSERT 0 1
postgres=# insert into aaa values (3);
INSERT 0 1
postgres=# select * from aaa ;
a
---
1
2
3
(3 rows)
在data2上可以看到,表和數據都弄好了,而且數據完全一樣
[postgres@localhost data]$ psql
Password:
psql (9.4.4)
Type "help" for help. postgres=# \d
List of relations
Schema | Name | Type | Owner
----------------+------+-------+--------
oracle_catalog | dual | view | postgres
public | aaa | table | postgres
(2 rows) postgres=# select * from aaa ;
a
---
1
2
3
(3 rows)
總結
以上是生活随笔為你收集整理的pgpool安装使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 设计师谈配色 配色方案 WEB
- 下一篇: 录ppt的时候录光标_ppt录制旁白后怎