接上篇《初识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