pgxl 系列之七: ubuntu 16.04 添加两个节点

版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/ctypyb2002/article/details/83411052

os: ubuntu 16.04
postgres-xl: 10alpha3

ip 规划:

gtm 192.168.56.99 gtm
gtms 192.168.56.100 gtm slave

node1 192.168.56.101 gtm-proxy,coordinator,datanode
node2 192.168.56.102 gtm-proxy,coordinator,datanode
node3 192.168.56.103 gtm-proxy,coordinator,datanode
node4 192.168.56.104 gtm-proxy,coordinator,datanode

node1、node2 互为主从,node3、node4 互为主从
端口使用情况

gtm               20001        gtm slave         20001

gtm proxy         20001        gtm proxy         20001
coordinator       20004        coordinator       20005
coordinator slave 20005        coordinator slave 20004
coordinator pool  20010        coordinator pool  20011
                  20011                          20010
datanode          20008        datanode          20009
datanode slave    20009	       datanode slave    20008
datanode pool     20012        datanode pool     20013
                  20013			                 20012

现在添加 node5、node6节点
node5 192.168.56.105 gtm-proxy,coordinator,datanode
node6 192.168.56.106 gtm-proxy,coordinator,datanode

node5、node6节点操作系统层级设置

参考另外一篇blog,详细过程略。

gtm 节点上添加 gtm-proxy

$ /usr/pgxl-10/bin/pgxc_ctl -c /var/lib/pgxl/10/pgxc_ctl/pgxc_ctl.conf 
PGXC help add

add gtm slave slave_name host port dir
add gtm_proxy name host port dir
add coordinator master name host port pooler dir extra_conf extra_pghba
add coordinator slave name host port pooler dir archDir
add datanode master name host port pooler dir waldir restore_datanode_name extra_conf extra_pghba
add datanode slave name host port pooler dir waldir archDir

Add the specified node to your postgres-xl cluster:
For more details, please see the pgxc_ctl documentation

PGXC$ add gtm_proxy gtm_proxy5 node5 20001 /var/lib/pgxl/10/gtm_proxy
PGXC$ monitor all
PGXC$
PGXC$ add gtm_proxy gtm_proxy6 node6 20001 /var/lib/pgxl/10/gtm_proxy
PGXC$ monitor all
PGXC$ 
PGXC$  

gtm 节点上添加 coordinator

$ /usr/pgxl-10/bin/pgxc_ctl -c /var/lib/pgxl/10/pgxc_ctl/pgxc_ctl.conf 
PGXC help add

add gtm slave slave_name host port dir
add gtm_proxy name host port dir
add coordinator master name host port pooler dir extra_conf extra_pghba
add coordinator slave name host port pooler dir archDir
add datanode master name host port pooler dir waldir restore_datanode_name extra_conf extra_pghba
add datanode slave name host port pooler dir waldir archDir

Add the specified node to your postgres-xl cluster:
For more details, please see the pgxc_ctl documentation

PGXC$ add coordinator master coord5 node5 20004 20010 /var/lib/pgxl/10/coord none none
PGXC$ add coordinator slave coord5 node6 20004 20010 /var/lib/pgxl/10/coord_slave /var/lib/pgxl/10/coord_archlog
PGXC$
PGXC$ monitor all
PGXC$ add coordinator master coord6 node6 20005 20011 /var/lib/pgxl/10/coord none none
PGXC$ add coordinator slave coord6 node5 20005 20011 /var/lib/pgxl/10/coord_slave /var/lib/pgxl/10/coord_archlog
PGXC$ monitor all
PGXC$  
PGXC$ 

gtm 节点上添加 datanode

$ /usr/pgxl-10/bin/pgxc_ctl -c /var/lib/pgxl/10/pgxc_ctl/pgxc_ctl.conf 
PGXC help add

add gtm slave slave_name host port dir
add gtm_proxy name host port dir
add coordinator master name host port pooler dir extra_conf extra_pghba
add coordinator slave name host port pooler dir archDir
add datanode master name host port pooler dir waldir restore_datanode_name extra_conf extra_pghba
add datanode slave name host port pooler dir waldir archDir

