linux ---pgbouncer的安装和配置

pgbouncer是一款轻量级针对postgresql的数据库连接工具,可以对客户端的连接做限制,防止恶意连接,另外也可以减少数据库的实际连接数,从而减少数据库的开销。 

环境:

centos 6.5

postgresql-9.3.4

pgbouncer-1.5.3

libevent-1.4.13

pgbouncer的安装:源码安装:http://my.oschina.net/Kenyon/blog/73935
1.tar -xjvf pgbouncer-1.5.3.tar.gz
2. cd pgbouncer-1.5.3
3. ./configure --prefix=/usr/local/pgbouncer(会有错误提示,依赖于libevent和libevent_devel)
4. yum install libevent 和yum install libevent_devel
5.再执行./configure
6. make & make install (安装完毕,剩下的就是配置):查看pgbouncer是否安装成功,可以通过查看config.log中最后的返回值exit来确认,0是成功1是失败.
7. 新建三个文件:
在/var/log/下,新建一个目录pgbouncer,设为postgres所有.设为postgres用户可读可写可执行
在/var/run/下,新建一个目录pgbouncer,设为postgres所有,设为postgres用户可读可写可执行
在/etc/下,新建一个目录pgbouncer,设为postgres用户所有,通过chown,设为postgres用户可读可写可执行
将/usr/local/pgbouncer-1.5.3/etc/pgbouncer.ini的配置文件copy到/etc/pgbouncer下,
修改pgbouncer.ini文件:
shilin_test = host=127.0.0.1 port=5432 user=postgres password=123456 client_encoding=UTF8 datestyle=ISO connect_query='SELECT 1'
pgbouncer默认端口6432,listen_addr设为*
logfile默认/var/log/pgbouncer/pgbouncer.log
pidfile默认/var/run/pgbouncer/pgbouncer.pid
max_client_conn = 300 最大连接数设为多一点
admin_users = admin
在/etc/pgbouncer下新建一个userlist.txt,用于管理pgbouncer的用户与登录
"dev" "dev@1234"
"admin" "admin@1234"
8. 启动pgbouncer:pgbouncer -d /etc/pgbouncer/pgbouncer.ini

安装过程注意的问题:
1.防火墙问题,把6432端口放开
2.新建几个文件夹,一定要在设为postgres用户所有,可执行可读权限
3. tail -f /var/log/pgbouncer/pgbouncer.log可以看pgbouncer的运行日志

原文地址:https://www.cnblogs.com/shilin000/p/5231706.html