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:分布式拒绝服务攻击。通过制造大量无用的请求向目标服务器发起访问,使其因短时间内无法处理大量请求而陷入瘫痪。主要针对…...
Flask RESTful 示例
目录 1. 环境准备2. 安装依赖3. 修改main.py4. 运行应用5. API使用示例获取所有任务获取单个任务创建新任务更新任务删除任务 中文乱码问题: 下面创建一个简单的Flask RESTful API示例。首先,我们需要创建环境,安装必要的依赖,然后…...
日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする
日语学习-日语知识点小记-构建基础-JLPT-N4阶段(33):にする 1、前言(1)情况说明(2)工程师的信仰2、知识点(1) にする1,接续:名词+にする2,接续:疑问词+にする3,(A)は(B)にする。(2)復習:(1)复习句子(2)ために & ように(3)そう(4)にする3、…...
智慧工地云平台源码,基于微服务架构+Java+Spring Cloud +UniApp +MySql
智慧工地管理云平台系统,智慧工地全套源码,java版智慧工地源码,支持PC端、大屏端、移动端。 智慧工地聚焦建筑行业的市场需求,提供“平台网络终端”的整体解决方案,提供劳务管理、视频管理、智能监测、绿色施工、安全管…...
渗透实战PortSwigger靶场-XSS Lab 14:大多数标签和属性被阻止
<script>标签被拦截 我们需要把全部可用的 tag 和 event 进行暴力破解 XSS cheat sheet: https://portswigger.net/web-security/cross-site-scripting/cheat-sheet 通过爆破发现body可以用 再把全部 events 放进去爆破 这些 event 全部可用 <body onres…...
linux 下常用变更-8
1、删除普通用户 查询用户初始UID和GIDls -l /home/ ###家目录中查看UID cat /etc/group ###此文件查看GID删除用户1.编辑文件 /etc/passwd 找到对应的行,YW343:x:0:0::/home/YW343:/bin/bash 2.将标红的位置修改为用户对应初始UID和GID: YW3…...
安卓基础(aar)
重新设置java21的环境,临时设置 $env:JAVA_HOME "D:\Android Studio\jbr" 查看当前环境变量 JAVA_HOME 的值 echo $env:JAVA_HOME 构建ARR文件 ./gradlew :private-lib:assembleRelease 目录是这样的: MyApp/ ├── app/ …...
libfmt: 现代C++的格式化工具库介绍与酷炫功能
libfmt: 现代C的格式化工具库介绍与酷炫功能 libfmt 是一个开源的C格式化库,提供了高效、安全的文本格式化功能,是C20中引入的std::format的基础实现。它比传统的printf和iostream更安全、更灵活、性能更好。 基本介绍 主要特点 类型安全:…...
算法250609 高精度
加法 #include<stdio.h> #include<iostream> #include<string.h> #include<math.h> #include<algorithm> using namespace std; char input1[205]; char input2[205]; int main(){while(scanf("%s%s",input1,input2)!EOF){int a[205]…...
【threejs】每天一个小案例讲解:创建基本的3D场景
代码仓 GitHub - TiffanyHoo/three_practices: Learning three.js together! 可自行clone,无需安装依赖,直接liver-server运行/直接打开chapter01中的html文件 运行效果图 知识要点 核心三要素 场景(Scene) 使用 THREE.Scene(…...
本地部署drawDB结合内网穿透技术实现数据库远程管控方案
文章目录 前言1. Windows本地部署DrawDB2. 安装Cpolar内网穿透3. 实现公网访问DrawDB4. 固定DrawDB公网地址 前言 在数字化浪潮席卷全球的背景下,数据治理能力正日益成为构建现代企业核心竞争力的关键因素。无论是全球500强企业的数据中枢系统,还是初创…...
