PostgreSQL+pgpool-II复制方案

这里不做功能的描述,只写搭建的过程和遇到的一些问题

1 系统

[root@mysqlhq ~]# cat /etc/redhat-release
Kylin Linux release 3.3.1707 (Core)

2 安装pg 复制

详细见 https://www.cnblogs.com/yhq1314/p/10119556.html

3 安装pgpool

使用yum安装,网上大多是源码tar的安装,

下载rpm包

https://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/repoview/

-rw-r--r-- 1 root root 716528 12月 24 11:13 pgpool-II-95-3.5.18-1.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 1706944 12月 24 11:14 pgpool-II-95-debuginfo-3.5.18-1.rhel7.x86_64.rpm
-rw-r--r-- 1 root root 14384 12月 24 11:12 pgpool-II-95-devel-3.5.18-1.rhel7.x86_64.rpm

[root@mysql3 soft]# yum install -y pgpool-II-95-3.5.18-1.rhel7.x86_64.rpm
[root@mysql3 soft]# cd /etc/pgpool-II

添加Pgpool-II运行用户
[root@mysql3 data]# useradd pgpool
[root@mysql3 data]# passwd pgpool
Changing password for user pgpool.
New password: ##pgpool
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[root@mysql3 data]# chown -R pgpool.pgpool /etc/pgpool-II
[root@mysql3 data]# mkdir -p /var/run/pgpool/
[root@mysql3 data]# chown pgpool.pgpool /var/run/pgpool/
[root@mysql3 pgpool-II]# pwd
/etc/pgpool-II

[root@mysql3 pgpool-II]# vim pool_hba.conf
# TYPE DATABASE USER CIDR-ADDRESS METHOD

# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.19.227/32 md5
host all all ::1/128 md5

[root@mysql3 pgpool-II]# pg_md5 postgres
e8a48653851e28c69d0506508fb27fc5
[root@mysql3 pgpool-II]# vim pcp.conf
# USERID:MD5PASSWD
postgres:e8a48653851e28c69d0506508fb27fc5
[root@mysql3 pgpool-II]# chmod u+s /sbin/ifconfig && chmod u+s /usr/sbin
[root@mysql3 pgpool-II]# vim pgpool.conf
# CONNECTIONS
listen_addresses = '*'
port = 9999
pcp_listen_addresses = '*'
pcp_port = 9898

# - Backend Connection Settings -
backend_hostname0 = '192.168.19.227'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = '/var/lib/pgsql/data'
backend_flag0 = 'ALLOW_TO_FAILOVER'

backend_hostname1 = '192.168.19.145'
backend_port1 = 5432
backend_weight1 = 1
backend_data_directory1 = '/var/lib/pgsql/data'
backend_flag1 = 'ALLOW_TO_FAILOVER'

# - Authentication -
enable_pool_hba = on
pool_passwd = 'pool_passwd'

# FILE LOCATIONS
pid_file_name = '/var/run/pgpool/pgpool.pid'

# REPLICATION MODE
replication_mode = off
load_balance_mode = on
master_slave_mode = on

sr_check_period = 5
sr_check_user = 'postgres'
sr_check_password = 'postgres'
sr_check_database = 'postgres'

# HEALTH CHECK
health_check_period = 10
health_check_timeout = 20
health_check_user = 'postgres'
health_check_password = 'postgres'
health_check_database = 'postgres'

# FAILOVER AND FAILBACK
failover_command = '/etc/pgpool-II/failover_stream.sh %d %H /tmp/trigger_file0'

# WATCHDOG
use_watchdog = on

wd_hostname = '192.168.19.227' #145
# - Virtual IP control Setting -

delegate_IP = ''
if_cmd_path = '/sbin'
if_up_cmd = 'ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0'
if_down_cmd = 'ifconfig eth0:0 down'

heartbeat_destination0 = 'slave1'
heartbeat_device0 = 'eth0'

other_pgpool_hostname0 = 'slave'

[root@mysql3 pgpool-II]# vim failover_stream.sh

