1、9999Pgpool信息SlavePg2192.168.18.2121Vip(虚拟IP)192.168.18.215对外提供服务二 配置主机信任关系在pg1机器上都生成ssh密钥和公钥如下:ssh-keygen -t rsacat /.ssh/id_rsa.pub /.ssh/authorized_keys.pg1chmod 600 /.ssh/authorized_keys.pg1在pg2机器上都生成ssh密钥和公钥如下: /.ssh/authorized_keys.pg2chmod 600 /.ssh/authorized_keys.pg2把pg1的公钥cp到pg2上,并且改名:scp .
2、ssh/authorized_keys.pg1 pg2:/home/postgres/.ssh/authorized_keys把pg2的公钥cp到pg1上,并且改名:scp .ssh/authorized_keys.pg2 pg1:把pg1的公钥写入到自己主机的authorized_keys文件中,自己主机信任自己:cat .ssh/authorized_keys.pg1 .ssh/authorized_keys把pg2的公钥写入到自己主机的authorized_keys文件中,自己主机信任自己:cat .ssh/authorized_keys.pg2 验证信任关系配置是否成功,注意远程和本机
3、都要以远程方式验证,如果不需要密码,说明配置成功。#pg1主机ssh postgrespg2 uptimessh postgrespg1 uptime #第一次需要密码#pg2主机ssh postgrespg2 uptime #第一次需要密码ssh postgrespg1 uptime三 安装pgpool 3.1、安装pgpoolmkdir /usr/local/pgpool (root)chown postgres:postgres /usr/local/pgpool (root)cd /soft/pgpool-II-3.7.13./configure -prefix=/usr/local/
4、pgpool -with-pgsql=/usr/local/pg12.2/makemake install 3.2、安装pgpool相关函数,可选,建议安装cd /soft/pgpool-II-3.7.13/src/sqlcd sqlpsql -f insert_lock.sql 3.3、配置postgres用户环境变量(pg1,pg2)vi .bash_profileexport PGPOOL_HOME=/usr/local/pgpoolexport PATH=$PATH:$PGPOOL_HOME/bin四、配置pgpool 4.1、配置pg1主机上的pool_hba.conf pool_h
5、ba.conf是对登录用户进行验证的,要和pg1的pg_hba.conf保持一致。cd /usr/local/pgpool/etc/cp pool_hba.conf.sample pool_hba.confvi pool_hba.conf 添加如下内容host replication repl pg2 trusthost replication repl 192.168.18.0/24 trusthost all all 192.168.18.0/24 trust 4.2、配置pg2主机上的pool_hba.conf,添加如下内容:host replication repl pg1 trust
6、 4.3、配置pcp.conf(pg1,pg2)pcp.conf配置用于pgpool自己登陆管理使用的,一些操作pgpool的工具会要求提供密码等,比如节点的添加和删除等,配置如下:cd /usr/local/pgpool/etccp pcp.conf.sample pcp.conf# 使用pg_md5生成配置的用户名密码pg_md5 postgrese8a48653851e28c69d0506508fb27fc5#编辑pcp.conf文件,文件里面有样本内容postgres: 4.4、在pgpool中添加pg数据库的用户名和密码(pg1,pg2):#需要先创建一个pgpool.conf,否则
7、在产生pool_passwd文件时会报错: cp pgpool.conf.sample-master-slave pgpool.confpg_md5 -p -m -u postgres pool_passwd#输入数据库登录用户postgres密码,生成pool_passwd文件 4.5、配置pgpool.conf配置该文件是最核心的内容,HA是否能够正常运行,跟此文件的配置息息相关。该配置文件分为不同模块,所以我们配置的时候要根据不同模块进行分类,否则配置的时候容易出错。我们可以根据前面4.4步骤产生的配置文件进行编辑。 4.5.1、主机pg1 pgpool.conf配置,由于参数繁多,只列
8、出需要修改或者关注的内容,有些值是默认的:#-# CONNECTIONS# - pgpool Connection Settings -listen_addresses = *port = 9999# - pgpool Communication Manager Connection Settings -pcp_listen_addresses = pcp_port = 9898# - Backend Connection Settings 此配置非常重要,不容易理解backend_hostname0 = pg1 #以后bankend0就代表了pg1在集群中的表述 backend_port0
9、= 1922 #连接pg数据库的端口 backend_weight0 = 1 backend_data_directory0 = /usr/local/pg12.2/data #pg数据库路径 backend_flag0 = ALLOW_TO_FAILOVERbackend_hostname1 = pg2 #bankend1代表pg2backend_port1 = 1922backend_weight1 = 1backend_data_directory1 = backend_flag1 = # - Authentication -enable_pool_hba = onpool_passwd
10、 = pool_passwd #此处的poo_passwd就是上面产生的文件# FILE LOCATIONSpid_file_name = /usr/local/pgpool/pgpool.pid# LOAD BALANCING MODE 启用负载均衡load_balance_mode = on# MASTER/SLAVE MODEmaster_slave_mode = onmaster_slave_sub_mode = stream# - Streaming 流复制检查sr_check_period = 10sr_check_user = repl #postgres replication
11、用户的名字sr_check_period = 0sr_check_password = oracle #postgres replication用户的密码sr_check_database = postgres# HEALTH CHECK GLOBAL PARAMETERS 各个节点之间健康检查health_check_period = 10 #默认为0,则不检查health_check_timeout = 20health_check_user = #pg数据库用户的名字,要求要有supper权限health_check_password = health_check_database =
12、# FAILOVER AND FAILBACKfailover_command = /usr/local/pgpool/failover_stream.sh %H #切换脚本,后面需要编辑# WATCHDOG# - Enabling -use_watchdog = on# - Watchdog communication Settings - 看门狗设置wd_hostname = wd_port = 9000 #看门狗进行通信的端口# - Virtual IP control Setting 虚拟ip配置,非常重要,否则无法启动虚拟ipdelegate_IP = 192.168.18.215
13、#虚拟ipif_cmd_path = /sbinif_up_cmd = ip addr add $_IP_$/24 dev eth4 label eth4:0 #注意选择公网ip的网口if_down_cmd = ip addr del $_IP_$/24 dev eth4 #以后需要把ip命令加上setuid的权限arping_path = /usr/sbinarping_cmd = arping -U $_IP_$ -w 1 -I eth4# - Lifecheck Setting wd_monitoring_interfaces_list = eth4# - heartbeat mode
14、心跳线设置,与备机的通信wd_heartbeat_port = 9694wd_heartbeat_keepalive = 2wd_heartbeat_deadtime = 30heartbeat_destination0 = #备机的名字heartbeat_destination_port0 = 9694 #进行测试存活状态的端口heartbeat_device0 = eth1 #pg2网络心跳的网口,一般选择专门的网口# - Other pgpool Connection Settings 与pg2连接的配置other_pgpool_hostname0 = other_pgpool_port0 = 9999other_wd_port0 = 9000 4.5.2、备机pg2 pgpool.conf配置,可以把主机的配置复制到备机,然后做少量的修改。 #主机的名字heartbeat_destination_port0
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1