Add the specified node to your postgres-xl cluster:
For more details, please see the pgxc_ctl documentation

PGXC$ add datanode master node5 node5 20008 20012 /var/lib/pgxl/10/dn none none none none
PGXC$ monitor all
PGXC$

如果此时直接 add datanode slave node5 会报错,查看日志发现是 master node5 会重启,启动后的 listen_address 变为 localhost。
所以这里要事先在node5节点修改 master node 的 postgresql.conf、pg_hba.conf

$ vi postgresql.conf
listen_addresses = '*'

$ vi pg_hba.conf
host replication postgres 192.168.0.0/24 trust
PGXC$ add datanode slave node5 node6 20008 20012 /var/lib/pgxl/10/dn_slave none /var/lib/pgxl/10/dn_archlog 
PGXC$ monitor all
PGXC$ 

至此,datanode node5 master、slave 已经添加完成

下面添加 datanode node6 master、slave

PGXC$ add datanode master node6 node6 20009 20013 /var/lib/pgxl/10/dn none none none none
PGXC$ monitor all
PGXC$

node6 节点上修改

$ vi postgresql.conf
listen_addresses = '*'

$ vi pg_hba.conf
host replication postgres 192.168.0.0/24 trust

添加 datanode node6 slave

PGXC$ add datanode slave node6 node5 20009 20013 /var/lib/pgxl/10/dn_slave none /var/lib/pgxl/10/dn_archlog 
PGXC$ monitor all
PGXC$ 

查看结果

PGXC monitor all
Running: gtm master
Running: gtm slave
Running: gtm proxy gtm_proxy1
Running: gtm proxy gtm_proxy2
Running: gtm proxy gtm_proxy3
Running: gtm proxy gtm_proxy4
Running: gtm proxy gtm_proxy5
Running: gtm proxy gtm_proxy6
Running: coordinator master coord1
Running: coordinator slave coord1
Running: coordinator master coord2
Running: coordinator slave coord2
Running: coordinator master coord3
Running: coordinator slave coord3
Running: coordinator master coord4
Running: coordinator slave coord4
Running: coordinator master coord5
Running: coordinator slave coord5
Running: coordinator master coord6
Running: coordinator slave coord6
Running: datanode master node1
Running: datanode slave node1
Running: datanode master node2
Running: datanode slave node2
Running: datanode master node3
Running: datanode slave node3
Running: datanode master node4
Running: datanode slave node4
Running: datanode master node5
Running: datanode slave node5
Running: datanode master node6
Running: datanode slave node6
postgres=# select * from pgxc_node;
 node_name | node_type | node_port | node_host | nodeis_primary | nodeis_preferred |   node_id   
-----------+-----------+-----------+-----------+----------------+------------------+-------------
 coord1    | C         |     20004 | node1     | f              | f                |  1885696643
 coord2    | C         |     20005 | node2     | f              | f                | -1197102633
 coord3    | C         |     20004 | node3     | f              | f                |  1638403545
 coord4    | C         |     20005 | node4     | f              | f                |  -890157977
 node2     | D         |     20009 | node2     | f              | t                |  -927910690
 node3     | D         |     20008 | node3     | f              | t                |   914546798
 node4     | D         |     20009 | node4     | f              | t                |   759086513
 coord5    | C         |     20004 | node5     | f              | f                | -1869430451
 coord6    | C         |     20005 | node6     | f              | f                |  -543030629
 node1     | D         |     20008 | node1     | t              | t                |  1148549230
 node5     | D         |     20008 | node5     | f              | f                |    65864847
 node6     | D         |     20009 | node6     | f              | f                | -1988534050
(12 rows)

至此,完成添加node5、node6节点的 gtm-proxy,coordinator,datanode。
如果有需要可以对添加节点前的表重新 distribute

peiybdb=>  ALTER TABLE fact_sales ADD NODE (node5);
peiybdb=>  ALTER TABLE fact_sales ADD NODE (node6);

peiybdb=>  ALTER TABLE fact_sales distribute by hash(qty);

参考:
https://www.postgres-xl.org/documentation/tutorial-createcluster.html

猜你喜欢

转载自blog.csdn.net/ctypyb2002/article/details/83411052