麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > 綜合 > 正文

PostgreSQL+pgpool-II復(fù)制方案

2024-07-21 02:52:40
字體:
供稿:網(wǎng)友

PostgreSQL+pgpool-II復(fù)制方案

@(學(xué)習(xí))[PostgreSQL, pgpool-II, 高可用]

PostgreSQLpgpool-II復(fù)制方案Pgpool-II介紹pgpool-II安裝1 安裝pgpool-II yum源并安裝pgpool-II2 添加Pgpool-II運(yùn)行用戶3 設(shè)置pcpconf4 設(shè)置Pgpool-II配置文件5 配置backend信息6 修改認(rèn)證方式61 修改pgpool-II的認(rèn)證方式為md562 修改PostgreSQL的認(rèn)證方式為md57 測試pgpool-II同步安裝pgpoolAdmin不推薦1 解壓pgpoolAdmin至web目錄使用戶能訪問其php2 php-fpm運(yùn)行用戶和pgpool用戶統(tǒng)一3 根據(jù)向?qū)瓿砂惭b4 一些細(xì)節(jié)說明5 phpini的disable_functions設(shè)置6 pgpoolAdmin中pcp_stop_pgpool參數(shù)總結(jié)

1. Pgpool-II介紹

pgpool-II是PostgreSQL服務(wù)器之間一種有效的中間件和PostgreSQL數(shù)據(jù)庫客戶端。它提供了以下功能。

連接池 pgpool-II保存到PostgreSQL服務(wù)器的連接,當(dāng)一個相同新連接(如用戶名、數(shù)據(jù)庫、協(xié)議版本)進(jìn)來時,重用他們。它減少了連接開銷,提高了系統(tǒng)的整體吞吐量。 復(fù)制 pgpool-II可以管理多個PostgreSQL服務(wù)器。使用復(fù)制功能可以使2個或更多的物理磁盤上創(chuàng)建一個實(shí)時備份,這樣服務(wù)不會因服務(wù)器的磁盤故障而中斷。 負(fù)載平衡 如果數(shù)據(jù)庫是復(fù)制的,在任何服務(wù)器上執(zhí)行一個SELECT查詢會返回相同的結(jié)果。pgpool-II復(fù)制特性的優(yōu)勢在于減少每個PostgreSQL服務(wù)器上的負(fù)載,因為它可以使用分布在多個服務(wù)器之間進(jìn)行SELECT查詢,從而提高系統(tǒng)的整體吞吐量。最好是查詢和PostgreSQL服務(wù)器數(shù)量成一定比例,多用戶同時執(zhí)行多查詢達(dá)到負(fù)載均衡最好的效果。 限制連接數(shù) PostgreSQL的最大并發(fā)連接數(shù)有一定限制的,當(dāng)超過限制的連接數(shù)后,連接會被拒絕。然而,設(shè)置增加最大連接數(shù)又會增加資源消耗,影響系統(tǒng)性能。pgpool-II也有最大連接數(shù)限制,但超過的連接進(jìn)來時是進(jìn)行立即排隊,而不是返回一個錯誤。

pgpool-II交互PostgreSQL的后端和前端協(xié)議時,起著繼電器的作用。因此,數(shù)據(jù)庫應(yīng)用程序(前端)認(rèn)為pgpool-II是真實(shí)的PostgreSQL服務(wù)器,服務(wù)器(后端)認(rèn)為pgpool-II是它的客戶端之一。因為pgpool-II在服務(wù)器和客戶端是透明的,所以pgpool-II可以使用現(xiàn)有的數(shù)據(jù)庫應(yīng)用程序而做到幾乎不修改它們。

環(huán)境: CentOS6.8 PostgreSQL9.5 pgpool-II-pg95-3.6.1

2. pgpool-II安裝

2.1 安裝pgpool-II yum源,并安裝pgpool-II

從官網(wǎng)找到相關(guān)yum源rpm包,使用rpm安裝后,并使用yum安裝pgpool-II

