TiDB 应急运维脚本,更加方便的管理TiDB集群

TiDB 应急运维脚本,更加方便的管理TiDB集群

使用方法

使用方法:[tidb@localhost ~]$ which tiup
~/.tiup/bin/tiup编辑脚本,MYSQL_PASSWD 和 PORT 根据实际替换 
[tidb@localhost ~]$ vi ~/.tiup/bin/ti#version 1.1
#@author guanguanglei
##########################################################
#date 2023/06/14 version 1.0#!/bin/shMYSQL_USER=root
MYSQL_PASSWD=root 
PORT=4000          
TIDB_HOST=127.0.0.1
TIDB_CONNSTR="mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h$TIDB_HOST -P$PORT"
CLUSTER_NAME=gsc-quotation
case $1 in si)${TIDB_CONNSTR};;info)${TIDB_CONNSTR} -e "select * from information_schema.CLUSTER_INFO;";;user)${TIDB_CONNSTR} -e "select user,host from mysql.user;";;tidb)tiup cluster display  $CLUSTER_NAME;;edit)tiup cluster edit-config  $CLUSTER_NAME;;var)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "show variables like '%$2%';"else echo "please input second paramter with variable name"fi;;config)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "show config where name  like '%$2%';"elseecho "please input config "fi;;list)${TIDB_CONNSTR} -e "select * from information_schema.cluster_processlist;";;listt)${TIDB_CONNSTR} -e "select * from information_schema.cluster_processlist order by time desc ;";;active)${TIDB_CONNSTR} -e "select * from information_schema.cluster_processlist where info is not null order by time desc \G;";;kill)${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e '  ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance;";;kstat)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e '  ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance where state='$2';"else echo "please input second paramter with session state"fi;;ksql)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e '  ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance where digest='$2';"elseecho "please input second paramter with sql digest"fi;;kid)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e '  ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance  where id='$2';"elseecho "please input second paramter with connect id"fi;;klike)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e "select concat(concat('mysql -u$MYSQL_USER -p$MYSQL_PASSWD -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e '  ),concat('\"kill tidb ',b.id,';\"')) from information_schema.CLUSTER_info a join information_schema.cluster_processlist b on a.STATUS_ADDRESS=b.instance  where info like '%$2%';"elseecho "please input info like "fi;;plan)if [ "$2"x != x ]; then${TIDB_CONNSTR} -e  "select SUMMARY_BEGIN_TIME,SUMMARY_END_TIME,STMT_TYPE,SCHEMA_NAME,DIGEST,DIGEST_TEXT,TABLE_NAMES,INDEX_NAMES,QUERY_SAMPLE_TEXT,PLAN_DIGEST,PLAN from information_schema.statements_summary where digest='$2'\G;"elseecho "please input second paramter with sql digest"fi;;size)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e  "SELECT TABLE_NAME,(DATA_LENGTH+INDEX_LENGTH)/1024/1024 mb,TABLE_ROWS FROM information_schema.TABLES WHERE TABLE_SCHEMA='$2' AND TABLE_NAME='$3';"elseecho "please input second paramter with table owner and table_name"fi;;index)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e  "show indexes from $2.$3;"elseecho "please input second paramter table_owner table_name"fi;;  stats_meta)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e  "show stats_meta where db_name='$2' table_name='$3';"elseecho "please input second paramter table_owner table_name"fi;; stats_histograms)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e  "show stats_histograms where  db_name='$2' and db_name='$3';"elseecho "please input second paramter table_owner table_name"fi;;dump)if [ "$2"x != x ] && [ "$3"x != x ]; then${TIDB_CONNSTR} -e  "select concat(' tiup dumpling -uroot -p   -h --filetype csv -t 8 -o /tmp/backup -f   ', '''', table_schema,'.',table_name,'''' ' --sql ''select * from ',table_name,'''') from tables where  table_schema='$2' and table_name='$3';"elseecho "please input second paramter table_owner table_name"fi;;ctl)${TIDB_CONNSTR} -e  "select concat('tiup ctl:',(select substring(version(),13,19)),'  pd  -u  http://',  (select INSTANCE from information_schema.cluster_info where TYPE='pd' limit 1),'  -i') from dual;
";;*)echoecho "Usage: mib keyword [value1] ";echo echo "  -----------------------------------------------------------------";echo "  si                          -- login tidb database";echo "  info                        -- show cluster info";echo "  tidb                        -- tiup cluster display";echo "  edit                        -- show cluster edit";echo "  user                        -- list all user";echo "  var                         -- show variables like ";echo "  config                      -- show config where name like ";echo "  list                        -- show  processlist";echo "  listt                       -- processlist order by time";  echo "  active                       -- processlist order by time limit 10";echo "  kill                        -- kill all session ";echo "  kstat                       -- kill session state";echo "  ksql                        -- kill sql session;";    echo "  kid                         -- kill session id";  echo "  klike                       -- kill info like "; echo "  plan                        -- list sql plan";  echo "  size                        -- get table size ";echo "  index                       -- get  on table index";echo "  stats_meta                  -- getstats_meta on table";echo "  stats_histograms            -- get cloumn statistics on table";echo "  ctl                         -- print tiup ctl command";    
;;
esac

