|
@@ -0,0 +1,78 @@
|
|
|
+# citus实战系列之一
|
|
|
+citus是一款基于PostgreSQL的开源分布式数据库,自动继承了PostgreSQL强大的SQL支持能力和应用生态。安装了citus之后
|
|
|
+postgresql就不必再安装了,因为会集成进来
|
|
|
+
|
|
|
+## docker下载citus镜像
|
|
|
+```
|
|
|
+docker pull citusdata/citus
|
|
|
+```
|
|
|
+
|
|
|
+## docker运行citus
|
|
|
+
|
|
|
+```
|
|
|
+//运行容器并指定密码
|
|
|
+docker run --name citus_standalone1 -e POSTGRES_PASSWORD=123456 -p 5433:5432 citusdata/citus
|
|
|
+```
|
|
|
+
|
|
|
+## 启动citus集群便捷方法
|
|
|
+
|
|
|
+docker-compose.yml文件提供了一种启动Citus集群的简便方法,该集群由多个工作程序组成。只需将其复制到当前目录并运行
|
|
|
+```
|
|
|
+docker-compose -p citus up
|
|
|
+```
|
|
|
+
|
|
|
+示例docker-compose文件,可根据需要进行修改
|
|
|
+```yaml
|
|
|
+version: '3'
|
|
|
+
|
|
|
+services:
|
|
|
+ master:
|
|
|
+ container_name: "${COMPOSE_PROJECT_NAME:-citus}_master"
|
|
|
+ image: 'citusdata/citus:9.5.1'
|
|
|
+ ports: ["${MASTER_EXTERNAL_PORT:-5432}:5432"]
|
|
|
+ labels: ['com.citusdata.role=Master']
|
|
|
+ environment: &AUTH
|
|
|
+ POSTGRES_USER: "${POSTGRES_USER:-postgres}"
|
|
|
+ POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
|
|
|
+ PGUSER: "${POSTGRES_USER:-postgres}"
|
|
|
+ PGPASSWORD: "${POSTGRES_PASSWORD}"
|
|
|
+ POSTGRES_HOST_AUTH_METHOD: "${POSTGRES_HOST_AUTH_METHOD:-trust}"
|
|
|
+ worker:
|
|
|
+ image: 'citusdata/citus:9.5.1'
|
|
|
+ labels: ['com.citusdata.role=Worker']
|
|
|
+ depends_on: [ manager ]
|
|
|
+ environment: *AUTH
|
|
|
+ command: "/wait-for-manager.sh"
|
|
|
+ volumes:
|
|
|
+ - healthcheck-volume:/healthcheck
|
|
|
+ manager:
|
|
|
+ container_name: "${COMPOSE_PROJECT_NAME:-citus}_manager"
|
|
|
+ image: 'citusdata/membership-manager:0.3.0'
|
|
|
+ volumes:
|
|
|
+ - "${DOCKER_SOCK:-/var/run/docker.sock}:/var/run/docker.sock"
|
|
|
+ - healthcheck-volume:/healthcheck
|
|
|
+ depends_on: [ master ]
|
|
|
+ environment: *AUTH
|
|
|
+volumes:
|
|
|
+ healthcheck-volume:
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+#citus实战系列之二
|
|
|
+citus的安装非常简单,但要实际用到生产上还需要下一番功夫。比如如何扩容
|
|
|
+citus为主从结构,分为cn节点和worker节点
|
|
|
+cn节点只存储分片信息,不存储元数据,而worker节点存储元数据
|
|
|
+
|
|
|
+常用命令
|
|
|
+```sql
|
|
|
+SELECT * FROM master_get_active_worker_nodes(); //查看所有节点
|
|
|
+
|
|
|
+select * from master_add_node('ip-or-name', port); //添加worker节点
|
|
|
+
|
|
|
+SELECT create_distributed_table('table', 'field'); //根据字段分片
|
|
|
+
|
|
|
+SELECT * from pg_dist_shard_placement order by shardid, placementid; //查询分片
|
|
|
+```
|
|
|
+
|
|
|
+
|
|
|
+
|