citus的分布式集群目前在苏宁大规模应用,苏宁陈华军也做了很多技术分享和博客介绍。目前所有的教程都是rpm和pg一起安装,个人不喜欢,毕竟citus定位是个插件,我想在我已安装的pg上源码装一个citus比较好。

一 集群规划

主机名 IP 角色 端口
coordinate 192.168.0.55 coordinate 5432
worker1 192.168.0.65 worker 5432
worker2 192.168.0.66 worker 5432
worker3 192.168.0.67 worker 5432
worker4 192.168.0.68 worker 5432

coordinate:协调节点,一般称为cn,存储所有元数据,不存实际数据,该节点直接对用户开放,等于一个客户端。
worker:工作节点,不存储元数据,存储实际数据。执行协调节点发来的查询请求。一般不直接对用户开放。

二 安装步骤

2.1 安装pg

在每个主机节点上都安装postgresql11。
详细参考: Centos7安装PostgreSQL
其中,coordinate节点的pg_hba.conf配置:

# IPv4 local connections:
host all all 0.0.0.0/0 md5

worker节点的pg_hba.conf配置:

# IPv4 local connections:
host all all 192.168.0.0/24 trust

2.2 安装citus

在每个节点上都安装citus。
从github上下载源码:https://github.com/citusdata/citus/releases

 
latest.png
[root@localhost opt]# wget https://github.com/citusdata/citus/archive/v8.1.1.tar.gz
[root@localhost opt]# tar -zxvf v8.1.1.tar.gz
[root@localhost opt]# cd citus8.1.1
#先安装curl依赖
[root@localhost citus-8.1.1]# yum install curl
[root@localhost citus-8.1.1]# yum install curl-devel
# 导入pg的环境变量
[root@localhost citus-8.1.1]# source /home/postgres/.bashrc
# 安装
[root@localhost citus-8.1.1]# ./configure
[root@localhost citus-8.1.1]# make
[root@localhost citus-8.1.1]# make install

三 集群配置

3.1 创建测试数据库

在所有节点执行以下语句:

[postgres@localhost ~]$ psql
psql (11.1)
Type "help" for help. postgres=# \c test
You are now connected to database "test" as user "postgres".
test=# create extension citus;

3.2 协调节点新增工作节点

以后的管理操作仅仅在协调节点(cn)上操作

[postgres@localhost ~]$ psql -d test
psql (11.1)
Type "help" for help.
# 节点可以是ip或者dns name
test=# SELECT * from master_add_node('worker1', 5432);
test=# SELECT * from master_add_node('worker2', 5432);
test=# SELECT * from master_add_node('worker3', 5432);
test=# SELECT * from master_add_node('worker4', 5432);
#查看工作节点:
test=# SELECT * FROM master_get_active_worker_nodes();
node_name | node_port
-----------+-----------
worker2 | 5432
worker4 | 5432
worker1 | 5432
worker3 | 5432
(4 rows)

3.3 创建分片表

test=# create table shiptrack(gid serial primary key,tracktime timestamp without time zone,geom geometry(Point,4326));
#旧版的master_create_distributed_table,master_create_worker_shards都已被废弃,现在由create_distributed_table替换。
#配置分片策略
#设置分片数,4个主机,设置分片4,每个主机一张表
test=# set citus.shard_count=4;
# 配置副本数
test=# set citus.shard_replication_factor=2;
test=# SELECT create_distributed_table('shiptrack', 'gid', 'hash'); # 查看分片分布
test=# SELECT * from pg_dist_shard_placement order by shardid, placementid;
shardid | shardstate | shardlength | nodename | nodeport | placementid
---------+------------+-------------+----------+----------+-------------
102016 | 1 | 0 | worker1 | 5432 | 25
102016 | 1 | 0 | worker2 | 5432 | 26
102017 | 1 | 0 | worker2 | 5432 | 27
102017 | 1 | 0 | worker3 | 5432 | 28
102018 | 1 | 0 | worker3 | 5432 | 29
102018 | 1 | 0 | worker4 | 5432 | 30
102019 | 1 | 0 | worker4 | 5432 | 31
102019 | 1 | 0 | worker1 | 5432 | 32

有4个worker,所以数据分片为4,每个分片,做两个副本。通过分片分布,如102016分布在worker1,worker2上,同理102017分布在worker2,worker3上。
假设worker1机器宕机了,集群访问102016原先是方位worker1的,现在会自动访问worker2上的102016分片。 也就是说,单个数据节点故障,集群还能正常用,通过多设置副本,多个节点故障也能更强壮。

四 citus常用命令

4.1 集群创建function,role,extension命令

SELECT run_command_on_workers($cmd$
/* the command to run */
drop extension pg_pathman;
$cmd$);