# Failover command for streaming replication.
# This script assumes that DB node 0 is primary, and 1 is standby.
#
# If standby goes down, do nothing. If primary goes down, create a
# trigger file so that standby takes over primary node.
#
# Arguments: $1: failed node id. $2: new master hostname. $3: path to
# trigger file.
failed_node=192.168.19.227
new_master=192.168.19.145
trigger_file=$3
# Do nothing if standby goes down.
if [ $failed_node = 1 ]; then
exit 0;
fi
# Create the trigger file.
/usr/bin/ssh -T $new_master /bin/touch $trigger_file
exit 0;

[root@mysql3 pgpool-II]# chown postgres:postgres failover_stream.sh &&chmod 777 failover_stream.sh
[root@mysql3 pgpool-II]# mkdir /var/log/pgpool
[root@mysql3 pgpool-II]# chown -R postgres.postgres /var/log/pgpool
[root@mysql3 pgpool-II]# pgpool -n -d -D > /var/log/pgpool/pgpool.log 2>&1 & #启动pgpool
[1] 29885

su - postgres

错误1 
-bash-4.2$ psql -h 192.168.19.227 -p 9999
psql: 无法联接到服务器: 拒绝连接
服务器是否在主机 "192.168.19.227" 上运行并且准备接受在端口
9999 上的 TCP/IP 联接?

#这里只有一个pgpool所以
2018-12-24 15:01:29: pid 29885: FATAL: invalid watchdog configuration. other pgpools setting is not defined

use_watchdog = off

#健康检查出错
2018-12-24 15:05:16: pid 29939: DEBUG: doing health check against database:postgres user:postgres
2018-12-24 15:05:16: pid 29939: DEBUG: Backend DB node 0 status is 3
2018-12-24 15:05:16: pid 29939: DEBUG: Backend DB node 1 status is 3
2018-12-24 15:05:16: pid 29939: DEBUG: health check: clearing alarm
2018-12-24 15:05:16: pid 29939: DEBUG: health check: clearing alarm

注释掉健康检查的几个参数

[root@mysql3 pgpool-II]# pgpool reload  #重新加载
[root@mysql3 pgpool-II]# ps -ef|grep pgpool
[root@mysql3 pgpool-II]# netstat -lnt|grep 9999

错误2 

#pg的错误日志
-bash-4.2$ tail -f -n 100 postgresql-Mon.log
STATEMENT: show user;
FATAL: no pg_hba.conf entry for host "192.168.19.227", user "postgres", database "postgres", SSL off

#master slave都更新此文件,然后reload
-bash-4.2$ vim pg_hba.conf
host all all 192.168.19.227/32 md5

#登录 master
-bash-4.2$ psql -h 192.168.19.227 -p 5432
口令:
psql (9.5.2)
输入 "help" 来获取帮助信息.

postgres=# select client_addr,sync_state from pg_stat_replication;
client_addr | sync_state
----------------+------------
192.168.19.145 | async
postgres=# \q
-bash-4.2$ psql -h 192.168.19.227 -p 5432 -U postgres
用户 postgres 的口令:
psql (9.5.2)
输入 "help" 来获取帮助信息.

错误3

-bash-4.2$ psql -h 192.168.19.227 -p 9999 -U postgres
psql: 服务器意外地关闭了联接
这种现象通常意味着服务器在处理请求之前
或者正在处理请求的时候意外中止
-bash-4.2$ psql -h 192.168.19.227 -p 9999 -U postgres -d postgres
psql: 服务器意外地关闭了联接
这种现象通常意味着服务器在处理请求之前
或者正在处理请求的时候意外中止
2018-12-24 15:38:37: pid 30728: DEBUG: reading startup packet
2018-12-24 15:38:37: pid 30728: DETAIL: Protocol Major: 1234 Minor: 5679 database: user:
2018-12-24 15:38:37: pid 30728: DEBUG: forwarding error message to frontend
2018-12-24 15:38:37: pid 30728: FATAL: pgpool is not accepting any new connections
2018-12-24 15:38:37: pid 30728: DETAIL: all backend nodes are down, pgpool requires at least one valid node
2018-12-24 15:38:37: pid 30728: HINT: repair the backend nodes and restart pgpool
2018-12-24 15:38:37: pid 29939: DEBUG: reaper handler
2018-12-24 15:38:37: pid 29939: LOG: child process with pid: 30728 exits with status 256
2018-12-24 15:38:37: pid 29939: LOG: fork a new child process with pid: 30766
2018-12-24 15:38:37: pid 29939: DEBUG: reaper handler: exiting normally
2018-12-24 15:38:37: pid 30766: DEBUG: initializing backend status

