注意:在升级的过程中不要执行 DDL 请求,否则可能会出现行为未定义的问题。
1、机器上安装 TiUP
1.1、在中控机上执行如下命令安装 TiUP:
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
1.2、重新声明全局环境变量:
source .bash_profile
cd到根目录执行
[tidb@dev29 tidb-ansible]$ cd
[tidb@dev29 ~]$ ll -a
总用量 56
drwx------. 8 tidb tidb 4096 7月 22 09:16 .
drwxr-xr-x. 6 root root 4096 7月 2 17:18 ..
drwx------. 4 tidb tidb 4096 7月 2 18:17 .ansible
-rw-------. 1 tidb tidb 2456 7月 9 18:30 .bash_history
-rw-r--r--. 1 tidb tidb 18 10月 31 2018 .bash_logout
-rw-r--r--. 1 tidb tidb 232 7月 9 18:29 .bash_profile
-rw-r--r--. 1 tidb tidb 231 10月 31 2018 .bashrc
drwxrwxr-x. 3 tidb tidb 4096 7月 6 17:47 .cache
drwxrw----. 3 tidb tidb 4096 7月 2 17:45 .pki
drwx------. 2 tidb tidb 4096 7月 10 11:18 .ssh
drwxrwxr-x. 18 tidb tidb 4096 7月 22 09:16 tidb-ansible
drwxrwxr-x. 7 tidb tidb 4096 7月 22 17:54 .tiup
-rw-------. 1 tidb tidb 7741 7月 22 09:16 .viminfo
[tidb@dev29 ~]$ source .bash_profile
1.3、确认 TiUP 工具是否安装:
which tiup
1.4、安装 TiUP 的 cluster 工具:
tiup cluster
如果之前安装过 TiUP,使用如下命令更新至最新版本即可:
tiup update cluster
2、将 TiDB Ansible 及 inventory.ini 配置导入到 TiUP
以 /home/tidb/tidb-ansible 为示例路径,使用如下命令将 TiDB Ansible 集群导入到 TiUP 中:
tiup cluster import -d /home/tidb/tidb-ansible
导入完成后,可以通过 tiup cluster display 查看当前集群状态以验证导入结果。由于 display 命令会查询各节点的实时状态,所以命令执行可能需要等待少许时间。
这个时候tidb版本还是当前版本
3、编辑 TiUP 拓扑配置文件(使用4.0默认参数可选择跳过)
注意:
以下情况可跳过该步骤:
- 原集群没有修改过配置参数。
- 升级后希望使用 4.0 默认参数。
3.1、进入 TiDB Ansible 的备份目录 ~/.tiup/storage/cluster/clusters/{cluster_name}/ansible-backup/conf/
,确认配置模板中修改过的参数
3.2、进入拓扑文件的 vi 编辑模式:
tiup cluster edit-config <cluster-name>
3.3、参考 topology 配置模板的格式,将原集群修改过的参数填到拓扑文件的 server_configs
下面。
注:没滚动升级到4.0的时候 tiup cluster edit-config中是没有 server_configs 需要手动添加
修改完成后 wq 保存并退出编辑模式,输入 Y 确认变更。
注意:
升级到 4.0 版本前,请确认 3.0 修改的参数在 4.0 版本中是兼容的,可参考配置模板。中支持的参数
4、滚动升级 TiDB 集群
4.1、最新版本可以通过执行 tiup list tidb 来查看 TiUP 支持的版本
tiup list tidb
运行后可以看到相关的版本
Available versions for tidb:
Version Installed Release Platforms
------- --------- ------- ---------
nightly 2020-06-29T05:00:12+08:00 linux/amd64,darwin/amd64
……
v4.0.0-beta.1 2020-05-26T11:42:48+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0-beta.2 2020-05-26T11:56:51+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc 2020-05-26T14:56:06+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc.1 2020-04-29T01:03:31+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0-rc.2 2020-05-15T21:54:51+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.0 2020-05-28T20:10:10+08:00 linux/amd64,linux/arm64,darwin/amd64
v4.0.1 2020-06-12T21:22:29+08:00 linux/amd64,linux/arm64,darwin/amd64
[tidb@dev29 ~]$
4.2、将集群升级到指定版本
tiup cluster upgrade <cluster-name> <version>
以升级到 v4.0.0 版本为例:
tiup cluster upgrade <cluster-name> v4.0.0
滚动升级会逐个升级所有的组件。升级 TiKV 期间,会逐个将 TiKV 上的所有 leader 切走再停止该 TiKV 实例。默认超时时间为 5 分钟,超过后会直接停止实例。
如果不希望驱逐 leader,而希望立刻升级,可以在上述命令中指定 --force,该方式会造成性能抖动,不会造成数据损失。
如果希望保持性能稳定,则需要保证 TiKV 上的所有 leader 驱逐完成后再停止该 TiKV 实例,可以指定 --transfer-timeout 为一个超大值,如 --transfer-timeout 100000000,单位为 s。
5、升级后验证
执行 display 命令来查看最新的集群版本 TiDB Version:
tiup cluster display <cluster-name>
如果报错Restarting component tiflash参考此篇文章
配置文件建议修改的参数:
执行修改参数
tiup cluster edit-config tidb-dev
添加:
server_configs:
tidb:
# 以字节为单位设置查询的内存配额。默认32G
mem-quota-query: 1073741824
oom-action: "log"
# 设置最大索引长度
max-index-length: 12288
# 最长的 SQL 输出长度。(变更)4.0需要修改
log.query-log-max-len: 6000
# 设置日志保留天数
log.file.max-days: 10
tikv:
pd:
重新加载配置文件
tiup cluster reload tidb-dev -N ip:port
或
tiup cluster reload tidb-dev -R tidb,tikv
配置参数参考:
TiDB config.toml.example
TiKV config.toml.example
PD config.toml.example
TiFlash
查看dashboard
[tidb@d ~]$ tiup cluster display test-cluster --dashboard
Starting component `cluster`: display test-cluster --dashboard
http://172.168.10.48:2379/dashboard/
[tidb@d ~]$
登录http://172.168.10.48:2379/dashboard/查看概况页面没有数据解决办法如下:
升级后,对于现有集群,可通过再次启动集群的方法汇报监控地址(将 CLUSTER_NAME 替换为实际集群名称):
tiup cluster start CLUSTER_NAME
即使集群已经启动,请仍然执行该命令。该命令不会影响集群上正常的业务,但会刷新并上报监控地址,从而能让监控在 TiDB Dashbaord 中正常显示。
tiup常用命令
使用 TiUP 部署时,对于已启动的集群,可通过 tiup cluster display 命令查看哪个 PD 节点提供了 TiDB Dashboard 服务(将 CLUSTER_NAME 替换为集群名称)
tiup cluster display CLUSTER_NAME --dashboard
pd-ctl操作:
[tidb@dev29 ~]$ tiup ctl pd -u http://172.168.10.47:2379 --help
Placement Driver control
Usage:
pd-ctl [flags]
pd-ctl [command]
Available Commands:
cluster show the cluster information
completion Output shell completion code for the specified shell (bash)
config tune pd configs
exit exit pdctl
health show all node's health information of the pd cluster
help Help about any command
hot show the hotspot status of the cluster
label show the labels
log set log level
member show the pd member status
operator operator commands
ping show the total time spend ping the pd
plugin plugin commands
region show the region status
scheduler scheduler commands
store manipulate or query stores
tso parse TSO to the system and logic time
Flags:
--cacert string path of file that contains list of trusted SSL CAs
--cert string path of file that contains X509 certificate in PEM format
-d, --detach Run pdctl without readline. (default true)
-h, --help help message
-i, --interact Run pdctl with readline.
--key string path of file that contains X509 key in PEM format
-u, --pd string address of pd (default "http://127.0.0.1:2379")
-V, --version Print version information and exit.
Use "pd-ctl [command] --help" for more information about a comman
显示 scheduler 的相关 config 信息:
tiup ctl pd -u http://192.168.180.47:2379 config show
设置权重:
设置 store id 为 1 的 store 的 leader weight 为 5,Region weight 为 10:
tiup ctl pd -u http://192.168.180.47:2379 store weight 1 5 10
查看store的region情况
tiup ctl pd -u http://xxx:xxx region store 763660