作者:遥想公瑾当年
链接:https://www.jianshu.com/p/ab4b86602fa1
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

Centos7 源码安装PostgreSQL Citus集群 (转载)的更多相关文章

  1. CentOS7 源码安装 PostgreSQL 12

    PostgreSQL 12 源码安装 Table of Contents 1. 下载 2. 准备环境 3. 编译安装 4. 设置环境变量 5. 初始化数据库 6. 配置参数文件 6.1. postgr ...

  2. centos7源码安装Python3的前提条件

    centos7源码安装Python3的前提条件: # yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline- ...

  3. 国产龙芯服务器源码安装PostgreSQL数据库的方法

    1. 公司最近有一些国产化项目的需求, 要求在国产CPU的服务器上面安装pg数据库等. 2.. 但是差查了下中标麒麟的官网,在龙芯MIPS的操作系统包源里面仅有 postgreSQL 9.2 版本的r ...

  4. centos7源码安装mysql5.7.19

    centos7源码包安装mysql5.7 5.7.20安装方法和5.7.19的一样. 1.安装前准备 清空环境.安装相应的软件包 1>关闭防火墙和SELinux 2>配置yum源(阿里云, ...

  5. 云原生分布式 PostgreSQL+Citus 集群在 Sentry 后端的实践

    优化一个分布式系统的吞吐能力,除了应用本身代码外,很大程度上是在优化它所依赖的中间件集群处理能力.如:kafka/redis/rabbitmq/postgresql/分布式存储(CephFS,Juic ...

  6. Centos7源码安装mysql及读写分离,互为主从

       Linux服务器 -源码安装mysql 及读写分离,互为主从   一.环境介绍: Linux版本: CentOS 7 64位 mysq版本: mysql-5.6.26 这是我安装时所使用的版本, ...

  7. CentOS7源码安装qbittorrent最新版本

    CentOS的软件 yum 里 yum search qbittorrent yum info qbittorrent 找到的是3.37版本 官网最新的是4.12版本.但需要源码安装: 官网下载最新版 ...

  8. CentOS7源码安装Redis5.0.4非关系型数据库

    源码安装redis-5.0.4 一. 下载redis 1. 需要连接网络 二. 案例(另一种安装方法) [root@localhost ~]# wget http://download.redis.i ...

  9. Centos7源码安装Apache和PHP

    源码安装Apache 安装需要的依赖 yum -y install gcc autoconf automake make pcre pcre-devel openssl openssl-devel​# ...

随机推荐

  1. python基础 — 循环重新输入

    后续完善各种循环案例 while True: try: str_num = input('input a number:') num = float(str_num) print("你输入的 ...

  2. Ali-Tomcat 安装

    通过在 Eclipse 安装 Tomcat4e 插件,或者在 Intellij Idea 安装配置 Ali-tomcat,可以快 速方便地启动并调试基于 EDAS 服务化框架 HSF 开发的应用. 1 ...

  3. PyTorch工具

    以装饰器添加所有代码对应的tensor的信息 https://github.com/zasdfgbnm/TorchSnooper

  4. ②将SVN迁移到GitLab-多分支多标签迁移

    之前我们介绍了<①将SVN迁移到GitLab-单分支迁移>,文中研究了svn迁移到git单分支的操作过程,本文针对实际开发过程中svn使用到的trunk.branches.tags情况进行 ...

  5. Git提交代码解决方案

    最近做项目不再用小乌龟了,开始用git,便做了记录如下,后期可以看看自己是怎么使用的   下载安装就不说了,直接进入使用环节.   1.使用规则 git pull origin master 和 gi ...

  6. 1+X证书学习日志——函数

    工具得特点: 1:重复性使用 2:隐藏内部原理(细节) 3:选择性应用 创建函数: 1:关键字 function 函数名称(){ } 2:字面量创建 var fn = function(){ } 3: ...

  7. [C#(WinForm)]判断第一次启动程序

    来源:https://bbs.csdn.net/topics/220023353/(10楼) 在判断窗口上添加: string strIsFirstRun = "false"; b ...

  8. LinuxKernel优秀博客

    1.vanbreaker的专栏 2.LinuxKernel Exploration 3.DroidPhone的专栏 4.Linux内核研究以及学习文档和ARM学习以及研究的开放文档   [力荐] 5. ...

  9. RedHat6.9下替换yum源

    因为RedHat的yum需要收费,且要注册后才能使用.因此想把Yum源更新为CentOS的.使用的RedHat版本为6.9,因此对应的CentOS版本也要为6.9 1. 检查并删除原有的yum源 rp ...

  10. HDFS写流程

    HDFS client首先会与NameNode交互元数据信息,然后NameNode制定策略,分配NameNode节点,客户端先会与离自己最近的DataNode进行socket连接,已经与DataNod ...