pgpool-ii的安装与使用

下载地址:http://pgpool.net/mediawiki/index.php/Downloads
环境:
两台redhat linux 6.5 两台机器上均安装好pg(本机postgresql9.4.4)
ip:data1 192.168.11.66 (主) pgpool安装在此机器上
data2 192.168.11.68 (备)
1、源码安装
[root@localhost ~]# tar xvf pgpool-II-3.3.3.tar.gz
[root@localhost ~]#mkdir /opt/pgpool
[root@localhost ~]#chown -R postgres:postgres /opt/*
[postgres@localhost~]$ cd /opt/pgpool-II-3.3.3
[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 /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 /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 /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
[postgres@localhost etc]$ cp pgpool.conf.sample pgpool.conf
[postgres@localhost etc]$ cp pcp.conf.sample pcp.conf
[postgres@localhost etc]$ 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.11.66'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = '/opt/pgsql/data'
backend_flag0 = 'ALLOW_TO_FAILOVER'
backend_hostname1 = '192.168.11.68'
backend_port1 = 5432
backend_weight1 = 1
backend_data_directory1 = '/opt/pgsql/data'
backend_flag1 = 'ALLOW_TO_FAILOVER'
一般使用hba的方式进行登录认证。所以要在pgpool.conf中打开如下选项:
enable_pool_nba=on
通常会把访问pgpool的用户名和密码的MD5值记录在/opt/pgpool/etc/pool_passwd中
[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、复制和负载均衡的示例
在pgpool.conf中配置以下内容:
replication_mode = true
load_balance_mode = true

backend_hostname0 = '192.168.11.66'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = '/opt/pgsql/data'
backend_flag0 = 'ALLOW_TO_FAILOVER'
backend_hostname1 = '192.168.11.68'
backend_port1 = 5432
backend_weight1 = 1
backend_data_directory1 = '/opt/pgsql/data'
backend_flag1 = 'ALLOW_TO_FAILOVER'

启动pgpool
pgpool -f /opt/pgpool/etc/pgpool.conf

在data1上连接pgpool的端口9999,然后创建一张表。并插入数据
[postgres@localhost etc]$ psql -h 192.168.11.66 -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)



  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
pgpool-ii的配置可以通过源码安装或者使用yum安装来完成。如果选择源码安装,可以按照以下步骤进行配置: 1. 解压源码包:使用命令`tar -xvf pgpool-II-4.2.2.tar.gz`解压源码包。 2. 进入解压后的目录:使用命令`cd pgpool-II-4.2.2`进入解压后的目录。 3. 配置安装路径:使用命令`./configure --prefix=/usr/package/pgpool-II-4.2.2`配置安装路径。 4. 编译和安装使用命令`make && make install`进行编译和安装。 如果选择使用yum安装,可以按照以下步骤进行配置: 1. 安装yum源:使用命令`yum install -y https://www.pgpool.net/yum/rpms/4.2/redhat/rhel-7-x86_64/pgpool-II-release-4.2-1.noarch.rpm`安装pgpool的yum源。 2. 安装pgpool使用命令`yum install -y pgpool-II-pg11-devel.x86_64`安装pgpool。 3. 启用pgpool服务:使用命令`systemctl enable pgpool.service`启用pgpool服务。 无论是源码安装还是yum安装,配置文件都可以在`/usr/package/pgpool-II-4.2.2/etc`目录下找到。可以将`pgpool.conf.sample-stream`复制为`pgpool.conf`进行配置。 需要注意的是,从Pgpool-II 4.2版本开始,所有的配置都将通过`/etc/pgpool/`目录下的`pgpool_node_id`文件来区分节点。 另外,如果需要进行postgresql的配置流同步,可以先安装postgresql,然后根据具体需求进行配置。 希望以上信息对您有所帮助。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* *2* *3* [pgpool-II安装及配置读写分离的高可用pg集群](https://blog.csdn.net/qq_35997793/article/details/114028254)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值