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
相关文章:
TiDB 应急运维脚本,更加方便的管理TiDB集群
TiDB 应急运维脚本,更加方便的管理TiDB集群 使用方法 使用方法:[tidblocalhost ~]$ which tiup ~/.tiup/bin/tiup编辑脚本,MYSQL_PASSWD 和 PORT 根据实际替换 [tidblocalhost ~]$ vi ~/.tiup/bin/ti#version 1.1 #author guanguanglei ##…...

第二部分:AOP
一、AOP简介 AOP(Aspect Oriented Programming)面向切面编程,一种编程范式,指导开发者如何组织程序结构。 AOP是OOP(面向对象编程)的进阶版。 作用:在不改变原始设计的基础上为其进行功能增强。 spring理念&#x…...

分享一组天气组件
先看效果: CSS部分代码(查看更多): <style>:root {--bg-color: #E9F5FA;--day-text-color: #4DB0D3;/* 多云 */--cloudy-background: #4DB0D3;--cloudy-temperature: #E6DF95;--cloudy-content: #D3EBF4;/* 晴 */--sunny-b…...
微服务中RestTemplate访问其他服务返回值转换问题
背景: 接收一个springcloud项目,UI模块访问其他服务的接口,返回数据统一都是使用fastjson进行转换,但是新开发了几个新模块之后发现fastjson很多bug(各种内存溢出),但是很多地方已经重度依赖fa…...

Centos7.9上(离线)安装Gitlab
1、下载Gitlab的rpm安装包Index of /gitlab-ce/yum/el7/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror 2、安装rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm,如果依赖缺失,yum安装即可 3、vi /etc/gitlab/gitlab.rb 配置external_url&…...

pikachu中RCE出现乱码的解决的方案
exec “ping” 输入127.0.0.1 这种乱码的解决办法就是在pikachu/vul/rce/rce_ping.php目录里面的第18行代码 header("Content-type:text/html; charsetgbk");的注释打开即可。 BUT但是吧!又出现了其他的乱码!但是搞完这个再把它给注释掉就行了…...
airflow是什么
Airflow 简介 Airflow是一个基于有向无环图(DAG)的可编程、调度和监控的工作流平台,它可以定义一组有依赖的任务,按照依赖依次执行。airflow提供了丰富的命令行工具用于系统管控,而其web管理界面同样也可以方便的管控调度任务,并…...
训练用于序列分类任务的 RoBERTa 模型的适配器
介绍 NLP当前的趋势包括下载和微调具有数百万甚至数十亿参数的预训练模型。然而,存储和共享如此大的训练模型非常耗时、缓慢且昂贵。这些限制阻碍了 RoBERTa 模型开发更多用途和适应性更强的 NLP 技术,该模型可以从多个任务中学习并针对多个任务进行学习;在本文中,我们将重…...

Linux之awk判断和循环
echo zhaoy 70 72 74 76 74 72 >> score.txt echo wangl 70 81 84 82 90 88 >> score.txt echo qiane 60 62 64 66 65 62 >> score.txt echo sunw 80 83 84 85 84 85 >> score.txt echo lixi 96 80 90 95 89 87 >> score.txt把下边的内容写入到s…...

Django入门
Day1 django环境安装 创建虚拟环境 # step1 创建虚拟环境 python3 -m venv datawhale_django # step2 mac进入虚拟环境 source ./datawhale_django/bin/activate # step3 退出虚拟环境 deactivate安装包 pip3 install django pip3 install djangorestframework pip3 …...

uniapp 格式化时间刚刚,几分钟前,几小时前,几天前…
效果如图: 根目录下新建utils文件夹,文件夹下新增js文件,文件内容: export const filters {dateTimeSub(data) {if (data undefined) {return;}// 传进来的data必须是日期格式,不能是时间戳//将字符串转换成时间格式…...

JProfiler —CPU评测
当JProfiler测量方法调用的执行时间及其调用堆栈时,我们称之为“CPU评测”。这些数据以多种方式呈现。根据你试图解决的问题,其中一个或另一个演示将是最有帮助的。默认情况下不会记录CPU数据,您必须打开CPU记录才能捕获有趣的用例。 一、调…...
994. 腐烂的橘子
994. 腐烂的橘子(面试题打卡/前缀和/简单) 来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/rotting-oranges/ 题干: 在给定的 m x n 网格 grid 中,每个单元格可以有以下三个值之一:…...

Rx.NET in Action 第三章学习笔记
3 C#函数式编程思想 本章内容包括 将 C# 与函数式技术相结合使用委托和 lambda 表达式使用 LINQ 查询集合 面向对象编程为程序开发提供了巨大的生产力。它将复杂的系统分解为类,使项目更易于管理,而对象则是一个个孤岛,你可以集中精力分别处理…...

Windows11环境下VS2019调用Pytorch语义分割模型(C++版)
语义分割模型在训练时往往采用python脚本进行网络搭建和训练,并获得训练好的模型。为了提高效率方便整个工程项目部署,实际工程应用中通常希望使用C编程语言调用训练好的网络模型。查询大量网络资料并踩过无数坑后,经实际测试实现了在window1…...
Milkv Duo 以太网使用与配置
网络配置 使能网卡 使用ip link查看是否存在eth0网卡,若无使用如下命令使能网卡: ip link set eth0 up两次使用ip link确认网卡eth0已经使能。 配置IP、gws 本人设备连接到华为路由器下,故增加如下路由信息: ip route add d…...

bash: make: command not found
make之后报错信息如下:cd 对应的文件路径后 make 发现报错:bash: make: command not found 这个原因可能是没有安装make工具,也可能是安装了make之后,没有将make的文件路径添加到系统环境变量中 有没有安装make,可以使用Search Everything搜索是否有make…...

热点如何用于期刊写作——以chatGPT为例
交叉领域A,B 以自己为例子,A是教育 B是技术,我是教育技术学专业。 经验来源 知网关于GPT的140余篇专业论文的观察 截止至2023年8月14日15:35:45 学习每出现一个热点,如何应用于学术。 实践阅读发现 套路一:谈理论…...
IGV.js 的完全本地化运行探索
问题及解决方法 IGV.js 完全本地化是为了合规,不使用外网的情况下查看基因组。不联网需要下载 genomes.json 文件及其中的内容之外,还需要修改 igv.js本身,防止5s超时后才显示网页内容。修改的关键词是: genomes.json,改为本地的…...

网络安全渗透测试之靶场训练
NWES: 7月26号武汉地震检测中心遭受境外具有政府背景的黑客组织和不法分子的网络攻击。 目前网络攻击主要来自以下几种方式: DDOS:分布式拒绝服务攻击。通过制造大量无用的请求向目标服务器发起访问,使其因短时间内无法处理大量请求而陷入瘫痪。主要针对…...

装饰模式(Decorator Pattern)重构java邮件发奖系统实战
前言 现在我们有个如下的需求,设计一个邮件发奖的小系统, 需求 1.数据验证 → 2. 敏感信息加密 → 3. 日志记录 → 4. 实际发送邮件 装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其…...

React19源码系列之 事件插件系统
事件类别 事件类型 定义 文档 Event Event 接口表示在 EventTarget 上出现的事件。 Event - Web API | MDN UIEvent UIEvent 接口表示简单的用户界面事件。 UIEvent - Web API | MDN KeyboardEvent KeyboardEvent 对象描述了用户与键盘的交互。 KeyboardEvent - Web…...

Nuxt.js 中的路由配置详解
Nuxt.js 通过其内置的路由系统简化了应用的路由配置,使得开发者可以轻松地管理页面导航和 URL 结构。路由配置主要涉及页面组件的组织、动态路由的设置以及路由元信息的配置。 自动路由生成 Nuxt.js 会根据 pages 目录下的文件结构自动生成路由配置。每个文件都会对…...
DeepSeek 技术赋能无人农场协同作业:用 AI 重构农田管理 “神经网”
目录 一、引言二、DeepSeek 技术大揭秘2.1 核心架构解析2.2 关键技术剖析 三、智能农业无人农场协同作业现状3.1 发展现状概述3.2 协同作业模式介绍 四、DeepSeek 的 “农场奇妙游”4.1 数据处理与分析4.2 作物生长监测与预测4.3 病虫害防治4.4 农机协同作业调度 五、实际案例大…...
Web 架构之 CDN 加速原理与落地实践
文章目录 一、思维导图二、正文内容(一)CDN 基础概念1. 定义2. 组成部分 (二)CDN 加速原理1. 请求路由2. 内容缓存3. 内容更新 (三)CDN 落地实践1. 选择 CDN 服务商2. 配置 CDN3. 集成到 Web 架构 …...

Qemu arm操作系统开发环境
使用qemu虚拟arm硬件比较合适。 步骤如下: 安装qemu apt install qemu-system安装aarch64-none-elf-gcc 需要手动下载,下载地址:https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x…...

Visual Studio Code 扩展
Visual Studio Code 扩展 change-case 大小写转换EmmyLua for VSCode 调试插件Bookmarks 书签 change-case 大小写转换 https://marketplace.visualstudio.com/items?itemNamewmaurer.change-case 选中单词后,命令 changeCase.commands 可预览转换效果 EmmyLua…...
绕过 Xcode?使用 Appuploader和主流工具实现 iOS 上架自动化
iOS 应用的发布流程一直是开发链路中最“苹果味”的环节:强依赖 Xcode、必须使用 macOS、各种证书和描述文件配置……对很多跨平台开发者来说,这一套流程并不友好。 特别是当你的项目主要在 Windows 或 Linux 下开发(例如 Flutter、React Na…...

一些实用的chrome扩展0x01
简介 浏览器扩展程序有助于自动化任务、查找隐藏的漏洞、隐藏自身痕迹。以下列出了一些必备扩展程序,无论是测试应用程序、搜寻漏洞还是收集情报,它们都能提升工作流程。 FoxyProxy 代理管理工具,此扩展简化了使用代理(如 Burp…...
raid存储技术
1. 存储技术概念 数据存储架构是对数据存储方式、存储设备及相关组件的组织和规划,涵盖存储系统的布局、数据存储策略等,它明确数据如何存储、管理与访问,为数据的安全、高效使用提供支撑。 由计算机中一组存储设备、控制部件和管理信息调度的…...