rpm -ivh http://www.pgpool.net/yum/rpms/3.6/redhat/rhel-6-x86_64/pgpool-II-release-3.6-1.noarch.rpmyum -y install pgpool-II-pg95yum -y install pgpool-II-pg95-debuginfoyum -y install pgpool-II-pg95-develyum -y install pgpool-II-pg95-extensionschkconfig pgpool on # 添加開機(jī)啟動service start/stop pgpool # 服務(wù)啟/停

2.2 添加Pgpool-II運(yùn)行用戶

添加Pgpool-II運(yùn)行用戶,并給相關(guān)目錄的讀寫權(quán)限

[root@im110 pgpool-II]# useradd pgpool [root@im110 pgpool-II]# passwd pgpoolChanging passWord for user pgpool.New password: Retype new password: passwd: all authentication tokens updated successfully.[root@im110 pgpool-II]# chown -R pgpool.pgpool /etc/pgpool-II[root@im110 pgpool-II]# mkdir -p /var/run/pgpool/[root@im110 pgpool-II]# chown pgpool.pgpool /var/run/pgpool/

修改啟動腳本的pgpool運(yùn)行用戶: 圖1

2.3 設(shè)置pcp.conf

cp /etc/pcp.conf.sample /etc/pcp.conf

內(nèi)容格式為如下,一行一個,#號為注釋標(biāo)識

username:[md5 encrypted password]

[md5 encrypted password] 可以使用如下命令生成

$ pg_md5 pgpoolba777e4c2f15c11ea8ac3be7e0440aa0

使用pg_md5 -p會隱藏輸入的密碼

$ pg_md5 -ppassword: your_password

配置文件pcp.conf必須允許pgpool執(zhí)行用戶可讀。

2.4 設(shè)置Pgpool-II配置文件

pgpool.conf是Pgpool-II的主配置文件。啟動Pgpool-II時可以使用 -f 參數(shù)指定 pgpool.conf路徑, 默認(rèn)是使用/etc/pgpool.conf.

Pgpool-II每個模式對應(yīng)的配置文件模板

圖2

復(fù)制一份作為你的配置文件:

# cd /etc# cp pgpool.conf.sample-replication pgpool.conf

2.5 配置backend信息

在pgpool.conf中加入如下格式的配置,其中0為backend主機(jī)號,不能重復(fù)。

backend_socket_dir = '/tmp'backend_hostname0 = '10.1.0.110'backend_port0 = 5432backend_weight0 = 1backend_data_directory0 = '/var/lib/pgsql/9.5/data/'backend_flag0 = 'ALLOW_TO_FAILOVER'

2.6 修改認(rèn)證方式

為了更安全,修改認(rèn)證方式為md5

2.6.1 修改pgpool-II的認(rèn)證方式為md5

vim /etc/pgpool-II/pool_hba.conf

# TYPE DATABASE USER CIDR-ADDRESS METHODhost all all 10.1.0.0/24 md5# "local" is for Unix domain socket connections onlylocal all all md5# ipv4 local connections:host all all 127.0.0.1/32 md5host all all ::1/128 md5

2.6.2 修改PostgreSQL的認(rèn)證方式為md5

vim pg_hba.conf

# TYPE DATABASE USER ADDRESS METHOD# "local" is for Unix domain socket connections only# IPv4 local connections:host all all 127.0.0.1/32 trusthost all all 10.1.0.0/24 md5# IPv6 local connections:host all all ::1/128 trust# Allow replication connections from localhost, by a user with the# replication PRivilege.local all postgres md5#local replication postgres peer#host replication postgres 127.0.0.1/32 ident#host replication postgres ::1/128 ident[root@im110 pgpool-II]#

2.7 測試pgpool-II同步

這里作簡單測試,在pgpool-II入口創(chuàng)建數(shù)據(jù)庫,看各節(jié)點(diǎn)是否自動創(chuàng)建,刪除后,看各節(jié)點(diǎn)是否自動刪除。

