pgpool-II 是一個中間 件,工作在PostgreSQL多服 務 器和PostgreSQL數據 庫 客 戶 端之 間。使用并行 查 詢 功能,數據可分布在多
pgpool-II 是一個中間 件,工作在PostgreSQL多服 務 器和PostgreSQL數據 庫 客 戶 端之 間。
它提供了以下功能
連 接池: pgpool -Ⅱ保存 連 接到PostgreSQL服 務 器,并重復利用具有相同屬性的新的 連 接(即用 戶 名,數據 庫 , 協議 的版本),減少 連 接的開 銷 ,并提高了系 統 的整體吞吐量。復制: pgpool - II可以管理多個PostgreSQL服務器。 使用復制功能,可以 實時備份在 2個或多個物理磁 盤 上,因此即使在硬 盤出故障的時候也不用停止服務。
負載 平衡: 如果數據 庫 是復制,任何服 務 器上 執 行一個SELECT 查 詢 將返回相同的 結 果。 pgpool -Ⅱ采用一個復制功能 優 勢 是,以減少多個服 務 器之 間 分配上的SELECT 查 詢 每個PostgreSQL服 務 器的 負載 ,提高系 統 的整體吞吐量。在最好的,性能的提高比例的PostgreSQL服 務 器的數量。在同一 時間有 大量用 戶 的 查 詢的時候,負載 平衡的情況下有最佳的 執 行。
連接超 過限制 : 有一個關于與 PostgreSQL 的最大并 發連 接數限制,最大 連接數超過后 的 連 接被拒 絕 。 設 置最大 連 接數,但是增加的 資 源消耗和影響系 統 性能。 pgpool - II 也有 對 最大 連 接數的限制,但 額 外的 連 接將被排 隊 ,而不是立即返回 錯誤 。
并行查詢 : 使用并行 查 詢 功能,數據可分布在多個服 務 器中,以便 查 詢 可以 執 行所有服 務 器上同 時 減少 總 體 執 行 時間 。 并行 查 詢 的工作 時 候 , 尋 找最佳的大 規 模的數據。
進行pgpool搭建前需要配置好postgresql的流復制,操作步驟參考
一、安裝
wget ?f=pgpool-II-3.4.0.tar.gz
tar -zxvf pgpool-3.4.0.tar.gz
cd pgpool-II-3.4.0/
./configure --prefix=/usr/local/pgpool --with-pgsql=path --with-pgsql=/usr/local/pgsql
make
make install
chown postgres.postgres /usr/local/pgpool/ -R
chown postgres.postgres /usr/src/pgpool-II-3 -R
mkdir /var/run/pgpool
chown postgres.postgres /var/run/pgpool/
#切換postgres 用戶安裝一些函數
su - postgres
cd /usr/src/pgpool-II-3.4.0/src/sql/
make
make install
cd pgpool-recovery/
make install
cd ../pgpool-regclass/
make install
二、配置
cd /usr/local/pgpool/etc
cp pcp.conf.sample pcp.conf
pg_md5 postgres
e8a48653851e28c69d0506508fb27fc5
echo "postgres:e8a48653851e28c69d0506508fb27fc5" >> pcp.conf
echo "postgres:e8a48653851e28c69d0506508fb27fc5" >> pool_passwd
cp pool_hba.conf.sample pool_hba.conf
vim pool_hba.conf
host all postgres db2 md5
listen_addresses = '*' #允許所有主機監聽
port = 9999 #訪問端口
backend_hostname0 = 'db1' #DBmaster ip
backend_port0 = 5432 #DBmaster postgresql 端口
backend_weight0 = 1 #權重
backend_data_directory0 = '/opt/data' #DBmaster 數據庫目錄
backend_flag0 = 'ALLOW_TO_FAILOVER' #允許切換
backend_hostname0 = 'db2'
backend_port0 = 5432
backend_weight0 = 1
backend_data_directory0 = '/opt/data'
backend_flag0 = 'ALLOW_TO_FAILOVER'
enable_pool_hba = on #隨意,自由定制,,使用 pool_hba.conf 對client的驗證
pool_passwd = 'pool_passwd' #md5驗證文件
sr_check_user = 'postgres' #用來故障切換的用戶
failover_command = '/usr/local/pgsql/bin/failover_command.sh %d %H /tmp/trigger_file'
故障切換腳本
vim /usr/local/pgsql/bin/failover_command.sh
#! /bin/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=$1
new_master=$2
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;
chmod +x /usr/local/pgsql/bin/failover_command.sh
三、調試
啟動命令,帶有日志輸出
[postgres@db1 etc]$ pgpool -nd >/tmp/pgpool.log 2>&1 &
[postgres@db1 etc]$ netstat -ntlp
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:9898 0.0.0.0:* LISTEN 16664/pgpool
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 16664/pgpool
tcp 0 0 :::22 :::* LISTEN -
tcp 0 0 ::1:25 :::* LISTEN -
tcp 0 0 :::9999 :::* LISTEN 16664/pgpool
登錄
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com