济南行业网站开发,网页制作基础教程免费,优化技术,企业管理培训免费视频课程Docker 安装 Citus 单节点集群#xff1a;全面指南与详细操作 文章目录 Docker 安装 Citus 单节点集群#xff1a;全面指南与详细操作一 服务器资源二 部署图三 安装部署1 创建网络2 运行脚本1#xff09;docker-compose.cituscd1.yml2#xff09;docker-compose.cituswk1.…Docker 安装 Citus 单节点集群全面指南与详细操作 文章目录 Docker 安装 Citus 单节点集群全面指南与详细操作一 服务器资源二 部署图三 安装部署1 创建网络2 运行脚本1docker-compose.cituscd1.yml2docker-compose.cituswk1.yml3docker-compose.cituswk2.yml4docker-compose.cituswk3.yml 四 配置访问五 节点添加六 示例创建表 本文详细介绍了如何使用 Docker 安装 Citus 单节点集群并为其配置多个工作节点与协调器。通过具体的服务器资源表、部署示意图以及 docker-compose 脚本逐步指导读者如何创建 Docker 网络、配置 PostgreSQL 的 postgresql.conf 和 pg_hba.conf并完成节点的添加与管理。此外本文还提供了完整的 SQL 命令示例帮助用户检查节点健康状况、查看节点表信息、创建分布式表和分片管理。无论是初学者还是有经验的开发者都可以通过本文轻松完成 Citus 集群的安装与配置。
一 服务器资源
域名解释服务器IP端口角色备注pg-cd1192.168.0.115434coordinatorpg-wk1192.168.0.115432workerpg-wk2192.168.0.215432workerpg-wk3192.168.0.315432worker
二 部署图 三 安装部署
1 创建网络
docker network create --driver bridge dbnet2 运行脚本
1docker-compose.cituscd1.yml
version: 3services:pg-cd-1:image: citusdata/citus:12.1.3restart: alwayscontainer_name: pg-cd-1environment:- TZAsia/Shanghai- POSTGRES_USERpostgres- POSTGRES_PASSWORD123456- PGUSERpostgres- PGPASSWORD123456working_dir: /postgresqlports:- 15434:5432networks:- dbnetextra_hosts:- pg-cd1:192.168.0.1- pg-wk1:192.168.0.1- pg-wk2:192.168.0.2- pg-wk3:192.168.0.3volumes:- ./postgresql/data:/var/lib/postgresql/data- ./postgresql/healthcheck-volume:/healthcheckhealthcheck:test: [CMD-SHELL, pg_isready -U postgres]interval: 30stimeout: 10sretries: 5
networks:dbnet:external: true2docker-compose.cituswk1.yml
version: 3services:pg-wk-1:image: citusdata/citus:12.1.3restart: alwayscontainer_name: pg-wk-1environment:- TZAsia/Shanghai- POSTGRES_USERpostgres- POSTGRES_PASSWORD123456- PGUSERpostgres- PGPASSWORD123456working_dir: /postgresqlnetworks:- dbnetextra_hosts:- pg-cd1:192.168.0.1- pg-wk1:192.168.0.1- pg-wk2:192.168.0.2- pg-wk3:192.168.0.3ports:- 15432:5432volumes:- ./postgresql/data:/var/lib/postgresql/data- ./postgresql/healthcheck-volume:/healthcheckhealthcheck:test: [CMD-SHELL, pg_isready -U postgres]interval: 30stimeout: 10sretries: 5
networks:dbnet:external: true3docker-compose.cituswk2.yml
version: 3services:pg-wk-2:image: citusdata/citus:12.1.3restart: alwayscontainer_name: pg-wk-2environment:- TZAsia/Shanghai- POSTGRES_USERpostgres- POSTGRES_PASSWORD123456- PGUSERpostgres- PGPASSWORD123456working_dir: /postgresqlnetworks:- dbnetextra_hosts:- pg-cd1:192.168.0.1- pg-wk1:192.168.0.1- pg-wk2:192.168.0.2- pg-wk3:192.168.0.3ports:- 15432:5432volumes:- ./postgresql/data:/var/lib/postgresql/data- ./postgresql/healthcheck-volume:/healthcheckhealthcheck:test: [CMD-SHELL, pg_isready -U postgres]interval: 30stimeout: 10sretries: 5
networks:dbnet:external: true4docker-compose.cituswk3.yml
version: 3services:pg-wk-3:image: citusdata/citus:12.1.3restart: alwayscontainer_name: pg-wk-3environment:- TZAsia/Shanghai- POSTGRES_USERpostgres- POSTGRES_PASSWORD123456- PGUSERpostgres- PGPASSWORD123456working_dir: /postgresqlnetworks:- dbnetextra_hosts:- pg-cd1:192.168.0.1- pg-wk1:192.168.0.1- pg-wk2:192.168.0.2- pg-wk3:192.168.0.3ports:- 15432:5432volumes:- ./postgresql/data:/var/lib/postgresql/data- ./postgresql/healthcheck-volume:/healthcheckhealthcheck:test: [CMD-SHELL, pg_isready -U postgres]interval: 30stimeout: 10sretries: 5
networks:dbnet:external: true四 配置访问
1 修改 postgresql.conf 配置。
# Uncomment listen_addresses for the changes to take effect
listen_addresses *2 配置postgres客户端访问修改 pg_hba.conf 。
# 每个节点都得配置重启的时候有互相通信。
host all all 192.168.0.1/32 trust
host all all 192.168.0.3/32 trust
host all all 192.168.0.2/32 trust五 节点添加
# 查看扩展
select * from pg_available_extensions;# 设置协调节点
SELECT citus_set_coordinator_host(pg-cd1, 15434);# 设置工作节点
SELECT citus_add_node(pg-wk1, 15432);
SELECT citus_add_node(pg-wk2, 15432);
SELECT citus_add_node(pg-wk3, 15432);# citus_get_active_worker_nodes() 函数返回活动工作线程主机名和端口号的列表。
SELECT * from citus_get_active_worker_nodes();# 检查所有节点之间的连通性
SELECT * FROM citus_check_cluster_node_health();# 集群中工作节点的信息
select * from pg_dist_node# 查看集群表信息
select * from citus_tables;# citus_total_relation_size 获取指定分布式表的所有分片使用的总磁盘空间
SELECT pg_size_pretty(citus_total_relation_size(devices));# 查看表节点分布
SELECTdp.logicalrelid::regclass AS table_name,n.nodename,n.nodeport,pg_size_pretty(pg_total_relation_size(p.placementid::regclass)) AS shard_size
FROMpg_dist_partition dp
JOINpg_dist_shard s ON dp.logicalrelid s.logicalrelid
JOINpg_dist_placement p ON s.shardid p.shardid
JOINpg_dist_node n ON p.groupid n.groupid
WHEREn.noderole primary
ORDER BYdp.logicalrelid,n.nodename;# 查看分片信息
select * from citus_shards
六 示例创建表
创建分布式表
CREATE TABLE events (id bigserial NOT NULL,device_id bigint,event_id bigserial,event_time timestamptz default now(),data jsonb not null,primary key (id)
);CREATE INDEX idx_dev_eve ON events (device_id, event_id);-- distribute the events table across shards placed locally or on the worker nodes
SELECT create_distributed_table(events, id, hash);INSERT INTO events (device_id, data)
SELECT s % 100, ({measurement:||random()||})::jsonb FROM generate_series(1,10000) s;CREATE TABLE devices (device_id bigint primary key,device_name text,device_type_id int
);
CREATE INDEX ON devices (device_type_id);-- co-locate the devices table with the events table
SELECT create_distributed_table(devices, device_id, colocate_with : events);-- insert device metadata
INSERT INTO devices (device_id, device_name, device_type_id)
SELECT s, device-||s, 55 FROM generate_series(0, 99) s;
文章转载自: http://www.morning.nrydm.cn.gov.cn.nrydm.cn http://www.morning.ttcmdsg.cn.gov.cn.ttcmdsg.cn http://www.morning.xjpnq.cn.gov.cn.xjpnq.cn http://www.morning.cklld.cn.gov.cn.cklld.cn http://www.morning.kncrc.cn.gov.cn.kncrc.cn http://www.morning.mtrrf.cn.gov.cn.mtrrf.cn http://www.morning.xqxrm.cn.gov.cn.xqxrm.cn http://www.morning.rhkmn.cn.gov.cn.rhkmn.cn http://www.morning.bprsd.cn.gov.cn.bprsd.cn http://www.morning.pamdeer.com.gov.cn.pamdeer.com http://www.morning.junyaod.com.gov.cn.junyaod.com http://www.morning.weitao0415.cn.gov.cn.weitao0415.cn http://www.morning.ffhlh.cn.gov.cn.ffhlh.cn http://www.morning.lqljj.cn.gov.cn.lqljj.cn http://www.morning.rnnwd.cn.gov.cn.rnnwd.cn http://www.morning.nbrkt.cn.gov.cn.nbrkt.cn http://www.morning.rkmsm.cn.gov.cn.rkmsm.cn http://www.morning.pngfx.cn.gov.cn.pngfx.cn http://www.morning.jfcbs.cn.gov.cn.jfcbs.cn http://www.morning.lxhny.cn.gov.cn.lxhny.cn http://www.morning.dwzwm.cn.gov.cn.dwzwm.cn http://www.morning.ykxnp.cn.gov.cn.ykxnp.cn http://www.morning.mmjyk.cn.gov.cn.mmjyk.cn http://www.morning.llmhq.cn.gov.cn.llmhq.cn http://www.morning.sgrwd.cn.gov.cn.sgrwd.cn http://www.morning.ksqzd.cn.gov.cn.ksqzd.cn http://www.morning.plxhq.cn.gov.cn.plxhq.cn http://www.morning.bmnm.cn.gov.cn.bmnm.cn http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn http://www.morning.lqypx.cn.gov.cn.lqypx.cn http://www.morning.qfrmy.cn.gov.cn.qfrmy.cn http://www.morning.wtcyz.cn.gov.cn.wtcyz.cn http://www.morning.fgxws.cn.gov.cn.fgxws.cn http://www.morning.lxngn.cn.gov.cn.lxngn.cn http://www.morning.mbdbe.cn.gov.cn.mbdbe.cn http://www.morning.rdwm.cn.gov.cn.rdwm.cn http://www.morning.jrqbr.cn.gov.cn.jrqbr.cn http://www.morning.fwdln.cn.gov.cn.fwdln.cn http://www.morning.mcjxq.cn.gov.cn.mcjxq.cn http://www.morning.hmjasw.com.gov.cn.hmjasw.com http://www.morning.zlnkq.cn.gov.cn.zlnkq.cn http://www.morning.snmsq.cn.gov.cn.snmsq.cn http://www.morning.yrfxb.cn.gov.cn.yrfxb.cn http://www.morning.pwrkl.cn.gov.cn.pwrkl.cn http://www.morning.rnds.cn.gov.cn.rnds.cn http://www.morning.lsxabc.com.gov.cn.lsxabc.com http://www.morning.hnrpk.cn.gov.cn.hnrpk.cn http://www.morning.ryglh.cn.gov.cn.ryglh.cn http://www.morning.gcthj.cn.gov.cn.gcthj.cn http://www.morning.grynb.cn.gov.cn.grynb.cn http://www.morning.qphdp.cn.gov.cn.qphdp.cn http://www.morning.hqqpy.cn.gov.cn.hqqpy.cn http://www.morning.ndngj.cn.gov.cn.ndngj.cn http://www.morning.zfhwm.cn.gov.cn.zfhwm.cn http://www.morning.llyqm.cn.gov.cn.llyqm.cn http://www.morning.qpzjh.cn.gov.cn.qpzjh.cn http://www.morning.ppghc.cn.gov.cn.ppghc.cn http://www.morning.snmsq.cn.gov.cn.snmsq.cn http://www.morning.qlkzl.cn.gov.cn.qlkzl.cn http://www.morning.hrkth.cn.gov.cn.hrkth.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.rkdnm.cn.gov.cn.rkdnm.cn http://www.morning.pnntx.cn.gov.cn.pnntx.cn http://www.morning.qxljc.cn.gov.cn.qxljc.cn http://www.morning.htmhl.cn.gov.cn.htmhl.cn http://www.morning.rttxx.cn.gov.cn.rttxx.cn http://www.morning.clfct.cn.gov.cn.clfct.cn http://www.morning.huarma.com.gov.cn.huarma.com http://www.morning.kjfqf.cn.gov.cn.kjfqf.cn http://www.morning.srnth.cn.gov.cn.srnth.cn http://www.morning.fkgcd.cn.gov.cn.fkgcd.cn http://www.morning.pmxw.cn.gov.cn.pmxw.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.xqxlb.cn.gov.cn.xqxlb.cn http://www.morning.zfhzx.cn.gov.cn.zfhzx.cn http://www.morning.jjwzk.cn.gov.cn.jjwzk.cn http://www.morning.pbgnx.cn.gov.cn.pbgnx.cn http://www.morning.zrpys.cn.gov.cn.zrpys.cn http://www.morning.juju8.cn.gov.cn.juju8.cn http://www.morning.zkqwk.cn.gov.cn.zkqwk.cn