[root@im109 ~]# psql -U postgres -h 10.1.0.115 -p 9999Password for user postgres: psql (9.5.6)Type "help" for help.postgres=# show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay ---------+------------+-------+--------+-----------+--------+------------+-------------------+------------------- 0 | 10.1.0.110 | 54321 | up | 0.500000 | master | 0 | true | 0 1 | 10.1.0.109 | 54321 | up | 0.500000 | slave | 0 | false | 0(2 rows)postgres=# postgres=# /l List of databases Name | Owner | Encoding | Collate | Ctype | access privileges -----------+----------+----------+-------------+-------------+----------------------- 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 wiseucmsg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows)postgres=# create database test01;CREATE DATABASEpostgres=# /q[root@im109 ~]# psql -U postgres -h 10.1.0.110 -p 54321Password for user postgres: psql (9.5.6)Type "help" for help.postgres=# /l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- 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 test01 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | wiseucmsg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (5 rows)postgres=# /q[root@im109 ~]# psql -U postgres -h 10.1.0.109 -p 54321 Password for user postgres: psql (9.5.6)Type "help" for help.postgres=# /l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- 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 test01 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | wiseucmsg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (5 rows)postgres=# /q[root@im109 ~]# psql -U postgres -h 10.1.0.115 -p 9999 Password for user postgres: psql (9.5.6)Type "help" for help.postgres=# /l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- 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 test01 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | wiseucmsg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (5 rows)postgres=# drop database test01;DROP DATABASEpostgres=# /l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- 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 wiseucmsg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows)postgres=# /q[root@im109 ~]# psql -U postgres -h 10.1.0.110 -p 54321Password for user postgres: psql (9.5.6)Type "help" for help.postgres=# /l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- 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 wiseucmsg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows)postgres=# /q[root@im109 ~]# psql -U postgres -h 10.1.0.109 -p 54321Password for user postgres: psql (9.5.6)Type "help" for help.postgres=# /l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- 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 wiseucmsg | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (4 rows)postgres=# /q[root@im109 ~]#

測試成功,說明從pgpool-II入口操作,各節(jié)點(diǎn)會同步數(shù)據(jù)。

3. 安裝pgpoolAdmin(不推薦)

雖然官網(wǎng)提供此工具,用于頁面管理pgpool,但是我覺得不安全,且可能bug較多。以下文中會有一些bug列出來。 安裝方法:

3.1 解壓pgpoolAdmin至web目錄,使用戶能訪問其php

wget http://www.pgpool.net/download.php?f=pgpoolAdmin-3.5.3.tar.gz -O pgpoolAdmin-3.5.3.tar.gzcd /var/wwwtar -zxvf pgpoolAdmin-3.5.3.tar.gzln -s pgpoolAdmin-3.5.3 pgpooladminmkdir templates_cchmod 777 templates_cchown www conf/pgmgt.conf.phpchmod 644 conf/pgmgt.conf.php

3.2 php-fpm運(yùn)行用戶和pgpool用戶統(tǒng)一

pgpoolAdmin使用pcp命令控制pgpool啟停,因此需要統(tǒng)一php和pgpool運(yùn)行用戶,以便pgpoolAdmin從頁面控制pgpool啟停。可參考上文中2.2步驟操作。

3.3 根據(jù)向?qū)瓿砂惭b

訪問安裝頁面,完成檢測,完成安裝。 http://yourweb/pgpooladmin/install/ 圖3

從上圖看到,3.5下面的勾處未有文字提示,我此處為通過。因為我裝了php-psql擴(kuò)展。從源碼中也可以看出,是檢測pgsql擴(kuò)展。 圖4

.pcppass文件格式如下(pgpool3.5以下用到): 它的作用是用于指定連接postgresql的連接串,包括主機(jī)、端口、用戶、密碼。

host:port:user:password

3.4 一些細(xì)節(jié)說明

完全設(shè)置好的完整功能如下: 圖5 3.4.1) 顯示pgpoolAdmin運(yùn)行機(jī)器的hostname 若php報warning,可在hosts中添加IP對應(yīng)主機(jī)名

[root@im110 pgpoolAdmin-3.5.3]# vim /etc/hosts10.1.0.110 im110

3.4.2) 此處為pgpoolAdmin的登錄用戶,superuser: yes表示在pgpool數(shù)據(jù)庫中,用戶為管理員用戶。此數(shù)據(jù)庫可以pgpool下,也可分離到其它postgresql中。若此處非yes,則節(jié)點(diǎn)相關(guān)操作為不可操作的灰色。代碼中并未指定host,所以只能是使用socket。 圖6