-bash-4.2$ psql -p 9999 -U postgres -d postgres
psql: ERROR: pgpool is not accepting any new connections
描述: all backend nodes are down, pgpool requires at least one valid node
提示: repair the backend nodes and restart pgpool
-bash-4.2$ psql -h 127.0.0.1 -p 9999 -U postgres -d postgres
psql: 服务器意外地关闭了联接
这种现象通常意味着服务器在处理请求之前
或者正在处理请求的时候意外中止

#这里stop 然后重启pgpool,查看到完整的启动日志,有重大发现

2018-12-24 15:51:50: pid 31010: DEBUG: loading hba configuration
2018-12-24 15:51:50: pid 31010: DETAIL: loading file :"/etc/pgpool-II/pool_hba.conf" for client authentication configuration file
2018-12-24 15:51:50: pid 31010: LOG: Backend status file /var/log/pgpool/pgpool_status discarded
2018-12-24 15:51:50: pid 31010: DEBUG: pool_coninfo_size: num_init_children (32) * max_pool (4) * MAX_NUM_BACKENDS (128) * sizeof(ConnectionInfo) (136) = 2228224 bytes requested for shared memory
2018-12-24 15:51:50: pid 31010: DEBUG: ProcessInfo: num_init_children (32) * sizeof(ProcessInfo) (32) = 1024 bytes requested for shared memory
2018-12-24 15:51:50: pid 31010: DEBUG: Request info are: sizeof(POOL_REQUEST_INFO) 5304 bytes requested for shared memory
2018-12-24 15:51:50: pid 31010: DEBUG: Recovery management area: sizeof(int) 4 bytes requested for shared memory
2018-12-24 15:51:50: pid 31010: LOG: Setting up socket for 0.0.0.0:9999
2018-12-24 15:51:50: pid 31010: LOG: Setting up socket for :::9999
2018-12-24 15:51:50: pid 31011: DEBUG: initializing backend status
2018-12-24 15:51:50: pid 31012: DEBUG: initializing backend status

2018-12-24 15:51:50: pid 31041: DEBUG: initializing backend status
2018-12-24 15:51:50: pid 31010: LOG: pgpool-II successfully started. version 3.6.2 (subaruboshi)
2018-12-24 15:51:50: pid 31010: DEBUG: find_primary_node: not in streaming replication mode
2018-12-24 15:51:50: pid 31042: DEBUG: initializing backend status
2018-12-24 15:51:50: pid 31043: DEBUG: I am PCP child with pid:31043
2018-12-24 15:51:50: pid 31016: DEBUG: initializing backend status
2018-12-24 15:51:50: pid 31044: DEBUG: I am 31044
2018-12-24 15:51:50: pid 31044: DEBUG: initializing backend status

[root@mysql3 pgpool-II]# vim pgpool.conf
master_slave_sub_mode = 'stream'
[root@mysql3 pgpool-II]# pgpool reload

错误4

-bash-4.2$ psql -U postgres -d postgres -h 192.168.19.227 -p 9999
psql: FATAL: client authentication failed
描述: no pool_hba.conf entry for host "192.168.19.227", user "postgres", database "postgres", SSL off
提示: see pgpool log for details

[root@mysql3 pgpool-II]# vim pool_hba.conf #添加一行
host all all 192.168.19.227/32 md5

错误5
-bash-4.2$ psql -U postgres -d postgres -h 192.168.19.227 -p 9999
psql: FATAL: md5 authentication failed
描述: pool_passwd file does not contain an entry for "postgres"

