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 install
  
2、安装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 stop
  
5、复制和负载均衡的示例  
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)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值