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. leetcode 罗马数字和数字的互相转换

    不知哪个大佬说过: 关于字符串的题都可以用指针或哈希解决. 罗马数字转数字: 思想: 我们能观察到规律: 一般情况下,表示大的字母在前,小字母在后; 特殊情况下,小字母会在大字母之前,但是相应的,得到 ...

  2. php位运算及其高级应用

    我们之前学过逻辑与(&&)      条件1 && 条件2 当两边条件同时成立时候返回1 逻辑或(||)         条件1 || 条件2    当两边条件只要有一 ...

  3. mybatis内置参数及foreach使用

  4. diverta 2019 Programming Contest 2

    A:签到. #include<bits/stdc++.h> using namespace std; #define ll long long #define inf 1000000010 ...

  5. go 学习笔记(3) 基础结构

    package main import ( "fmt" ) const NAME string = "imooc" var a string = "慕 ...

  6. go 读取BMP文件头二进制读取

    BMP文件头定义: WORD 两个字节 16bit DWORD 四个字节 32bit package main import ( "encoding/binary" "f ...

  7. MySQL事务和事务隔离级别

    1.概述 事务就是对数据库数据进行更改(包括insert.update.delete等)操作的一个执行单元,通常有一条或多条更改语句组成.在同一个事务中的更改操作要么同时成功,要么同时失败. 事务具有 ...

  8. 并发编程之Callable异步,Future模式

    Callable 在Java中,创建线程一般有两种方式,一种是继承Thread类,一种是实现Runnable接口.然而,这两种方式的缺点是在线程任务执行结束后,无法获取执行结果.我们一般只能采用共享变 ...

  9. stack + positioned

    stack 下套container, 发现最大的显示,小的都没显示, 把所有都套个POSITIONED, 都正常显示了.

  10. 使用ngspice进行电路仿真

    电路spice仿真工具已经比较成熟,开源的免费工具也有不错的性能.使用ngspice可以得到不错的仿真结果. 在Linux系统上,例如写一个RLC谐振的电路: RLCV1 1 0 AC 1V L 1 ...