TiDB集群安装维护
TIDB安装操作文档-https://docs.pingcap.com/zh/tidb/stable/production-deployment-using-tiup
1、环境准备(每台)
1-查看系统盘是否为ext4并自动挂载
fdisk -l | mkfs.ext4 /dev/ | mount /dev/ | vim /etc/fstab
2-关闭swap :
一起执行 swapoff -a 和 swapon -a 命令是为了刷新 swap,将 swap 里的数据转储回内存,并清空 swap 里的数据。
echo "vm.swappiness = 0">> /etc/sysctl.conf
swapoff -a && swapon -a
sysctl -p
3-关闭防火墙:
systemctl stop firewalld.service | systemctl disable firewalld.service
4-时间需同要步,
建议使用ntp服务。(最好添加 crontab -e 定期任务 :30 10 * * * `/sbin/ntpdate xx.xx.xx.xx)记得写入硬件时间中,重启不恢复。 hwclock -w
5-优化环境参数:使用 tuned。
1.执行
tuned-adm list 0, Current active profile: balanced
表示当前操作系统的 tuned 策略使用 balanced,建议在当前策略的基础上添加操作系统优化配置。
2.创建新的 tuned 策略
mkdir /etc/tuned/balanced-tidb-optimal/
vi /etc/tuned/balanced-tidb-optimal/tuned.conf
[main]
include=balanced#“include=balanced 表示在现有的 balanced 策略基础上添加操作系统优化配置。”
[cpu]
governor=performance
[vm]
transparent_hugepages=never
[disk]
devices_udev_regex=(ID_SERIAL=36d0946606d79f90025f3e09a0c1fc035)|(ID_SERIAL=36d0946606d79f90025f3e09a0c1f9e81)
elevator=noop
**3.应用新的tuned策略 **
tuned-adm profile balanced-tidb-optimal
** 4.检查:**
1)
cat /sys/kernel/mm/transparent_hugepage/enabled
执行以下命令验证透明大页的状态 返回值应为 always madvise [never]
2)```
cat /sys/block/sd[bc]/queue/scheduler
执行以下命令验证数据目录所在磁盘的 I/O 调度器。返回值 [noop] deadline cfq
3)
cpupower frequency-info --policy
执行以下命令查看 cpufreq 模块选用的节能策略。返回:
```analyzing CPU 0:
current policy: frequency should be within 1.20 GHz and 3.10 GHz.
The governor "performance" may decide which speed to use within this range.
4)执行以下命令修改 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
5)执行以下命令配置用户的 limits.conf 文件。
cat << EOF >>/etc/security/limits.conf
tidb soft nofile 1000000
tidb hard nofile 1000000
tidb soft stack 32768
tidb hard stack 32768
EOF
cat << EOF >>/etc/security/limits.conf
tidb soft nofile 1000000
tidb hard nofile 1000000
tidb soft stack 32768
tidb hard stack 32768
EOF
6)互信(可不做)
6-安装 numactl 工具:在生产环境中,因为硬件机器配置往往高于需求,为了更合理规划资源,会考虑单机多实例
部署TiDB 或者 TiKV。NUMA 绑核工具的使用,主要为了防止 CPU 资源的争抢,引发性能衰退。
1.登录所有节点安装
yum -y install numactl
==================================================================================================================
2、安装部署(安装前一定确定时间校准!)
现有环境三台机器:
172.16.80.31
172.16.80.32
172.16.80.33
1.离线安装包传至主节点解压
2.开始安装:
1)sh /date/tidb-community-server-v5.1.1-linux-amd64/local_install.sh
根据回显看 shell protile: 显示目录
2)执行环节变量 :source / (shell protile: 显示目录)
3)查看tidb list : tiup list tidb 查看版本号
4)按需编辑配置文件 topology.yaml,配置文件不用放到文件夹中,只是安装配置文件
5)执行 tiup cluster deploy lgtidb v5.1.1 ./topology.yaml --user root -p 输入服务器本机密码,Y确认。
#注意 lgtidb<命名集群名> v5.1.1<根据tiup list tidb查询到的版本号修改>
6)根据提示启动集群 tiup cluster start lgtidb
7)查看集群状态 tiup cluster display lgtidb
3.安装完毕:
1)查看集群pd|L|UP 领导节点 172.16.80.31:2379 密码默认为空
2)查看grafana监测页面 172.16.80.31:3000 默认账号密码为admin/admin
安装后调试--TIDB
1、检查集群状态:tiup cluster display lgtidb <集群名称> , http://172.16.80.31:3000 查看Overview(IP为grafana部署地址)。
2、启动集群:tiup cluster start lgtidb <集群名称>。
3、查看 TiUP 管理集群情况:tiup cluster list该命令会输出当前通过 TiUP cluster 管理的所有集群信息,包括集群名称、部署用户、版本、密钥信息等。
4、扩容与缩容
扩容 编辑一个 scale-out.yaml 的文件,tiup cluster scale-out lgtidb<集群名称> scale-out.yaml
预期输出 Scaled cluster lgtidb<集群名称> out successfully 信息,表示扩容操作成功。
内容格式:
TiDB 配置文件参考:
tidb_servers:
- host: 10.0.1.5
ssh_port: 22
port: 4000
status_port: 10080
deploy_dir: /data/deploy/deploy/tidb-4000
log_dir: /data/deploy/log/tidb-4000
TiKV 配置文件参考:
tikv_servers:
- host: 10.0.1.5
ssh_port: 22
port: 20160
status_port: 20180
deploy_dir: /data/deploy/deploy/tikv-20160
data_dir: /data/deploy/data/tikv-20160
log_dir: /data/deploy/log/tikv-20160
PD 配置文件参考:
pd_servers:
- host: 10.0.1.5
ssh_port: 22
name: pd-1
client_port: 2379
peer_port: 2380
deploy_dir: /data/deploy/deploy/pd-2379
data_dir: /data/deploy/data/pd-2379
log_dir: /data/deploy/log/pd-2379```
查看当前集群的配置:
可以使用 tiup cluster edit-config lgtidb<cluster-name> 查看当前集群的配置信息,
因为其中的 global 和 server_configs参数配置默认会被 scale-out.yaml 继承,
因此也会在scale-out.yaml 中生效。
缩容 查看集群运行状态后(tiup cluster display lgtidb<cluster-name>),根据node(ID ,为IP加端口号)
关闭、移除服务。
移除PD服务: tiup cluster scale-in lgtidb --node 172.16.80.32:2379 <PD>
移除TIDB服务:tiup cluster scale-in lgtidb --node 172.16.80.32:4000 <TIDB>
移除KITV服务:tiup cluster scale-in lgtidb --node 172.16.80.32:20160 <KITV>
tidb扩容ticdc组件
1.在安装路径/opt/tidb-community-toolkit-v6.5.1-linux-amd64下创建scale-out.yaml文件
cdc_servers:
- host: 192.168.44.81
gc-ttl: 86400
data_dir: /yw-data/tidb-deploy/ticdc/cdc-8300
- host: 192.168.44.82
gc-ttl: 86400
data_dir: /yw-data/tidb-deploy/ticdc/cdc-8300
- host: 192.168.44.83
gc-ttl: 86400
data_dir: /yw-data/tidb-deploy/ticdc/cdc-8300
host为节点ip
gc-ttl为gc大小 86400为默认值
data_dir为ticdc的路径
2.执行以下命令扩容
tiup cluster scale-out yw-test scale-out.yaml --user root -p yw-test 集群名称
3.查看集群状态
tiup cluster display yw-test
终止 TiCDC 节点:tiup cluster stop -R cdc
启动 TiCDC 节点:tiup cluster start -R cdc
重启 TiCDC 节点:tiup cluster restart -R cdc
---------------------------------------------ticdc维护------------------------------------------------------------------------
使用 TiUP 在原有 TiDB 集群上移除或缩容 TiCDC 组件
推荐使用 TiUP 完成对 TiCDC 集群节点的缩容。使用类似下面的命令完成缩容:
tiup cluster scale-in <cluster-name> --node 182.168.44.81:8300
更多用例说明,请参考缩容 TiCDC 节点。
使用 TiUP 升级 TiCDC 集群
TiUP 支持升级 TiDB 集群,包括 TiCDC 组件。执行升级指令时,TiUP 会自动升级 TiCDC 组件,无需额外操作。
操作示例如下:
tiup update --self && \
tiup update --all && \
tiup cluster upgrade <cluster-name> <version> --transfer-timeout 600
注意
命令中的 <cluster-name> 需要替换为集群名字,<version> 需要替换为目标版本号,例如 v6.5.1。
升级的注意事项
升级 TiCDC 集群时,需要注意以下事项:
TiCDC v4.0.2 对 changefeed 的配置做了调整,请参阅配置文件兼容注意事项。
升级期间遇到的问题及其解决办法,请参阅使用 TiUP 升级 TiDB。
TiCDC 自 v6.3.0 起支持滚动升级,使用 TiUP 升级 TiCDC 节点期间,能够保证同步延迟稳定,不发生剧烈波动。
满足以下条件将自动启用滚动升级:
TiCDC 版本大于等于 v6.3.0。
TiUP 版本大于等于 v1.11.0。
集群中至少有两个正在运行的 TiCDC 实例。
使用 TiUP 变更 TiCDC 集群配置
本节介绍如何使用
TiUP 的 tiup cluster edit-config 命令来修改 TiCDC 的配置。在以下例子中,假设需要把 TiCDC 的 gc-ttl 从默认值 86400 修改为 172800,即 48 小时。
执行 tiup cluster edit-config 命令,注意将 <cluster-name> 替换成实际的集群名:
tiup cluster edit-config <cluster-name>
在 vi 编辑器页面,修改 server-configs 下的 cdc 配置:
server_configs:
tidb: {}
tikv: {}
pd: {}
tiflash: {}
tiflash-learner: {}
pump: {}
drainer: {}
cdc:
gc-ttl: 172800
以上把 TiCDC 的 gc-ttl 的值设置为 48 小时。
执行 tiup cluster reload -R cdc 命令重新加载配置。
使用 TiUP 终止和启动 TiCDC 节点
使用 TiUP 可以方便地终止和启动 TiCDC 节点,命令如下:
终止 TiCDC 节点:tiup cluster stop -R cdc
启动 TiCDC 节点:tiup cluster start -R cdc
重启 TiCDC 节点:tiup cluster restart -R cdc
使用加密传输 (TLS) 功能
请参阅为 TiDB 组件间通信开启加密传输。
使用 TiCDC 命令行工具来查看集群状态
执行以下命令来查看 TiCDC 集群运行状态,注意需要将 v<CLUSTER_VERSION> 替换为 TiCDC 集群版本,例如 v6.5.1:
tiup ctl:v<CLUSTER_VERSION> cdc capture list --server=http://10.0.10.25:8300
[
{
"id": "806e3a1b-0e31-477f-9dd6-f3f2c570abdd",
"is-owner": true,
"address": "127.0.0.1:8300",
"cluster-id": "default"
},
{
"id": "ea2a4203-56fe-43a6-b442-7b295f458ebc",
"is-owner": false,
"address": "127.0.0.1:8301",
"cluster-id": "default"
}
]
id:表示服务进程的 ID。
is-owner:表示该服务进程是否为 owner 节点。
address:该服务进程对外提供接口的地址。
cluster-id:该 TiCDC 的集群 ID,默认值为 default。
-------------------------------------------------------------------------------‘
-----------------------一定检查TIDB用户的密码有效期要设置为用不过期---------------------------不设置过期后无法执行tiup重启和关闭
chage -l tidb
chage -M 99999 -W 7 tidb
-----------------------一定检查TIDB迁移后的存储文件目录是否为tidb用户组---------------------------不修改无法修改reload配置文件
chown -R tidb:tidb /目标路径
-----------------------一定检查TIDB所有节点的last_tikv.toml,修改后再同步配置文件-----------------具体参考https://asktug.com/t/topic/63294
将所有节点的last_tikv.toml文件mv 为 last_tikv.toml.bak ,修改后再同步配置文件。
安装HA
HAProxy安装文档——参考https://www.cnblogs.com/chen110xi/p/6208553.html、https://blog.51cto.com/johnsz/715922
参数说明:
TARGET=linux3100
使用uname -r查看内核,如:2.6.18-371.el5,此时该参数就为linux26
kernel 大于2.6.28的用:TARGET=linux2628
CPU=x86_64 #使用uname -r查看系统信息,如x86_64 x86_64 x86_64 GNU/Linux,此时该参数就为x86_64
PREFIX=/usr/local/haprpxy #/data/haprpxy为haprpxy安装路径
1、解压 :tar xf 压缩包
2、安装 :
进入解压后的文件夹,make TARGET=linux310(查询linux内核版本 rname -r 3.10.0-862.el7.x86_64) PREFIX=/data/haproxy
make install PREFIX=/data/haproxy
3、创建配置文件并创建软连接。
mkdir -p /usr/local/haproxy/conf #创建配置文件目录
mkdir -p /etc/haproxy``` #创建配置文件目录
touch /usr/local/haproxy/conf/haproxy.cfg #创建配置文件 --安装包中有配置好的,需要修改tidb的ip地址
ln -s /usr/local/haproxy/conf/haproxy.cfg /etc/haproxy/haproxy.cfg #添加配置文件软连接
cp -r /usr/local/src/haproxy-1.6.9/examples/errorfiles /usr/local/haproxy/errorfiles #拷贝错误页面
ln -s /usr/local/haproxy/errorfiles /etc/haproxy/errorfiles #添加软连接
mkdir -p /usr/local/haproxy/log #创建日志文件目录
touch /usr/local/haproxy/log/haproxy.log #创建日志文件
ln -s /usr/local/haproxy/log/haproxy.log /var/log/haproxy.log #添加软连接
4、开机启动
cp /usr/local/src/haproxy-1.6.9/examples/haproxy.init /etc/rc.d/init.d/haproxy #拷贝开机启动文件
chmod +x /etc/rc.d/init.d/haproxy #添加脚本执行权限
chkconfig haproxy on #设置开机启动
ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin #添加软连接
配置文件中,stats中配置的是可视化页面访问地址和端口和后缀。http://192.169.144.167:8080/haproxy
升级TiDB版本
升级 TiUP 或更新 TiUP 离线镜像
升级 TiUP 和 TiUP Cluster
注意
先升级 TiUP 版本(建议 tiup 版本不低于 1.11.0):
tiup update --self
tiup --version
再升级 TiUP Cluster 版本(建议 tiup cluster 版本不低于 1.11.0):
tiup update cluster
tiup cluster --version
下载部署新版本的 TiUP 离线镜像,上传到中控机。在执行 local_install.sh 后,TiUP 会完成覆盖升级。
tar xzvf tidb-community-server-${version}-linux-amd64.tar.gz
sh tidb-community-server-${version}-linux-amd64/local_install.sh
source /home/tidb/.bash_profile
覆盖升级完成后,需将 server 和 toolkit 两个离线镜像合并,执行以下命令合并离线组件到 server 目录下。
tar xf tidb-community-toolkit-${version}-linux-amd64.tar.gz
ls -ld tidb-community-server-${version}-linux-amd64 tidb-community-toolkit-${version}-linux-amd64
cd tidb-community-server-${version}-linux-amd64/
cp -rp keys ~/.tiup/
tiup mirror merge ../tidb-community-toolkit-${version}-linux-amd64
离线镜像合并后,执行下列命令升级 Cluster 组件:
tiup update cluster
检查当前集群的健康状况
为避免升级过程中出现未定义行为或其他故障,建议在升级前对集群当前的 region 健康状态进行检查,此操作可通过 check 子命令完成。
tiup cluster check <cluster-name> --cluster
执行结束后,最后会输出 region status 检查结果。如果结果为 "All regions are healthy",则说明当前集群中所有 region 均为健康状态,可以继续执行升级;如果结果为 "Regions are not fully healthy: m miss-peer, n pending-peer" 并提示 "Please fix unhealthy regions before other operations.",则说明当前集群中有 region 处在异常状态,应先排除相应异常状态,并再次检查结果为 "All regions are healthy" 后再继续升级。
升级 TiDB 集群
升级的方式有两种:不停机升级和停机升级。TiUP Cluster 默认的升级 TiDB 集群的方式是不停机升级,即升级过程中集群仍然可以对外提供服务。升级时会对各节点逐个迁移 leader 后再升级和重启,因此对于大规模集群需要较长时间才能完成整个升级操作。如果业务有维护窗口可供数据库停机维护,则可以使用停机升级的方式快速进行升级操作。
不停机升级
tiup cluster upgrade <cluster-name> <version>
以升级到 6.5.1 版本为例:
tiup cluster upgrade <cluster-name> v6.5.1
停机升级
在停机升级前,首先需要将整个集群关停。
tiup cluster stop <cluster-name>
之后通过 upgrade 命令添加 --offline 参数来进行停机升级,其中 <cluster-name> 为集群名,<version> 为升级的目标版本,例如 v6.5.1。
tiup cluster upgrade <cluster-name> <version> --offline
升级完成后集群不会自动启动,需要使用 start 命令来启动集群。
tiup cluster start <cluster-name>
升级后验证
执行 display 命令来查看最新的集群版本 TiDB Version:
tiup cluster display <cluster-name>
Cluster type: tidb
Cluster name: <cluster-name>
Cluster version: v6.5.1
TiDB集群安装维护的更多相关文章
- Centos7配置TiDB集群
一:各模块属性 模块名称 状态 建议实例数 功能 负载均衡组件 TiDB 无状态 2 接收SQL请求,处理SQL相关逻辑,并通过PB找到存储数据的TiKV地址 LVS.HAProxy.F5 PB 集群 ...
- 在线安装TIDB集群
在线安装TiDB集群 服务器准备 说明:TiDB8需要能够连接外网,以便下载各类安装包 TiDB4非必须,但最好是有一台,因为后续测试Mysql数据同步或者进行性能比较时,都要用到 TiKV最好是采 ...
- 使用 Docker Compose 快速构建 TiDB 集群
本文档介绍如何在单机上通过 Docker Compose 快速一键部署一套 TiDB 测试集群.Docker Compose 可以通过一个 YAML 文件定义多个容器的应用服务,然后一键启动或停止. ...
- 部署TiDB集群
架构图 节点规划 120.52.146.213 Control Machine 120.52.146.214 PD1_TiDB1 120.52.146.215 PD2_TiDB2 120.52.146 ...
- TiDB集群安装主要操作
TiDB集群安装主要操作 参考资料:https://www.cnblogs.com/plyx/archive/2018/12/21/10158615.html 一.TiDB数据简介 TiDB 是 Pi ...
- tidb集群
tidb ansible部署 https://zhuanlan.zhihu.com/p/27308307?refer=newsql 网址:http://www.cnblogs.com/mowei/p/ ...
- Tiup离线安装TIDB集群4.0.16版本
环境:centos7.6 中控机:8.213.8.25(内网) 可用服务器8.213.8.25-8.213.8.29 一.准备 TiUP 离线组件包 方法1:外网下载离线安装包拷贝进内网服务器 在Ti ...
- tidb集群某个节点报错之:node_exporter-9100.service failed
今天启动集群tidb时出现一个错误,是某个tikv节点报错:node_exporter-9100.service failed 一个节点的问题会导致整个集群启动失败.去此节点下的日志文件中查找,发现 ...
- tidb 集群扩容
1. tidb 新增节点 a. 编辑 inventory.ini [tidb_servers] 10.0.230.14 10.0.230.15 10.10.230.20 b. 初始化新增节点 ansi ...
- TiDB集群手动安装
TIDB的安装 TiDB 是 PingCAP 公司受 Google Spanner / F1 论文启发而设计的开源分布式 HTAP (Hybrid Transactional and Analytic ...
随机推荐
- 【Git】03 撤销 & 版本回退
回退分为三种情况,每种情况对应了我们文件的存储区域 工作区 | 暂存区 | 版本区(当前分支) 1.文件可能存放在工作区,没有被Git追踪[红色标记状态] 2.文件可能已经添加到暂存区,没有被Git提 ...
- 【Layui】05 选项卡 Tabs
文档位置: https://www.layui.com/doc/element/tab.html 案例演示: <div class="layui-tab"> <u ...
- Springboot实现HTML表单from简单的接收信息
HTML< from >元素 from可向Web服务器提交请求 普遍格式: <from action="服务器地址" method="请求方式" ...
- RTX显卡 运行TensorFlow=1.14.0 代码 报错 Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR
硬件环境: RTX2070super 显卡 软件环境: Ubuntu18.04.5 Tensorflow = 1.14.0 -------------------------------------- ...
- 国产深度学习框架吸引用户的一种免费手段——免费GPU时长
国产的深度学习框架基本成为了一个头部公司的标配了,不论是阿里.百度还是华为都推出了自己的深度学习框架,这几家公司为了吸引用户也都采取了免费使用GPU的活动,但是与阿里.百度的不同,华为是与固定的高校的 ...
- Python报错:WARNING conda.models.version:get_matcher(542): Using .* with relational operator is superfluous and deprecated and will be removed in a future version of conda.
参考: https://blog.csdn.net/weixin_45685859/article/details/132916216 报错: [23:59:14](pytorch) devil@OM ...
- 【转载】 使用Python的ctypes查看内存
=================================================================== 原文地址: https://zhuanlan.zhihu.com ...
- docker 常用工具
windows 下常常需要linux环境 直接安装虚拟机不方便也浪费资源 所以直接在docker下安装一个centos 然后搭建好开发环境就是个不错的办法 一.Linux 环境 1.安装centos ...
- 2023 ICPC 香港
gym 开场发现 E 是传统数据结构题很高兴,不过先跳了.F 知道相邻两段的长度差 \(\le1\),以为最终每段长度只有 \(\lfloor\frac{n}{m+1}\rfloor,\lceil\f ...
- SLF4J+Logback日志搭建
一.jar包依赖 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api< ...