修改权限

[tidb@localhost ~]$ chmod 775 ~/.tiup/bin/ti

使用示例


1. 查看集群状态
ti  tidb 2. 登录数据库
[tidb@localhost ~]$ ti si
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 820992
Server version: 5.7.25-TiDB-v4.0.13-1-g7eeeda700 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatibleCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MySQL [(none)]> 3.查看活跃会话
[tidb@localhost ~]$ ti active 
*************************** 1. row ***************************
INSTANCE: xxxxxxxx :10080ID: 820997USER: rootHOST: 127.0.0.1DB: NULLCOMMAND: QueryTIME: 0STATE: 2INFO: select * from information_schema.cluster_processlist where info is not null order by time descDIGEST: 6140c4093c70debc9c729807414f36c32fad049daecf2d5655afd10a2374fae9MEM: 6
TxnStart: 08-10 15:22:29.866(443456461174472707)4. 登录pd 
[root@vm10-2-103-65 ~]# ti ctl
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| concat('tiup ctl:',(select substring(version(),13,19)),'  pd  -u  http://',  (select INSTANCE from information_schema.cluster_info where TYPE='pd' limit 1),'  -i') |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tiup ctl:v7.1.0  pd  -u  http://10.2.103.65:2379  -i                                                                                                                |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@vm10-2-103-65 ~]# tiup ctl:v7.1.0  pd  -u  http://10.2.103.65:2379  -i 
Starting component `ctl`: /root/.tiup/components/ctl/v7.1.0/ctl pd -u http://10.2.103.65:2379 -i
»  5. 查看参数
[root@vm10-2-103-65 ~]# ti var oom
+--------------------------------+--------+
| Variable_name                  | Value  |
+--------------------------------+--------+
| tidb_enable_tmp_storage_on_oom | ON     |
| tidb_mem_oom_action            | CANCEL |
+--------------------------------+--------+查看config参数 
root@vm10-2-103-65 ~]# ti config block-cache
+------+--------------------+-------------------------------------------+----------+
| Type | Instance           | Name                                      | Value    |
+------+--------------------+-------------------------------------------+----------+
| tikv | 10.2.103.199:20160 | raftdb.defaultcf.block-cache-size         | 317MiB   |
| tikv | 10.2.103.199:20160 | raftdb.defaultcf.disable-block-cache      | false    |
| tikv | 10.2.103.199:20160 | raftdb.defaultcf.prepopulate-block-cache  | disabled |
| tikv | 10.2.103.199:20160 | rocksdb.defaultcf.block-cache-size        | 3971MiB  |
| tikv | 10.2.103.199:20160 | rocksdb.defaultcf.disable-block-cache     | false    |
| tikv | 10.2.103.199:20160 | rocksdb.defaultcf.prepopulate-block-cache | disabled |6.查看执行计划
[root@vm10-2-103-65 ~]# ti plan 76069b6abc74fc855272108f656d4d1132948a55a3b12f66eaa4373648380d81
*************************** 1. row ***************************
SUMMARY_BEGIN_TIME: 2023-08-10 15:30:00SUMMARY_END_TIME: 2023-08-10 16:00:00STMT_TYPE: SelectSCHEMA_NAME: NULLDIGEST: 76069b6abc74fc855272108f656d4d1132948a55a3b12f66eaa4373648380d81DIGEST_TEXT: select * from `information_schema` . `cluster_processlist` where `info` is not ? order by time descTABLE_NAMES: information_schema.cluster_processlistINDEX_NAMES: NULLQUERY_SAMPLE_TEXT: select * from information_schema.cluster_processlist where info is not null order by time descPLAN_DIGEST: deabf06ff5a37585b637b6bc4ddf0bb2affc0aa92148953d10f678359c7cda69PLAN:     id                      task            estRows operator info                                                   actRows execution info                                                                                                                                                                      memory          diskSort_5                  root            9990    information_schema.cluster_processlist.time:desc                1       time:41.9ms, loops:2                                                                                                                                                                7.70 KB         0 Bytes└─TableReader_10        root            9990    data:Selection_9                                                1       time:41.9ms, loops:2, cop_task: {num: 2, max: 41.8ms, min: 41.5ms, avg: 41.6ms, p95: 41.8ms, rpc_num: 2, rpc_time: 83.2ms, copr_cache_hit_ratio: 0.00, max_distsql_concurrency: 2}  727 Bytes       N/A└─Selection_9         cop[tidb]       9990    not(isnull(information_schema.cluster_processlist.info))        0                                                                                                                                                                                           N/A             N/A└─TableFullScan_8   cop[tidb]       10000   table:CLUSTER_PROCESSLIST, keep order:false, stats:pseudo       0                                                                                                                                                                                           N/A             N/A7. kill 会话 
[root@vm10-2-103-65 ~]# ti kid 716063544658887111
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| concat(concat('mysql -uroot -pM4Ab_d03%pQ27^1Xa# -h ',substring_index(a.INSTANCE,':',1), ' -P',substring_index(a.INSTANCE,':',-1) ,' -e '  ),concat('"kill tidb ',b.id,';"')) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| mysql -uroot -pM4Ab_d03%pQ27^1Xa# -h 10.2.103.65 -P4000 -e "kill tidb 716063544658887111;"                                                                                    |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
[root@vm10-2-103-65 ~]#  mysql -uroot -pM4Ab_d03%pQ27^1Xa# -h 10.2.103.65 -P4000 -e "kill tidb 716063544658887111;"  8.常用命令
[root@vm10-2-103-65 ~]# ti Usage: mib keyword [value1] -----------------------------------------------------------------si                          -- login tidb databaseinfo                        -- show cluster infouser                        -- list all uservar                         -- show variables like config                      -- show config where name like list                        -- show  processlistlistt                       -- processlist order by timeactive                       -- processlist order by time limit 10kill                        -- kill all session kstat                       -- kill session stateksql                        -- kill sql session;kid                         -- kill session idklike                       -- kill info like plan                        -- list sql plansize                        -- get table size index                       -- get  on table indexstats_meta                  -- getstats_meta on tablestats_histograms            -- get cloumn statistics on tablectl                         -- print tiup ctl command

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/37006.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Base64编码-算法特别的理解

