首页 > 其他分享 >Tiup离线安装TIDB集群4.0.16版本

Tiup离线安装TIDB集群4.0.16版本

时间:2023-01-13 10:24:05浏览次数:59  
标签:10.0 4.0 16 tiup TiDB 离线 cluster host tidb

环境: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 [email protected] #输入密码配置免密登陆
ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]

五、集群初始化配置文件需要手动编写,需要在中控机上面创建 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: 22
  deploy_dir: "/tidb-deploy"
  data_dir: "/tidb-data"

server_configs:
  pd:
    replication.enable-placement-rules: true

pd_servers:
  - host: 10.0.1.4
  - host: 10.0.1.5
  - host: 10.0.1.6
tidb_servers:
  - host: 10.0.1.7
  - host: 10.0.1.8
  - host: 10.0.1.9
tikv_servers:
  - host: 10.0.1.1
  - host: 10.0.1.2
  - host: 10.0.1.3
tiflash_servers:
  - host: 10.0.1.10
    data_dir: /data1/tiflash/data,/data2/tiflash/data
cdc_servers:
  - host: 10.0.1.6
  - host: 10.0.1.7
  - host: 10.0.1.8
monitoring_servers:
  - host: 10.0.1.4
grafana_servers:
  - host: 10.0.1.4
alertmanager_servers:
  - host: 10.0.1.4

六、部署 TiDB 集群

useradd tidb

每台服务器创建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 tidb
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.

标签:10.0,4.0,16,tiup,TiDB,离线,cluster,host,tidb
From: https://www.cnblogs.com/chunjeh/p/17046972.html

相关文章