postgres高可用学习篇二:通过pgbouncer连接池工具来管理postgres连接

安装pgbouncer

 yum -y install pgbouncer 

node1:编辑pgbouncer.ini配置文件

cat /etc/pgbouncer/pgbouncer.ini 
[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgres 

[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = 192.168.216.130
listen_port = 6432
unix_socket_dir = /var/run/postgresql
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
admin_users = postgres
ignore_startup_parameters = extra_float_digits,geqo
 
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 10000
default_pool_size = 10
reserve_pool_size = 1
reserve_pool_timeout = 1
max_db_connections = 1000
pkt_buf = 8192


# Documentation https://pgbouncer.github.io/config.html

配置postgres管理账户和密码

cat /etc/pgbouncer/userlist.txt
"postgres" "postgres-pass"

node2:编辑pgbouncer.ini配置文件

cat /etc/pgbouncer/pgbouncer.ini 
[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgres 

[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = 192.168.216.132
listen_port = 6432
unix_socket_dir = /var/run/postgresql
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
admin_users = postgres
ignore_startup_parameters = extra_float_digits,geqo
 
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 10000
default_pool_size = 10
reserve_pool_size = 1
reserve_pool_timeout = 1
max_db_connections = 1000
pkt_buf = 8192


# Documentation https://pgbouncer.github.io/config.html

配置postgres管理账户和密码

cat /etc/pgbouncer/userlist.txt
"postgres" "postgres-pass"

node3:编辑pgbouncer.ini配置文件

cat /etc/pgbouncer/pgbouncer.ini 
[databases]
postgres = host=127.0.0.1 port=5432 dbname=postgres 

[pgbouncer]
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
listen_addr = 192.168.216.134
listen_port = 6432
unix_socket_dir = /var/run/postgresql
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
admin_users = postgres
ignore_startup_parameters = extra_float_digits,geqo
 
pool_mode = session
server_reset_query = DISCARD ALL
max_client_conn = 10000
default_pool_size = 10
reserve_pool_size = 1
reserve_pool_timeout = 1
max_db_connections = 1000
pkt_buf = 8192


# Documentation https://pgbouncer.github.io/config.html

配置postgres管理账户和密码

cat /etc/pgbouncer/userlist.txt
"postgres" "postgres-pass"

创建/etc/systemd/system/pgbouncer.service文件,通过systemctl管理pgbouncer服务

cat /etc/systemd/system/pgbouncer.service
[Unit]
Description=pgBouncer connection pooling for PostgreSQL
After=syslog.target network.target

[Service]
Type=forking

User=postgres
Group=postgres

PermissionsStartOnly=true
ExecStartPre=-/bin/mkdir -p /var/run/pgbouncer /var/log/pgbouncer
ExecStartPre=/bin/chown -R postgres:postgres /var/run/pgbouncer /var/log/pgbouncer
ExecStart=/usr/bin/pgbouncer -d /etc/pgbouncer/pgbouncer.ini
ExecReload=/bin/kill -SIGHUP $MAINPID
PIDFile=/var/run/pgbouncer/pgbouncer.pid

LimitNOFILE=100000

[Install]
WantedBy=multi-user.target

  

 

转载于:https://www.cnblogs.com/caidingyu/p/11567033.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值