TiUP部署TiDB

一、环境准备

服务器4台
系统:CentOS 7
用户:root

4节点:
hostname@ip    部署组件
tidb1@192.168.8.31  monitoring,grafana,alertmanager
tidb2@192.168.8.32  PD,TiKV,TiDB
tidb3@192.168.8.33  PD,TiKV,TiDB
tidb4@192.168.8.34  PD,TiKV,TiDB

所有节点完成以下操作

1.设置时间同步

yum install -y ntpdate
ntpdate -u ntp1.aliyun.com

2.加大文件描述

cat << EOF >>/etc/security/limits.conf
tidb           soft    nofile          1000000
tidb           hard    nofile          1000000
tidb           soft    stack           32768
tidb           hard    stack           32768
EOF

3.安装numactl工具

yum -y install numactl

4.检测及关闭系统 swap

TiDB 运行需要有足够的内存。如果内存不足,不建议使用 swap 作为内存不足的缓冲,因为这会降低性能。建议永久关闭系统 swap。

要永久关闭 swap,可执行以如下命令

echo "vm.swappiness = 0">> /etc/sysctl.conf
swapoff -a && swapon -a
sysctl -p

5.执行以下命令修改 sysctl 参数

echo "fs.file-max = 1000000">> /etc/sysctl.conf
echo "net.core.somaxconn = 32768">> /etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle = 0">> /etc/sysctl.conf
echo "net.ipv4.tcp_syncookies = 0">> /etc/sysctl.conf
echo "vm.overcommit_memory = 1">> /etc/sysctl.conf
sysctl -p

6.配置SSH免密(可选配置,可通过添加参数手动输入密码完成部署)

使用 TiUP 部署工具会自动配置 SSH 互信及免密登录,可忽略本段内容。

参考:https://www.cnblogs.com/litchi/p/16802840.html

二、部署

1.在线部署

tidb1   192.168.8.31    中控机

中控机配置TiUP

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

重新声明全局环境变量

source .bash_profile

确认 TiUP 工具是否安装

which tiup

安装 TiUP cluster 组件

tiup cluster

如果已经安装,则更新 TiUP cluster 组件至最新版本

tiup update --self && tiup update cluster

验证当前 TiUP cluster 版本信息。执行如下命令查看 TiUP cluster 组件版本

tiup --binary cluster

2.离线部署

 

三、初始化集群拓扑文件

1.生成集群初始化配置文件

tiup cluster template > topology.yaml

2.编辑 topology.yaml,查看并配置文件的内容

global:
  user: "tidb"
  ssh_port: 22
  deploy_dir: "/tidb-deploy"
  data_dir: "/tidb-data"
server_configs: {}
pd_servers:
  - host: 192.168.8.32
  - host: 192.168.8.33
  - host: 192.168.8.34
tidb_servers:
  - host: 192.168.8.32
  - host: 192.168.8.33
  - host: 192.168.8.34
tikv_servers:
  - host: 192.168.8.32
  - host: 192.168.8.33
  - host: 192.168.8.34
monitoring_servers:
  - host: 192.168.8.31
grafana_servers:
  - host: 192.168.8.31
alertmanager_servers:
  - host: 192.168.8.31

四、执行部署命令

通过 TiUP 进行集群部署可以使用密钥或者交互密码方式来进行安全认证:
如果是密钥方式,可以通过 -i 或者 --identity_file 来指定密钥的路径。
如果是密码方式,可以通过 -p 进入密码交互窗口。
如果已经配置免密登录目标机,则不需填写认证。
一般情况下 TiUP 会在目标机器上创建 topology.yaml 中约定的用户和组,以下情况例外:
topology.yaml 中设置的用户名在目标机器上已存在。
在命令行上使用了参数 --skip-create-user 明确指定跳过创建用户的步骤

1.检查集群存在的潜在风险

tiup cluster check ./topology.yaml --user root -p

2.自动修复集群存在的潜在风险

tiup cluster check ./topology.yaml --apply --user root -p

3.部署 TiDB 集群

tiup cluster deploy tidb-test v6.1.1 ./topology.yaml --user root -p

4.查看 TiUP 管理的集群情况

tiup cluster list

TiUP 支持管理多个 TiDB 集群,该命令会输出当前通过 TiUP cluster 管理的所有集群信息,包括集群名称、部署用户、版本、密钥信息等。

5.检查部署的 TiDB 集群情况
例如,执行如下命令检查 tidb-test 集群情况

tiup cluster display tidb-test

预期输出包括 tidb-test 集群中实例 ID、角色、主机、监听端口和状态(由于还未启动,所以状态为 Down/inactive)、目录信息。

五、启动集群

1.普通启动

tiup cluster start tidb-test

预期结果输出 Started cluster `tidb-test` successfully,表示启动成功。使用普通启动方式后,可通过无密码的 root 用户登录数据库。

2.验证集群运行状态

tiup cluster display tidb-test

预期结果输出:各节点 Status 状态信息为 Up 说明集群状态正常。

六、测试

1. 通过 MySQL客户端连接或者通过Navicat软件连接TiDB

yum install -y mariadb.x86_64 mariadb-libs.x86_64
mysql -h 127.0.0.1 --P4000 -u root

2.通过 http://192.168.8.32:2379/dashboard 访问 TiDB Dashboard 页面,默认用户名为 root,密码为空

3.通过 http://192.168.8.31:9090 访问 TiDB 的 Prometheus 管理界面

4.通过 http://192.168.8.31:3000 访问 TiDB 的 Grafana 界面,默认用户名和密码都为 admin 或从新设置密码

 

官网文档:https://docs.pingcap.com/zh/tidb/stable/production-deployment-using-tiup
       https://docs.pingcap.com/zh/tidb/stable/check-before-deployment

posted @ 2022-10-18 17:42  荔枝的汁  阅读(289)  评论(0编辑  收藏  举报