Base64 在DES加密和AES加密的过程中,加密的编码会出现负数,在ascii码表中找不到对应的字符,就会出现乱码。为了解决乱码的问题,一般结合base64使用 所谓Base64,即是说在编码过程中使用了64种字符:大写A到Z、…

【GO】配置环境使加速下载 go 模块

问题 在使用 go 语言编译时,需要安装一些包,这些包在使用 go build 或 go install 时,go 自己去下载,但是会有网络不通导致无法下载的问题 解决 配置 go 的环境变量 go env -w GOPROXYhttps://goproxy.io,direct

chartGPT生成:python中连接函数的使用

在Python中,连接函数用于将多个字符串拼接在一起。常见的连接函数有join和操作符。 join函数: strings ["Hello", "world", "!"] result " ".join(strings) print(result) # 输出:Hello world …

Azure资源命名和标记决策指南

参考 azure创建虚拟机在虚拟机中选择编辑标签,并添加标记,点击应用 3.到主页中转到所有资源 4. 添加筛选器并应用 5.查看结果,筛选根据给服务器定义的标签筛选出结果。 参考链接: https://learn.microsoft.com/zh-cn/azure/cloud-adoption…

在Java中操作Redis(详细-->从环境配置到代码实现)

在Java中操作Redis 文章目录 在Java中操作Redis1、介绍2、Jedis3、Spring Data Redis3.1、对String的操作3.2、对哈希类型数据的操作3.3、对list的操作3.4、对set类型的操作3.5、对 ZSet类型的数据(有序集合)3.6、通用类型的操作 1、介绍 Redis 的Java客…

基于Echarts的数据可视化大屏

本项目学习于b站up主(视频链接) up主分享的资料,gitee仓库: 其中有笔记,笔记链接 项目总结 项目主要分为前端页面的布局和Echarts图表的嵌入,页面主要就是css较为繁琐,图表毕竟官网有模板&…

Python 2.x 中如何使用pandas模块进行数据分析