[root@mysql3 pgpool-II]# cat pool_passwd
[root@mysql3 pgpool-II]# pg_md5 -m -p -u postgres pool_passwd
password:
[root@mysql3 pgpool-II]# cat pool_passwd #此文件
postgres:md53175bce1d3201d16594cebf9d7eb3f9d
[root@mysql3 pgpool-II]# pgpool reload
-bash-4.2$ psql -U postgres -d postgres -h 192.168.19.227 -p 9999 #正常登录
用户 postgres 的口令:
psql (9.5.2)
postgres=# show pool_nodes;
node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay
---------+----------------+------+--------+-----------+--------+------------+-------------------+-------------------
0 | 192.168.19.227 | 5432 | up | 0.500000 | master | 0 | false | 0
1 | 192.168.19.145 | 5432 | up | 0.500000 | slave | 0 | true | 0

hq=# \c test1_user
您现在已经连接到数据库 "test1_user",用户 "postgres".
test1_user=# \dt
关联列表
架构模式 | 名称 | 类型 | 拥有者
----------+---------------+--------+------------
public | test1_user111 | 数据表 | test1_user
public | testcase | 数据表 | test1_user
(2 行记录)

test1_user=# select * from public.testcase;
id | task_class | age
----+------------+-----
(0 行记录)
test1_user=# insert into public.testcase(id,task_class,age) values(1,1,18); #插入记录
INSERT 0 1
test1_user=# select * from public.testcase;
id | task_class | age
----+------------+-----
1 | 1 | 18

#连接master库,查询刚刚数据
-bash-4.2$ psql -p 5432
psql (9.5.2)
输入 "help" 来获取帮助信息.

postgres=# \l
数据库列表
名称 | 拥有者 | 字元编码 | 校对规则 | Ctype | 存取权限
------------+------------+----------+-------------+-------------+---------------------------
exampledb | dbuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/dbuser +
| | | | | dbuser=CTc/dbuser
hq | dbuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
mydb | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
mypg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
test1_user | test1_user | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/test1_user +
| | | | | test1_user=CTc/test1_user
test2_user | test1_user | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
yhq1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(10 行记录)

postgres=# \c test1_user;
您现在已经连接到数据库 "test1_user",用户 "postgres".
test1_user=# \dt
关联列表
架构模式 | 名称 | 类型 | 拥有者
----------+---------------+--------+------------
public | test1_user111 | 数据表 | test1_user
public | testcase | 数据表 | test1_user
(2 行记录)

test1_user=# select * from public.testcase;
id | task_class | age
----+------------+-----
1 | 1 | 18
(1 行记录)

#登录slave,查询刚刚的数据
-bash-4.2$ psql -p 5432
psql (9.5.2)
Type "help" for help.

postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
------------+------------+----------+-------------+-------------+---------------------------
exampledb | dbuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/dbuser +
| | | | | dbuser=CTc/dbuser
hq | dbuser | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
mydb | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
mypg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
test1_user | test1_user | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/test1_user +
| | | | | test1_user=CTc/test1_user
test2_user | test1_user | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
yhq1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
(10 rows)

postgres=# \c test1_user
You are now connected to database "test1_user" as user "postgres".
test1_user=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------------+-------+------------
public | test1_user111 | table | test1_user
public | testcase | table | test1_user
(2 rows)

test1_user=# select * from public.testcase;
id | task_class | age
----+------------+-----
1 | 1 | 18
(1 row)

