postgresql从入门到精通 - 第35讲:中间件PgBouncer部署|PostgreSQL教程
# 安装PgBouncer
sudo apt-update
sudo apt-get install pgbouncer
# 创建PgBouncer配置文件目录
mkdir -p /etc/pgbouncer
# 创建PgBouncer用户密码文件
echo "pgbouncer" | sudo passwd --stdin pgbouncer
chown pgbouncer:pgbouncer /etc/pgbouncer
# 创建PgBouncer配置文件
cat << EOF > /etc/pgbouncer/pgbouncer.ini
[databases]
mydb = host=localhost port=5432 dbname=mydb
[pgbouncer]
listen_port = 6432
listen_addr = localhost
auth_type = md5
auth_file = /etc/pgbouncer/userlist.txt
logfile = /var/log/pgbouncer/pgbouncer.log
pidfile = /var/run/pgbouncer/pgbouncer.pid
admin_users = pgbouncer
[users]
EOF
# 创建PgBouncer用户列表文件
echo "pgbouncer pgbouncer" > /etc/pgbouncer/userlist.txt
chown pgbouncer:pgbouncer /etc/pgbouncer/userlist.txt
# 创建日志和PID目录
sudo mkdir -p /var/log/pgbouncer
sudo mkdir -p /var/run/pgbouncer
sudo chown pgbouncer:pgbouncer /var/log/pgbouncer
sudo chown pgbouncer:pgbouncer /var/run/pgbouncer
# 启动PgBouncer
sudo su - pgbouncer -c "pgbouncer -d /etc/pgbouncer/pgbouncer.ini"
这段代码展示了如何在基于Debian的系统上安装和配置PgBouncer。它首先通过apt-get更新包索引并安装PgBouncer,然后创建必要的配置文件目录并设置权限。接着,它创建了PgBouncer的配置文件/etc/pgbouncer/pgbouncer.ini
,并定义了数据库别名、监听地址和端口、认证类型以及用户列表文件。最后,它创建日志和PID文件所需的目录并设置相应权限,然后以pgbouncer用户身份启动PgBouncer。
评论已关闭