TiKV部署;结合dcoker-ce 部署单主机 TiKV 集群
本博客来源自个人毕业设计的开发过程中,需要使用TiKV做为K-V store进行持久化存储数据,为方便开发故部署单节点集群,方便调试:
本部署方案,修改自TiKV官方文档中3节点部署方案,利用docker 用户自定义网络实现单机部署。部署并验证后,显示部署方案可行;
关于docker如何安装和使用,请参考:
TiKV整体架构:https://tikv.org/docs/4.0/concepts/architecture/
单主机3节点TiKV部署方案:
名称 |
节点IP |
服务 |
数据路径 |
节点1 |
172.18.0.11 |
PD1 |
/mnt/tikv/pd1 |
节点2 |
172.18.0.12 |
PD2 |
/mnt/tikv/pd2 |
节点3 |
172.18.0.13 |
PD3 |
/mnt/tikv/pd3 |
节点4 |
172.18.0.14 |
TiKV1 |
/mnt/tikv/tikv1 |
节点5 |
172.18.0.15 |
TiKV2 |
/mnt/tikv/tikv2 |
节点6 |
172.18.0.16 |
TiKV3 |
/mnt/tikv/tikv3 |
环境初始化命令:
mkdir -p /mnt/tikv/pd1 mkdir -p /mnt/tikv/pd2 mkdir -p /mnt/tikv/pd3 mkdir -p /mnt/tikv/tikv1 mkdir -p /mnt/tikv/tikv2 mkdir -p /mnt/tikv/tikv3 docker network create --subnet=172.18.0.0/16 yx-network # 创建自定义网络
# 拉取镜像docker pull pingcap/tikv:latest docker pull pingcap/pd:latest
节点启动脚本:
PD1:
docker run -d --name pd1 \ -p 12379:2379 \ -p 12380:2380 \ -v /etc/localtime:/etc/localtime:ro \ -v /mnt/tikv/pd1:/data \ --network yx-network \ --ip 172.18.0.11 \ pingcap/pd:latest \ --name="pd1" \ --data-dir="/data/pd1" \ --client-urls="http://0.0.0.0:2379" \ --advertise-client-urls="http://172.18.0.11:2379" \ --peer-urls="http://0.0.0.0:2380" \ --advertise-peer-urls="http://172.18.0.11:2380" \ --initial-cluster="pd1=http://172.18.0.11:2380,pd2=http://172.18.0.12:2380,pd3=http://172.18.0.13:2380"
PD2:
docker run -d --name pd2 \ -p 22379:2379 \ -p 22380:2380 \ -v /etc/localtime:/etc/localtime:ro \ -v /mnt/tikv/pd2:/data \ --network yx-network \ --ip 172.18.0.12 \ pingcap/pd:latest \ --name="pd2" \ --data-dir="/data/pd2" \ --client-urls="http://0.0.0.0:2379" \ --advertise-client-urls="http://172.18.0.12:2379" \ --peer-urls="http://0.0.0.0:2380" \ --advertise-peer-urls="http://172.18.0.12:2380" \ --initial-cluster="pd1=http://172.18.0.11:2380,pd2=http://172.18.0.12:2380,pd3=http://172.18.0.13:2380"
PD3:
docker run -d --name pd3 \ -p 32379:2379 \ -p 32380:2380 \ -v /etc/localtime:/etc/localtime:ro \ -v /mnt/tikv/pd3:/data \ --network yx-network \ --ip 172.18.0.13 \ pingcap/pd:latest \ --name="pd3" \ --data-dir="/data/pd3" \ --client-urls="http://0.0.0.0:2379" \ --advertise-client-urls="http://172.18.0.13:2379" \ --peer-urls="http://0.0.0.0:2380" \ --advertise-peer-urls="http://172.18.0.13:2380" \ --initial-cluster="pd1=http://172.18.0.11:2380,pd2=http://172.18.0.12:2380,pd3=http://172.18.0.13:2380"
TiKV1:
docker run -d --name tikv1 \ -p 40160:20160 \ -v /etc/localtime:/etc/localtime:ro \ -v /mnt/tikv/tikv1:/data \ --network yx-network \ --ip 172.18.0.14 \ pingcap/tikv:latest \ --addr="0.0.0.0:20160" \ --advertise-addr="172.18.0.14:20160" \ --data-dir="/data/tikv1" \ --pd="172.18.0.11:2379,172.18.0.12:2379,172.18.0.13:2379"
TiKV2:
docker run -d --name tikv2 \ -p 50160:20160 \ -v /etc/localtime:/etc/localtime:ro \ -v /mnt/tikv/tikv2:/data \ --network yx-network \ --ip 172.18.0.15 \ pingcap/tikv:latest \ --addr="0.0.0.0:20160" \ --advertise-addr="172.18.0.15:20160" \ --data-dir="/data/tikv2" \ --pd="172.18.0.11:2379,172.18.0.12:2379,172.18.0.13:2379"
TiKV3:
docker run -d --name tikv3 \ -p 60160:20160 \ -v /etc/localtime:/etc/localtime:ro \ -v /mnt/tikv/tikv3:/data \ --network yx-network \ --ip 172.18.0.16 \ pingcap/tikv:latest \ --addr="0.0.0.0:20160" \ --advertise-addr="172.18.0.16:20160" \ --data-dir="/data/tikv3" \ --pd="172.18.0.11:2379,172.18.0.12:2379,172.18.0.13:2379"
集群验证:
curl 172.18.0.11:2379/pd/api/v1/stores # 验证集群,所有返回Up即成功!
保持更新,转载请注明出处,更多内容请关注cnblogs.com/xuyaowen;
访问dashboard:http://172.18.0.11:2379/dashboard
参考文档:https://github.com/yaowenxu/Workplace/tree/master/understand-TiKV