这里只搭建了pgpool的集群环境,没有验证主从切换的情况(切换脚本待验证

postgresql 9.5 pgpool 主从复制 以及错误解决的更多相关文章

  1. PHP编译安装时常见错误解决办法,php编译常见错误

    PHP编译安装时常见错误解决办法,php编译常见错误 1.configure: error: xslt-config not found. Please reinstall the libxslt & ...

  2. SQL SERVER 9003错误解决方法 只适用于SQL2000

    SQLSERVER 9003错误解决方法 只适用于SQL2000 (只适用于SQL2000) "无法打开新数据库 'POS'.CREATE DATABASE 中止. (Microsoft S ...

  3. linux下遇见mysql启动报2002错误解决办法

    前言:目前问题解决了,但是仍不知道是什么原因造成的,在出现问题前安装uWSGI后,mysql就出现这个问题的,哪位大侠说说这是怎么回事? 正文:Linux 下 Mysql error 2002 错误解 ...

  4. Ubuntu 汉化时ubuntu software database is broken错误解决

    关于Ubuntu 汉化时的错误解决:按照网上的方法没有解决 最后 删掉thunderbird mail .这个软件,顺利解决!! 错误:thunderbird-locale-en: Depends: ...

  5. 记录centos6.8安装Oracle10.2.0.1过程中的错误解决

    [root@hadoop01 database]# ./runInstaller ./runInstaller: /opt/database/install/.oui: /lib/ld-linux.s ...

  6. New XAMPP security concept:错误解决方法

    New XAMPP security concept:错误解决方法 (2014-03-06 16:07:46) 转载▼   分类: php 在Linux上配置xampp后远程访问域名报错: New X ...

  7. 真机测试-Please enter a different string错误解决

    错误原因是这个bundle ID已经被占用了,这是想到的是要重置测试证书,那么则需要去修改Bundle identifier,因为测试证书是以Bundle identifier为基准的,修改后运行,重 ...

  8. paip.python错误解决24

    paip.python错误解决 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...

  9. paip.python错误解决23

    paip.python错误解决 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...

随机推荐

  1. 谈谈你对Glide和Picasso他们的对比的优缺点

    1.Picasso和Glide的withi后面的参数不同 Picasso.with(这里只能传入上下文)     . Glide.with,后面可以传入上下文,activity实例,FragmentA ...

  2. 去除掉myeclipse2017页面右上角的图片

    图标如下所示,这是方便测试用的,但是有时候也很碍人. 在servers中进行关闭,操作如下所示: 点击图中的CodeLive就可以使图标消失,再次点击图标会再次出现.

  3. ubuntu下tar.bz2解压错误

    在执行tar -jxvf firefox-latest-x86_64.tar.bz2是出现了如下错误: 出错原因是: (1)帐号权限不足造成的 (2)原tar包损坏 (3)可能磁盘空间不足,可以用命令 ...

  4. 【Java】final关键字

    1.final数据 (1)基本类型      数值恒定不变 (2)对象引用      引用恒定不变,初始化的时候指向一个对象后,无法改变为另一个对象,但是对象本身可以修改 2.final方法 可以把方 ...

  5. Android Broadcast 和 BroadcastReceiver的权限机制

    在Android应用开发中,有时会遇到以下两种情况, 1. 一些敏感的广播并不想让第三方的应用收到 : 2. 要限制自己的Receiver接收某广播来源,避免被恶意的同样的ACTION的广播所干扰. ...

  6. 官方:MySQL 5.7 并行复制实现原理与调优 | InsideMySQL(转载)

    MySQL 5.7并行复制时代 众所周知,MySQL的复制延迟是一直被诟病的问题之一,然而在Inside君之前的两篇博客中(1,2)中都已经提到了MySQL 5.7版本已经支持“真正”的并行复制功能, ...

  7. InpOut32 InputTest.cpp hacking

    /************************************************************************************ * InpOut32 Inp ...

  8. [QT] Tab键切换焦点顺序

    在Qt Designer 中点击“编辑Tab顺序“按钮进入编辑Tab顺序模式,如下图: 之后界面会变成这样: 随处点击右键即可弹出菜单,选择  "制表符顺序列表..." 出现 剩下 ...

  9. Android sharedUserId 使用

    在Android 系统中,所有安装到系统的应用程序都必有一个数字证书,此数字证书用于标识应用程序的作者和在应用程序之间建立信任关系,.这个数字证书并不需要权威的数字证书签名机构认证,它只是用来让应用程 ...

  10. linux【基础命令】

    最近在学linux,避免一些命令忘记,所以在此记录一下: linux文件列表遍历 ls -a 列出所有的文件及文件夹 包括隐藏的ls -l 列出文件目录的详细信息 history 查看历史命令ctrl ...