TiDB 在单机上模拟部署生产环境集群
参考地址:https://docs.pingcap.com/zh/tidb/dev/quick-start-with-tidb
前提条件
硬件要求
开始部署 TiDB 集群前,准备一台部署主机,确保其软件满足需求:
推荐安装 CentOS 7.3 及以上版本
运行环境可以支持互联网访问,用于下载 TiDB 及相关软件安装包
部署主机软件和环境要求如下:
部署需要使用部署主机的 root 用户及密码
部署主机关闭防火墙或者开放 TiDB 集群的节点间所需端口
目前 TiUP Cluster 支持在 x86_64(AMD64)和 ARM 架构上部署 TiDB 集群
在 AMD64 架构下,建议使用 CentOS 7.3 及以上版本 Linux 操作系统
在 ARM 架构下,建议使用 CentOS 7.6 1810 版本 Linux 操作系统
sudo 免密码
sudo vim /etc/sudoers
%sudo ALL=(ALL:ALL) ALL
修改为
%sudo ALL=(ALL:ALL) NOPASSWD:ALL
实施部署
这里使用 docker 安装一个 ubuntu 系统作为部署机:
docker run -itd --name ubuntu-test ubuntu
apt update
apt install vim curl
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
source /root/.profile
编写 topo.yaml
文件看最下面
部署:tiup cluster deploy
启动:tiup cluster start
tiup cluster deploy tidb-test 7.5.0 ./topo.yaml --user cl -p
tiup cluster start tidb-test --init
监控
访问 TiDB 的 Grafana 监控:
通过 http://{grafana-ip}:3000 访问集群 Grafana 监控页面,默认用户名和密码均为 admin。
访问 TiDB 的 Dashboard:
通过 http://{pd-ip}:2379/dashboard 访问集群 TiDB Dashboard 监控页面,默认用户名为 root,密码为空。
# # Global variables are applied to all deployments and used as the default value of
# # the deployments if a specific deployment value is missing.
global:
user: "tidb"
ssh_port: 22
deploy_dir: "/tidb-deploy"
data_dir: "/tidb-data"
# # Monitored variables are applied to all the machines.
monitored:
node_exporter_port: 9100
blackbox_exporter_port: 9115
server_configs:
tidb:
instance.tidb_slow_log_threshold: 300
tikv:
readpool.storage.use-unified-pool: false
readpool.coprocessor.use-unified-pool: true
pd:
replication.enable-placement-rules: true
replication.location-labels: ["host"]
tiflash:
logger.level: "info"
pd_servers:
- host: 192.168.2.33
tidb_servers:
- host: 192.168.2.33
tikv_servers:
- host: 192.168.2.33
port: 20160
status_port: 20180
config:
server.labels: { host: "logic-host-1" }
- host: 192.168.2.33
port: 20161
status_port: 20181
config:
server.labels: { host: "logic-host-2" }
- host: 192.168.2.33
port: 20162
status_port: 20182
config:
server.labels: { host: "logic-host-3" }
tiflash_servers:
- host: 192.168.2.33
monitoring_servers:
- host: 192.168.2.33
grafana_servers:
- host: 192.168.2.33