接上篇《初識Postgres-XL》https://segmentfault.com/a/11...
寫一下Postgres-XL(簡稱PGXL)的部署與測試。html
第一節 安裝
安裝很簡單,源碼安裝,和PG的安裝基本相同,可能比PG多一個依賴庫。在全部節點上執行相同操做。node
./configure make make install
若是執行./configure報錯則根據提示安裝相應的庫便可,如readline-devel等。默認的安裝目錄是/usr/local/pgsql,和原生PG相同,很順手。須要注意的是pgxc_ctl這個工具須要單獨編譯安裝,在源碼包的contrib/pgxc_ctl/目錄下執行make && make install便可。sql
第二節 配置
集羣的配置能夠經過兩種方式完成:
第一種,手動配置:首先經過initgtm、initdb命令在相應的節點上初始化GTM、GTM Proxy(非必須)初始化Coordinator和Datanode節點,而後依次啓動GTM、Coordinator和Datanode。不推介這種方式,不細說。
第二種,經過pgxc_ctl這個工具配置管理集羣:使用pgxc_ctl配置集羣以前須要在當前節點和集羣各個節點之間作ssh免密碼認證,執行pgxc_ctl的節點能夠是集羣內的任意一個節點也能夠是集羣外的節點。這個工具的原理大概是經過ssh執行各類bash命令完成集羣各節點的配置與啓動,很是方便,能夠徹底控制整個集羣與各個節點。pgxc_ctl的官方操做手冊在這裏:http://files.postgres-xl.org/...
配置過程以下:
直接執行pgxc_ctl,進入pgxc_ctl命令行環境,第一次執行會在主目錄下生成pgxc_ctl目錄,其中包括配置文件與日誌,首次執行pgxc_ctl會提示沒找到配置文件,由於此時尚未配置文件,在pgxc_ctl命令行中執行prepare,會生成默認的配置文件pgxc_ctl.conf,此時q退出命令行,編輯生成的配置文件,再次執行pgxc_ctl時就會使用這個配置文件。
個人集羣配置是這樣的:三臺機器,地址分別是172.17.0.二、172.17.0.四、172.17.0.5,一臺跑GTM,另外兩臺同時跑Coordinator和Datanode節點,暫不考慮高可用配置。下面將我在pgxc_ctl.conf中的配置貼出來,省去了無關配置與註釋:segmentfault
#---- OVERALL ----------------------------------------------------- pgxcOwner=postgres # owner of the Postgres-XC databaseo cluster. pgxcUser=$pgxcOwner # OS user of Postgres-XC owner tmpDir=/tmp # temporary dir used in XC servers localTmpDir=$tmpDir # temporary dir used here locally configBackup=n # If you want config file backup, specify y to this value. #---- GTM Master -------------------------------------------------- gtmName=gtm gtmMasterServer=172.17.0.2 gtmMasterPort=6666 gtmMasterDir=/pgdata/gtm gtmExtraConfig=none # Will be added gtm.conf for both Master and Slave (done at initilization only) gtmMasterSpecificExtraConfig=none # Will be added to Master's gtm.conf (done at initialization only) #---- GTM Slave ----------------------------------------------- gtmSlave=n # Specify y if you configure GTM Slave. #---- GTM Proxy ----------------------------------------------- gtmProxy=n #---- Coordinators ------------------------------------------------ #---- shortcuts ---------- coordMasterDir=/pgdata/coord coordSlaveDir=/pgdata/coord coordArchLogDir=/pgdata/coord/archive #---- Overall ------------ coordNames=(c1 c2) # Master and slave use the same name coordPorts=(5432 5432) # Master ports poolerPorts=(5433 5433) # Master pooler ports coordPgHbaEntries=(0.0.0.0/0) # #---- Master ------------- coordMasterServers=(172.17.0.4 172.17.0.5) # none means this master is not available coordMasterDirs=($coordMasterDir $coordMasterDir) coordMaxWALsernder=0 # max_wal_senders coordMaxWALSenders=($coordMaxWALsernder $coordMaxWALsernder) # #---- Slave ------------- coordSlave=n #---- Configuration files--- coordExtraConfig=coordExtraConfig # Extra configuration file for coordinators. cat > $coordExtraConfig <<EOF #================================================ # Added to all the coordinator postgresql.conf # Original: $coordExtraConfig log_destination = 'stderr' logging_collector = on log_directory = 'pg_log' listen_addresses = '*' coordSpecificExtraConfig=(none none) coordExtraPgHba=none # Extra entry for pg_hba.conf. coordSpecificExtraPgHba=(none none) #---- Datanodes --------------------------------------------------- #---- Shortcuts -------------- datanodeMasterDir=/pgdata/datanode datanodeSlaveDir=/pgdata/datanode datanodeArchLogDir=/pgdata/datanode/archive #---- Overall --------------- datanodeNames=(d1 d2) datanodePorts=(15432 15432) # Master ports datanodePoolerPorts=(5434 5434) # Master pooler ports datanodePgHbaEntries=(0.0.0.0/0) # #---- Master ---------------- datanodeMasterServers=(172.17.0.4 172.17.0.5) # none means this master is not available. datanodeMasterDirs=($datanodeMasterDir $datanodeMasterDir) datanodeMaxWalSender=0 datanodeMaxWALSenders=($datanodeMaxWalSender $datanodeMaxWalSender) #---- Slave ----------------- datanodeSlave=n # ---- Configuration files --- datanodeExtraConfig=none # Extra configuration file for datanodes. datanodeSpecificExtraConfig=(none none) datanodeExtraPgHba=none # Extra entry for pg_hba.conf. datanodeSpecificExtraPgHba=(none none) #---- WAL archives ---------------------------------------------- walArchive=n # ----End of Configuration Section----
配置文件看着挺長,其實理順了以後發現要配置的地方其實就那麼幾塊。
完成配置文件以後,一切就變得爲所欲爲,你須要作的只是執行pgxc_ctl,在其交互式環境中執行init all 便可完成全部節點的初始化可啓動。以後執行monitor all 查看全部節點的狀態。pgxc_ctl還能完成啓停節點、增刪節點等一系列操做,具體能夠參考官方操做文檔:http://files.postgres-xl.org/...bash
先到這裏,有時間的話寫一下我在試用PGXL過程當中遇到的問題以及可用性評估等。ssh