Python 2.x 中如何使用pandas模块进行数据分析 概述: 在数据分析和数据处理过程中,pandas是一个非常强大且常用的Python库。它提供了数据结构和数据分析工具,可以实现快速高效的数据处理和分析。本文将介绍如何在Python 2.x中使用pandas进行数据分析&am…

【深度学习_TensorFlow】自定义层实现cifar10

写在前面 尽管 tf.keras 提供了很多的常用网络层类,但深度学习可以使用的网络层远远不止这些。科研工作者一般是自行实现了较为新颖的网络层,经过大量实验验证有效后,深度学习框架才会跟进,内置对这些网络层的支持。因此掌握自定…

学习笔记整理-面向对象-01-认识对象

一、认识对象 1. 对象 对象(object)是键值对的集合,表示属性和值的映射关系。 对象的语法 k和v之间用冒号分割,每组k:v之间用逗号分割,最后一个k:v对后可以不书写逗号。 属性是否加引号 如果对象的属性键名不符合命名规范,则这…

数组slice、splice字符串substr、split

一、定义 这篇文章主要对数组操作的两种方法进行介绍和使用,包括:slice、splice。对字符串操作的两种方法进行介绍和使用,包括:substr、split (一)、数组 slice:可以操作的数据类型有:数组字符串 splice:数组 操作数组…

一个基础但全面的Vue的表单范例,很基础,但是很容易,也很全面。

下面这个案例,路人朋友们可以直接粘贴到html文件类型中运行,注意引入Vuejs的路径即可,不会改的可以参考我第一篇Vue入门,同时建议同志们手打,真的前端都不能熟能生巧,既不要编程了, 可以详细看注…

计算机网络-物理层(一)物理层的概念与传输媒体

计算机网络-物理层(一)物理层的概念与传输媒体 物理层相关概念 物理层的作用用来解决在各种传输媒体上传输比特0和1的问题,进而为数据链路层提供透明(看不见)传输比特流的服务物理层为数据链路层屏蔽了各种传输媒体的差异,使数据…

最新Kali Linux安装教程:从零开始打造网络安全之旅

Kali Linux,全称为Kali Linux Distribution,是一个操作系统(2013-03-13诞生),是一款基于Debian的Linux发行版,基于包含了约600个安全工具,省去了繁琐的安装、编译、配置、更新步骤,为所有工具运行提供了一个…

[低端局][cx32L003] 移植U8G2

文章目录 一、简介(1)U8g2(2)U8x8 二、配置要求三、移植步骤(1)文件准备和添加(2)实现回调接口(I2C的读写函数)①软件I2C②硬件I2C (3)功能裁剪① u8g2_d_set…

Gof23设计模式之模板方法模式

1.定义 定义一个操作中的算法骨架,而将算法的一些步骤延迟到子类中,使得子类可以不改变该算法结构的情况下重定义该算法的某些特定步骤。 2.结构 模板方法(Template Method)模式包含以下主要角色: 抽象类&#xff0…

Kerberos 重新认识 From Oracle安全

参考 https://docs.oracle.com/cd/E24847_01/html/819-7061/seamtm-1.html#scrolltoc Kerberos服务 Kerberos服务是一种网络身份认证协议,由麻省理工学院(MIT)开发。它提供了强大的身份验证功能,用于在计算机网络中验证用户和服务…

买爱心气球(nim博弈)

链接:登录—专业IT笔试面试备考平台_牛客网 来源:牛客网 Alice 和 Bob 是一对竞技编程选手,他们路过了一家气球店,发现有 m 个大爱心气球和 n个小爱心气球。他们决定玩一个游戏,游戏规则如下: Alice先手拿…

Python Selenium 设置带账号密码的socks5代理,启动浏览器

selenium添加带有账密的socks5代理 我们都知道在使用selenium开发爬虫的时候不可避免的会使用socks5高匿名代理。一般情况下我们使用方法如下(开发语言为python): from selenium import webdriver chrome_options webdriver.ChromeOptions() chrome_options.add_…

Java并发之ReentrantLock

AQS AQS(AbstractQueuedSynchronizer):抽象队列同步器,是一种用来构建锁和同步器的框架。在是JUC下一个重要的并发类,例如:ReentrantLock、Semaphore、CountDownLatch、LimitLatch等并发都是由AQS衍生出来…

React Native Expo项目,复制文本到剪切板

装包: npx expo install expo-clipboard import * as Clipboard from expo-clipboardconst handleCopy async (text) > {await Clipboard.setStringAsync(text)Toast.show(复制成功, {duration: 3000,position: Toast.positions.CENTER,})} 参考链接&#xff1a…