环境:centos7.6

中控机:8.213.8.25(内网)

可用服务器8.213.8.25-8.213.8.29

一、准备 TiUP 离线组件包

方法1:外网下载离线安装包拷贝进内网服务器

TiDB官网下载页面选择对应版本的TiDBserver离线安装包,拷贝进内网中控机的/root/soft目录下。

方法2:使用 tiup mirror clone 命令手动打包离线组件包

1、在线环境中安装 TiUP 包管理器工具

①执行如下命令安装 TiUP 工具:

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

②重新声明全局环境变量:

source .bash_profile

③确认 TiUP 工具是否安装:

which tiup

2、使用 TiUP 制作离线镜像

①在一台和外网相通的机器上拉取需要的组件:

tiup mirror clone tidb-community-server-${version}-linux-amd64 ${version} --os=linux --arch=amd64

该命令会在当前目录下创建一个名叫 tidb-community-server-${version}-linux-amd64 的目录,里面包含 TiUP 管理的组件包。

②通过 tar 命令将该组件包打包然后发送到隔离环境的中控机:

tar czvf tidb-community-server-${version}-linux-amd64.tar.gz tidb-community-server-${version}-linux-amd64

此时,tidb-community-server-${version}-linux-amd64.tar.gz 就是一个独立的离线环境包。

二、 部署离线环境 TiUP 组件

将离线包发送到目标集群的中控机后,执行以下命令安装 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

local_install.sh 脚本会自动执行 tiup mirror set tidb-community-server-${version}-linux-amd64 命令将当前镜像地址设置为 tidb-community-server-${version}-linux-amd64

若需将镜像切换到其他目录,可以通过手动执行 tiup mirror set <mirror-dir> 进行切换。如果需要切换到在线环境,可执行 tiup mirror set https://tiup-mirrors.pingcap.com。

三、TiKV 数据盘挂载

推荐 TiKV 部署目标机器的数据目录使用 EXT4 文件系统格式。相比于 XFS 文件系统格式,EXT4 文件系统格式在 TiDB 集群部署案例较多,生产环境优先选择使用 EXT4 文件系统格式。

磁盘大于1T方法

fdisk -l

Disk /dev/vdb: 1000 GB

parted -s -a optimal /dev/vdb mklabel gpt -- mkpart primary ext4 1 -1

创建分区

echo "UUID=$(lsblk -f|grep vdb1|awk '{print $3}') /data1 ext4 defaults,nodelalloc,noatime 0 2" >> /etc/fstab

配置开机自动挂载

mkfs.ext4 /dev/vdb1

格式化磁盘

more /etc/fstab

mkdir /data1 && mount -a

挂载盘

磁盘小于1T方法

pvcreate /dev/vdb

vgcreate vg_data /dev/vdb

lvcreate -l 100%VG -n lv_tidb vg_data mkdir /data1

mkfs.ext4 /dev/mapper/vg_data-lv_tidb

echo "UUID=$(lsblk -f|grep vg_data-lv_tidb|awk '{print $3}') /data1 ext4 defaults,nodelalloc,noatime 0 2" >> /etc/fstab

more /etc/fstab

mount -a

四、中控机上配置ssh免密登陆(包括自己对自己的免密)

ssh-keygen #一直回车

ssh-copy-id root@80.213.8.25 #输入密码配置免密登陆

ssh-copy-id root@80.213.8.26

ssh-copy-id root@80.213.8.27

ssh-copy-id root@80.213.8.28

ssh-copy-id root@80.213.8.29

中控机自己也需要对自己做免密

五、集群初始化配置文件需要手动编写,需要在中控机上面创建 YAML 格式配置文件,例如 topology.yaml

cat topology.yaml

点击查看代码
# # Global variables are applied to all deployments and used as the default value of
# # the deployments if a specific deployment value is missing.
global:
user: "tidb"
ssh_port: 60022
deploy_dir: "/tidb-deploy"
data_dir: "/tidb-data" server_configs:
pd:
replication.enable-placement-rules: true pd_servers:
- host: 80.213.8.25
- host: 80.213.8.26
- host: 80.213.8.27
tidb_servers:
- host: 80.213.8.26
- host: 80.213.8.28
- host: 80.213.8.29
tikv_servers:
- host: 80.213.8.27
- host: 80.213.8.28
- host: 80.213.8.29 monitoring_servers:
- host: 80.213.8.25
grafana_servers:
- host: 80.213.8.25
alertmanager_servers:
- host: 80.213.8.25

六、部署 TiDB 集群

每台服务器创建tidb用户

useradd tidb

