【Postgresql分布式---单节点多实例部署citus】

2021/12/26 19:11:21

本文主要是介绍【Postgresql分布式---单节点多实例部署citus】,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.安装依赖
yum -y install libcurl-devel openssl-devel zlib-devel readline-devel libevent-devel autoconf

2.创建cn 和 worker 节点
su - pg10
mkdir -p /home/pg10/{data_cn,data_worker01,data_worker02}

3.初始化三个实例
initdb -D /home/pg10/data_cn
initdb -D /home/pg10/data_worker01
initdb -D /home/pg10/data_worker02

4.修改postgresql.auto.conf文件里实例端口和listen_addresses
echo “PORT=1921”>> /home/pg10/data_cn/postgresql.auto.conf
echo “PORT=7000”>> /home/pg10/data_worker01/postgresql.auto.conf
echo “PORT=8000”>> /home/pg10/data_worker02/postgresql.auto.conf

echo “listen_addresses=’’">> /home/pg10/data_cn/postgresql.auto.conf
echo "listen_addresses=’’”>> /home/pg10/data_worker01/postgresql.auto.conf
echo “listen_addresses=’*’”>> /home/pg10/data_worker02/postgresql.auto.conf

5.启动三个实例
pg_ctl start -D /home/pg10/data_cn -l /tmp/cnlog
pg_ctl start -D /home/pg10/data_worker01 -l /tmp/dn1log
pg_ctl start -D/home/pg10/data_worker02 -l /tmp/dn2log

6.连接到每个实例下创建 postgres 超级用户
psql -d postgres -p 1921 -c "CREATE USER postgres WITH SUPERUSER PASSWORD ‘1qaz@WSX’; "
psql -d postgres -p 7000 -c "CREATE USER postgres WITH SUPERUSER PASSWORD ‘1qaz@WSX’; "
psql -d postgres -p 8000 -c “CREATE USER postgres WITH SUPERUSER PASSWORD ‘1qaz@WSX’;”

7.编译安装 citus
我的压缩包为v8.3.2.tar.gz,放在/home/pg10/resource目录下
cd /home/pg10/resource
tar -zxvf v8.3.2.tar.gz
cd citus-8.3.2/

./autogen.sh
./configure
make -j24
make install -j24

8.给每个实例下的 pg_hba.conf 添加如下
vi /home/pg10/data_cn/pg_hba.conf
host all all 0.0.0.0/0 trust

vi /home/pg10/data_worker01/pg_hba.conf
host all all 0.0.0.0/0 trust

vi /home/pg10/data_worker02/pg_hba.conf
host all all 0.0.0.0/0 trust

9.reload使配置生效
pg_ctl reload -D /home/pg10/data_cn
pg_ctl reload -D /home/pg10/data_worker01
pg_ctl reload -D /home/pg10/data_worker02

10.在 postgresql.conf 中添加 预载库,并重新启动
echo “shared_preload_libraries = ‘citus’” >>
/home/pg10/data_cn/postgresql.conf

echo “shared_preload_libraries = ‘citus’” >> /home/pg10/data_worker01/postgresql.conf

echo “shared_preload_libraries = ‘citus’” >> /home/pg10/data_worker02/postgresql.conf

重新启动
pg_ctl restart -D /home/pg10/data_cn
pg_ctl restart -D /home/pg10/data_worker01
pg_ctl restart -D /home/pg10/data_worker02

11.在每个节点创建 citus扩展
psql -U postgres -d postgres -p 1921 -c “CREATE EXTENSION IF NOT EXISTS citus;”
psql -U postgres -d postgres -p 7000 -c “CREATE EXTENSION IF NOT EXISTS citus;”
psql -U postgres -d postgres -p 8000 -c “CREATE EXTENSION IF NOT EXISTS citus;”

12.在cn 节点添加 worker (172.20.10.7为我部署citus的这台主机的ip)
psql -U postgres -d postgres -p 1921
SELECT master_add_node(‘172.20.10.7’,7000);
SELECT master_add_node(‘172.20.10.7’,8000);

//如果添加错误可以用如下命令移除节点
select master_remove_node(‘localhost’, ‘port’);

13.验证添加结果
SELECT * FROM master_get_active_worker_nodes();



这篇关于【Postgresql分布式---单节点多实例部署citus】的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程