您的位置:首页 > 运维架构 > Linux

Database-Postgresql-Centos 7安装citus集群

2019-05-13 13:53 471 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/adson1987/article/details/90171878

Database-Postgresql-Centos 7安装citus集群


安装基于postgresql10的citus集群
三个节点,centos7.4,一个coordinator,两个worker
基础环境(ip、selinux、ssh互信等已完成)

第一步:扩展依赖安装:

yum install -y epel-release && yum update -y

第二步:安装citus源:

curl https://install.citusdata.com/community/rpm.sh | sudo bash

第三步:配置postgresql源:

vi /etc/yum.repos.d/pgdg-11-centos.repo
将11都改为10

第四步:安装citus和postgresql10、postgis2.5

#yum install -y citus74_10 此命令将安装postgresql10
#yum install -y postgis25_10 安装postgis

第五步:initialize a database

#initialize system database (using RHEL 6 vs 7 method as necessary)
sudo service postgresql-10 initdb || sudo /usr/pgsql-10/bin/postgresql-10-setup initdb
#preload citus extension
echo “shared_preload_libraries = ‘citus’” | sudo tee -a /var/lib/pgsql/10/data/postgresql.conf

第六步:Configure connection and authentication:

sudo vi /var/lib/pgsql/10/data/postgresql.conf
#Uncomment listen_addresses for the changes to take effect
listen_addresses = ‘*’

sudo vi /var/lib/pgsql/10/data/pg_hba.conf
#Allow unrestricted access to nodes in the local network. The following ranges
#correspond to 24, 20, and 16-bit blocks in Private IPv4 address spaces.
host all all 10.0.0.0/8 trust

#Also allow the host unrestricted access to connect to itself
host all all 127.0.0.1/32 trust
host all all ::1/128 trust

该实验在pg_hba.cong只执行
echo “host all all 0.0.0.0/0 trust” | sudo tee -a /var/lib/pgsql/10/data/pg_hba.conf

第七步:Start database servers, create Citus and Postgis extension

service postgresql-10 restart
chkconfig postgresql-10 on

sudo -i -u postgres psql -c “CREATE EXTENSION citus;”
sudo -i -u postgres psql -c “CREATE EXTENSION postgis;”
sudo -i -u postgres psql -c “alter user postgres with password ‘postgres’;”

以下只在coordinator节点执行

第八步:Add worker node information

sudo -i -u postgres psql -c “SELECT * from master_add_node(‘worker1’, 5432);”
sudo -i -u postgres psql -c “SELECT * from master_add_node(‘worker2’, 5432);”

第九步:Verify that installation has succeeded

[root@coordinator ~]# sudo -i -u postgres psql -c “SELECT * FROM master_get_active_worker_nodes();”
node_name | node_port
-----------±----------
worker2 | 5432
worker1 | 5432
(2 rows)

示例:

1、连接postgresql数据库,创建一张表test_table
2、配置分片策略:
SELECT master_create_distributed_table(‘test_table’, ‘id’, ‘hash’);
3、配置分片操作(将表分为2片,每个分片有两个副本)
SELECT master_create_worker_shards(‘test_table’, 2, 2);
4、装载数据
5、查看分片
SELECT * from pg_dist_shard;
6、查看分片分布
SELECT * from pg_dist_shard_placement order by shardid, placementid;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: