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


    安装pgbouncer

    yum install libevent -y
    yum install libevent-devel -y
    wget http://www.pgbouncer.org/downloads/files/1.11.0/pgbouncer-1.11.0.tar.gz
    tar -xvf pgbouncer-1.11.0.tar.gz
    ./configure --prefix=/usr/local --with-libevent=libevent-prefix
    make
    make install

    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
    

      

  • 相关阅读:
    python 数据结构--Set(集合)
    python 数据结构--Dictionary(字典)
    idea使用心得
    SpringBoot(一):构建第一个SpringBoot工程
    springboot服务的一些问题
    maven使用问题总结

    多线程学习三:Thread API,ThreadLocal,synchronized,volatile和Condition
    多线程学习二:线程池 ExecutorService
    多线程学习一:创建多线程的方式
  • 原文地址:https://www.cnblogs.com/caidingyu/p/11567033.html
Copyright © 2020-2023  润新知