3.4.3) 頁面中顯示節(jié)點(diǎn)是否連接,是在pgpool中show pool_nodes命令下的節(jié)點(diǎn)status.

[root@im109 ~]# psql -U postgres -h 10.1.0.115 -p 9999Password for user postgres: psql (9.5.6)Type "help" for help.postgres=# show pool_nodes; node_id | hostname | port | status | lb_weight | role | select_cnt | load_balance_node | replication_delay ---------+------------+-------+--------+-----------+--------+------------+-------------------+------------------- 0 | 10.1.0.110 | 54321 | up | 0.500000 | master | 0 | true | 0 1 | 10.1.0.109 | 54321 | up | 0.500000 | slave | 0 | false | 0(2 rows)

其它命令參考官方文檔: http://www.pgpool.net/docs/latest/en/html/reference.html

3.4.4) pgpool.conf 設(shè)置中的健康檢查,檢查postgressql是否啟動 此處是通過連接各節(jié)點(diǎn)是否成功來判斷的,因此需要在各節(jié)點(diǎn)創(chuàng)建用于連接的角色。 圖7

[root@im110 pgpool-II]# psql -U pgpool -p 54321 -h 10.1.0.110 template1Password for user pgpool: psql (9.5.6)Type "help" for help.template1=>

3.5 php.ini的disable_functions設(shè)置

源代碼中php調(diào)用的exec執(zhí)行pcp相關(guān)命令, 圖8 因此需要將php.ini配置文件中的disable_functions中的exec去掉,以允許php使用該函數(shù)。 圖9

3.6 pgpoolAdmin中pcp_stop_pgpool參數(shù)

在pgpool-II3.6中,pcp_stop_pgpool用法如下:

root@im110 pgpooladmin]# pcp_stop_pgpool --helppcp_stop_pgpool - terminate pgpool-IIUsage:pcp_stop_pgpool [OPTION...] Options: -U, --username=NAME username for PCP authentication -h, --host=HOSTNAME pgpool-II host -p, --port=PORT PCP port number -w, --no-password never prompt for password -W, --password force password prompt (should happen automatically) -m, --mode=MODE MODE can be "smart", "fast", or "immediate" -d, --debug enable debug message (optional) -v, --verbose output verbose messages -?, --help print this help

pgpoolAdmin中需要做相應(yīng)修改。 圖10

4. 總結(jié)

此PostgreSQL高可用方案搭建簡單方便,且可以在不影響原來環(huán)境的基礎(chǔ)上搭建;生產(chǎn)環(huán)境中的pgpoool-II是怎樣的我不好評判。網(wǎng)上此博客寫的不錯,可以看看,PG的兩種集群技術(shù):Pgpool-II與Postgres-XL
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 黄色视频一级毛片 | 中文字幕11 | 激情夜色| 色婷婷a v | 免费一级欧美大片视频 | 91一区二区在线观看 | www.17c亚洲蜜桃 | 成人在线视频免费 | 久久艹艹艹 | 色呦呦一区二区三区 | 欧美黄一区 | 国产91亚洲精品一区二区三区 | 久久精品在线免费观看 | 看毛片免费| 亚洲一区久久久 | 国产日韩在线观看一区 | 真人一级毛片免费 | h色视频在线观看 | 国产精品成人久久 | 91香蕉国产亚洲一区二区三区 | 免费午夜视频 | 欧美三级短视频 | 久久综合综合 | 免费三级大片 | 狠狠操电影 | 久久久久亚洲精品国产 | 精品一区二区三区免费毛片 | 黄色一级片在线观看 | 欧美a视频在线观看 | 欧美一级特级 | 国产精品久久久久久久成人午夜 | 国产一区免费视频 | wankzhd| 国内自拍网址 | 欧美人人干 | 久久久久久久久久美女 | 国产亚洲精品精 | 黄色高清免费 | 精品国产99久久久久久宅男i | 九九热在线视频观看 | 特级毛片a级毛片100免费 |