echo 'yourpasswd'|passwd --stdin tidb

export TIUP_MIRRORS=/path/to/mirror /path/to/mirror 是执行 local_install.sh 命令时输出的离线镜像包的位置

tiup cluster deploy tidb-cluster v4.0.16 topology.yaml --user root

tiup cluster start tidb-cluster

通过 TiUP cluster 部署的集群名称为 tidb-cluster

部署版本为 v4.0.16,其他版本可以执行 tiup list tidb 获取

初始化配置文件为 topology.yaml

--user tidb:通过 tidb 用户登录到目标主机完成集群部署,该用户需要有 ssh 到目标机器的权限,并且在目标机器有 sudo 权限。也可以用其他有 ssh 和 sudo 权限的用户完成部署。

预期日志结尾输出会有 Deployed cluster tidb-test successfully 关键词,表示部署成功。

七、tidb常用命令

点击查看代码
[root@localhost tidb-tiup]# tiup cluster
The component `cluster` is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/cluster-v1.0.7-linux-amd64.tar.gz 9.62 MiB / 9.62 MiB 100.00% 245.11 MiB p/s
Starting component `cluster`: /root/.tiup/components/cluster/v1.0.7/tiup-cluster
Deploy a TiDB cluster for production Usage:
tiup cluster cluster [flags]
tiup cluster [command] Available Commands:
check Perform preflight checks for the cluster.
deploy Deploy a cluster for production
start Start a TiDB cluster
stop Stop a TiDB cluster
restart Restart a TiDB cluster
scale-in Scale in a TiDB cluster
scale-out Scale out a TiDB cluster
destroy
upgrade Upgrade a specified TiDB cluster
exec Run shell command on host in the tidb cluster
display Display information of a TiDB cluster
list List all clusters
audit Show audit log of cluster operation
import Import an exist TiDB cluster from TiDB-Ansible
edit-config Edit TiDB cluster config
reload Reload a TiDB cluster's config and restart if needed
patch Replace the remote package with a specified package and restart the service
help Help about any command Flags:
-h, --help help for tiup
--ssh-timeout int Timeout in seconds to connect host via SSH, ignored for operations that don't need an SSH connection. (default 5)
-v, --version version for tiup
--wait-timeout int Timeout in seconds to wait for an operation to complete, ignored for operations that don't fit. (default 60)
-y, --yes Skip all confirmations and assumes 'yes' Use "tiup cluster help [command]" for more information about a command.

最新文章

  1. OpenNURBS to OpenCASCADE
  2. robotframework----模板的使用
  3. hdu-5525 Product(费马小定理)
  4. Linux下C++静态库、动态库的制作与使用
  5. 造成ORA-12560: TNS: 协议适配器错误的问题的原因有三个:
  6. Android Studio导入GitHub上的项目常见问题(有例子)
  7. Android(java)学习笔记68:同步代码块 和 同步方法 的应用
  8. [POJ1969]Count on Canton
  9. poj Fishnet
  10. Parrot源代码分析之海贼王
  11. Swift - 自定义函数规则说明
  12. log4go的精确定时程序(带自动延迟补偿)
  13. Java 将两个有序数组合成为一个有序数组
  14. Java finalize方法使用
  15. robotframework+selenium搭配chrome浏览器,web测试案例(搭建篇)
  16. zabbix模板
  17. Typescript 学习笔记七:泛型
  18. (5)MySQL的查询:模糊查询(通配符查询like)、限制符查询(limit)、排序查询(order by)、分组查询(group by)、(子查询)
  19. 关于lampp中的proftpd的一些使用
  20. 西数移动固态SSD

热门文章

  1. angular 引入服务报错global is not defined----angular11引入service报错Can&#39;t resolve &#39;@core/net/aa/aa.service&#39; in &#39;D:\pro&#39;
  2. node.js接收前端上传的文件并保存到其他位置+后端代码支持进度条
  3. 《深入理解Java虚拟机》第三章读书笔记(二)——HotSpot垃圾回收算法实现(OopMap,安全点安全区域,卡表,写屏障,三色标记算法)
  4. 连接KingbaseES异常,致命错误/ 用户&quot;system&quot; Password 认证失败(kbjdbc/autodetected server-encoding to be GB2312...)
  5. mysql 错误解决大法 Specified key was too long; max key length is 767 bytes
  6. vue3 ts遇到的问题
  7. 通过Nacos配置刷新进行RabbitMQ消费者在线启停
  8. P12_小程序API的3大分类
  9. day14-异常处理
  10. 跳板攻击之:NPS代理转发