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. python3.7 pip升级或安装,拒绝访问 解决方案

  2. django RetrieveModelMixin 查询字段替换

    mixins 中RetrieveModelMixin 获取当个实例 其中的主键pk获取,可以通过lookup_field 如:要换成用username字段进行查询 注:替换的字段要有唯一约束 look ...

  3. WAMP集成环境虚拟路径修改

    只需要改httpd.conf这一个文件就好了. 1.单击右下角wamp图标如下图打开httpd.conf,或者从文件夹打开httpd.conf.

  4. Chart 文件结构

    一个 Chart 包由以下几个配置文件组成: wordpress/ Chart.yaml # Yaml文件,用于描述 Chart 的基本信息,包括名称版本等 LICENSE # [可选] 文本格式的协 ...

  5. ubuntu 18.04安装RTX 2060 显卡驱动

    第一:安装ppa的显卡驱动源 sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt update 第二:检查显卡和推荐驱动 ubuntu- ...

  6. Java身份证处理工具

    身份证处理工具 /** * <html> * <body> * <P> Copyright 1994 JsonInternational</p> * & ...

  7. C# HtmlAgilityPack爬取静态页面

    最近对爬虫很感兴趣,稍微研究了一下,利用HtmlAgilityPack制作了一个十分简单的爬虫,这个简易爬虫只能获取静态页面的Html HtmlAgilityPack简介 HtmlAgilityPac ...

  8. AppRTC服务搭建(测试)

    提供一个在线的webrtc服务器测试,需要的朋友看看.https://www.webrtcserver.cn/ 服务器搭建环境各有不同在此参考前人经验差试一下. 运行AppRTC需要使用Google ...

  9. ZK中使用JS读取客户端txt文件内容问题

    最近写一个需求时遇到一个问题,用户需要通过点击一个按钮直接读取他自己电脑上D盘的一个txt文件内容显示到页面,因为项目现在是用ZK写的.我对于ZK也是刚刚了解不就,很多都还不是很熟.起初我是想用io流 ...

  10. Jmeter学习笔记(十)——元件的作用域和执行顺序

    jmeter是一个开源的性能测试工具,它可以通过鼠标拖拽来随意改变元件之间的顺序以及元件的父子关系,那么随着它们的顺序和所在的域不同,它们在执行的时候,也会有很多不同. jmeter的test pla ...