Linux编译安装PgBouncer


一、安装依赖项libevent

方法一. 直接编译安装

wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
mkdir /usr/local/libevent
./configure --prefix=/usr/local/libevent
make -j 4
make install
echo "export PKG_CONFIG_PATH=/usr/local/libevent/lib/pkgconfig:\$PKG_CONFIG_PATH" >> /etc/profile
source /etc/profile

方法二. 通过vcpkg安装

安装cmake

wget https://github.com/Kitware/CMake/releases/download/v3.24.2/cmake-3.24.2.tar.gz
cd cmake-3.24.2
#./bootstrap
./bootstrap --system-curl
make -j 4
make install

安装最新git

wget https://github.com/git/git/archive/refs/tags/v2.37.3.tar.gz
make configure
./configure --prefix=/usr/local
make -j 4
make install

安装vcpkg

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
yum install curl zip unzip tar -y
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install libevent

二、安装PgBouncer

从PgBouncer官网下载最新版本的PgBouncer源码包,并使用tar命令解压:

wget https://www.pgbouncer.org/downloads/files/1.17.0/pgbouncer-1.17.0.tar.gz

进入解压后的目录,运行以下命令进行编译和安装:

mkdir /usr/local/pgbouncer 
./configure --prefix=/usr/local/pgbouncer 
make -j 4
make install

在生成的文件/usr/local/pgbouncer/share/doc/pgbouncer中,包含启动所需的关键文件

pgbouncer.ini
userlist.txt
pgbouncer.service

编辑配置文件 pgbouncer.ini

[databases]  
mydb = host=localhost port=5432 dbname=mydb  
  
[pgbouncer]  
logfile = /var/log/pgbouncer/pgbouncer.log  
pidfile = /var/run/pgbouncer/pgbouncer.pid  
listen_addr = *  
listen_port = 6432  
auth_type = md5  
auth_file = /etc/pgbouncer/userlist.txt  
admin_users = postgres  
pool_mode = transaction  
max_client_conn = 1000  
default_pool_size = 20  
reserve_pool_size = 5

创建用户认证文件

echo "username 'md5hashedpassword' dbname" > /etc/pgbouncer/userlist.txt  

sudo chown postgres. /etc/pgbouncer/userlist.txt  

sudo chmod 600 /etc/pgbouncer/userlist.txt

启动PgBouncer

sudo systemctl start pgbouncer  
sudo systemctl enable pgbouncer

在使用过程中,如果遇到报错"FATAL: unsupported startup parameter: extra float digits"时,将以下配置添加到pgbouncer.ini

ignore_startup_parameters = extra_float_digits

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值