Postgres-XL集群安装部署
一、集群的规划
useradd postgres
passwd postgres
su - postgres
mkdir ~/.ssh
chmod 700 ~/.ssh
2、关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld #重启不会启动
systemctl status firewalld #查看一下状态,确定一下
关闭selinux,编辑/etc/selinux/config文件
将SELINUX的值设置为disabled
3、进行域名解析,配置/etc/hosts,在末尾添加如下内容
192.168.1.1 gtm
192.168.1.5 datanode1
192.168.1.6 datanode2
192.168.1.7 backupnode1
192.168.1.8 backupnode2
4、配置gtm到其他节点免密ssh登陆,在gtm节点操作
su – postgres
ssh-keygen -t rsa #这里一定要一直按回车,不要输入任何字符
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys postgres@datanode1:~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys postgres@datanode2:~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys postgres@backupnode1:~/.ssh/authorized_keys
scp ~/.ssh/authorized_keys postgres@backupnode2:~/.ssh/authorized_keys
tar -zxvf postgres-xl-9.5r1.6.tar.gz
cd postgres-xl
./configure --prefix=/home/postgres/pgxl/
make
make install
cd contrib/
make
make install
4、配置环境变量,在每个节点操作,需切换到postgres用户
su – postgres
# vi ~/.bashrc
export PGHOME=/usr/local/pgsql
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH
# source ~/.bashrc
注:可以用echo $PGHOME查看变量是否生效
5、每个节点目录权限设置,切换为root用户 su root
# chown -R postgres:postgres /usr/local/pgsql
6、配置集群配置文件,仅在gtm上配置,先生成一份模板,在修改其中内容,然后同步到其他设备,
gxc_ctl ---忽略错误提示
PGXC prepare ---该命令会生成一份模板配置文件
PGXC ^C
编辑/home/postgres/pgxc_ctl/pgxc_ctl.conf
#---- GTM Master -----------------------------------------------
#---- Overall ----
gtmName=gtm
gtmMasterServer=gtm
gtmMasterPort=6666
gtmMasterDir=$HOME/pgxc/nodes/gtm
#---- Configuration ---
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 -----------------------------------------------
# Because GTM is a key component to maintain database consistency, you may want to configure GTM slave
# for backup.
#---- Overall ------
gtmSlave=y # Specify y if you configure GTM Slave. Otherwise, GTM slave will not be configured and
# all the following variables will be reset.
gtmSlaveName=gtm_slaver
gtmSlaveServer=backupnode1 # value none means GTM slave is not available. Give none if you don't configure GTM Slave.
gtmSlavePort=20001 # Not used if you don't configure GTM slave.
gtmSlaveDir=$HOME/pgxc/nodes/gtm # Not used if you don't configure GTM slave.
# Please note that when you have GTM failover, then there will be no slave available until you configure the slave
# again. (pgxc_add_gtm_slave function will handle it)
#---- Configuration ----
gtmSlaveSpecificExtraConfig=none # Will be added to Slave's gtm.conf (done at initialization only)
pgxc_ctl init all #会初始化其他节点
pgxc_ctl monitor all #查看节点是否运行
五、测试集群
可以在任意节点上输入以下命令,查看除gtm以外的所有节点的配置情况:
select * from pgxc_node;
简单的测试,在datanode1节点上创建一个数据库test,并创建一个表test,插入数据:
psql -p 20004 -U postgres
CREATE DATABASE test;
\c test
CREATE TABLE test(id int);
INSERT INTO test VALUES(1);
SELECT * FROM test;
\q
在datanode2节点上查看刚刚在datanode1节点的更改:
psql -p 20004 -U postgres
\c test
SELECT * FROM test;
\q
测试是有数据,至此我们的pg_xl集群搭建完毕!
相关文章