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. day36——死锁、递归锁、信号量、GIL、多线程实现socket通信、线程池和进程池

    day36 死锁现象与递归锁 死锁现象 是指两个或两个以上的进程或线程在执行过程中,因争夺资源而造成的一种互相等待的现象,若无外力作用,它们都将无法推进下去.此时称系统处于死锁状态或系统产生了死锁,这 ...

  2. ② Python3.0 运算符

    Python3.0 语言支持的运算符有: 算术运算符.比较(关系)运算符.赋值运算符.逻辑运算符.位运算符.成员运算符.身份运算符.运算符优先级 一.算术运算符 常见的算术运算符有+,-,*,/,%, ...

  3. 进入恢复模式(Recovery HD)

    进入恢复模式(Recovery HD) 1,选中要启动的虚拟机,随后点击VM菜单的启动按钮后面向下箭头,随后点击菜单项”打开电源时进入固件“. 2,在虚拟机里面,用上下键移动到”Enter setup ...

  4. Java知识回顾 (11) 异常处理

    距离最近的 Java知识回顾系列(10),2019.4.24日,到现在,已经近半年过去了. 感觉,做一件事情,如果有头无尾,实在不好,心里会一直悬着.所以,现在继续上面的内容. 再次声明,正如(1)中 ...

  5. 1.工厂模式(Factory Method)

    注:图片来源于 https://www.cnblogs.com/-saligia-/p/10216752.html 工厂UML图解析: 工厂模式:client用户需要三步: 1.创建工厂: 2.生产产 ...

  6. ES6之promise原理

    我在这里介绍了promise的原理: https://juejin.im/post/5cc54877f265da03b8585902 我在这里 仅仅张贴 我自己实现的简易promise——DiProm ...

  7. Fortify漏洞之Dynamic Code Evaluation: Code Injection(动态脚本注入)和 Password Management: Hardcoded Password(密码硬编码)

    继续对Fortify的漏洞进行总结,本篇主要针对  Dynamic Code Evaluation: Code Injection(动态脚本注入) 和 Password Management: Har ...

  8. RabbitMQ direct交换器

    1:队列和交换器多次绑定 String[] routekeys={"routekey1","routekey2","routekey3"}; ...

  9. [ipsec][strongswan] 使用VTI配置基于路由的ipsec

    之前写的一个:[dev][ipsec] 基于路由的VPrivateN 一 我们默认用strongswan的时候基于策略的. 也就是policy. 基于策略的ipsec中, policy承担了两部分功能 ...

  10. Linux下 启动tomcat 时候同时日志命令

    ./startup.sh && tail -f ../logs/catalina.out