日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

pgpool mysql_postgresql 9.5 pgpool 主从复制 以及错误解决

發布時間:2023/12/31 数据库 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pgpool mysql_postgresql 9.5 pgpool 主从复制 以及错误解决 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

PostgreSQL+pgpool-II復制方案

這里不做功能的描述,只寫搭建的過程和遇到的一些問題

1 系統

[root@mysqlhq ~]# cat /etc/redhat-release

KylinLinux release 3.3.1707 (Core)

2 安裝pg 復制

3 安裝pgpool

使用yum安裝,網上大多是源碼tar的安裝,

下載rpm包

-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的集群環境,沒有驗證主從切換的情況(切換腳本待驗證)

總結

以上是生活随笔為你收集整理的pgpool mysql_postgresql 9.5 pgpool 主从复制 以及错误解决的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。