TIDB离线部署shell脚本(适用于麒麟和统信uos)

tidb离线安装脚本部署,适用于统信uos和麒麟系统,自用
1.下载离线安装包
推荐下载最新稳定版

TiDB 社区版 | PingCAP

https://cn.pingcap.com/product-community/

安装前去Pingcap官网查看硬件要求和机器数量要求
2. 脚本里所需内容分布,还有mariadb-client和ufw的deb包自行下载,脚本中也有提示
在这里插入图片描述
(1)其中/usr/local/ankeyin/tidb/bin/initialize.sql如下
在这里插入图片描述
(2)互信
cd /root
ssh-keygen -t rsa #一直按回车
ssh-copy-id root@“$IP” #可跟自己的安装tidb的电脑ip互信
#可拷贝/root/.ssh到/usr/local/ankeyin/tidb文件夹下,下一次其他电脑安装tidb就不用再进行上面互信操作

shell脚本如下:

#!/bin/bash
akyPath=/usr/local/ankeyin
log=/var/log/ankeyin_install.log
sqlfile=/usr/local/ankeyin/tidb/bin/initialize.sql


IP=$(hostname -I | awk '{gsub(/ +$/,""); print}')
echo "本机 IP 地址为:$IP"


chmod -R 777 /usr/local/ankeyin
#这个步骤是mariadb的deb包,可自行下载获取
cd /usr/local/ankeyin/dependent/tidb
dpkg -i *.deb

#可在TIDB官网获取离线包,放在/usr/local/ankeyin/tidb文件夹下
#tar -zxvf tidb-community-server-v8.1.0-linux-amd64.tar.gz
#tar -zxvf tidb-community-toolkit-v8.1.0-linux-amd64.tar.gz

echo "MaxSessions = 20" >> /etc/ssh/sshd_config
service sshd restart

#cd /root
#ssh-keygen -t rsa 一直按回车
#ssh-copy-id root@"$IP" 可跟自己的安装tidb的电脑ip互信
#可拷贝/root/.ssh到/usr/local/ankeyin/tidb文件夹下,下一次其他电脑安装tidb就不用再进行上面互信操作
cp -r /usr/local/ankeyin/tidb/.ssh /root/.ssh
chmod -R 700 /root/.ssh/
cd /usr/local/ankeyin/tidb/tidb-community-server-v8.1.0-linux-amd64
case $(uname -s) in
    Linux|linux) os=linux ;;
    Darwin|darwin) os=darwin ;;
    *) os= ;;
esac

if [ -z "$os" ]; then
    echo "OS $(uname -s) not supported." >&2
    exit 1
fi

case $(uname -m) in
    amd64|x86_64) arch=amd64 ;;
    arm64|aarch64) arch=arm64 ;;
    *) arch= ;;
esac

if [ -z "$arch" ]; then
    echo "Architecture  $(uname -m) not supported." >&2
    exit 1
fi
if [ -z "$TIUP_HOME" ]; then
    TIUP_HOME=$HOME/.tiup
fi
bin_dir=$TIUP_HOME/bin
mkdir -p "$bin_dir"

script_dir=/usr/local/ankeyin/tidb/tidb-community-server-v8.1.0-linux-amd64

install_binary() {
  tar -zxf "$script_dir/tiup-$os-$arch.tar.gz" -C "$bin_dir" || return 1
  # Use the offline root.json
  cp "$script_dir/root.json" "$bin_dir" || return 1
  # Remove old manifests
  rm -rf $TIUP_HOME/manifests
  return 0
}

check_depends() {
    pass=0
    command -v tar >/dev/null || {
        echo "Dependency check failed: please install 'tar' before proceeding."
        pass=1
    }
    return $pass
}

if ! check_depends; then
    exit 1
fi

if ! install_binary; then
    echo "Failed to download and/or extract tiup archive."
    exit 1
fi

chmod 755 "$bin_dir/tiup"

# telemetry is not needed for offline installations
"$bin_dir/tiup" telemetry disable

# set mirror to the local path
"$bin_dir/tiup" mirror set ${script_dir}

bold=$(tput bold 2>/dev/null)
sgr0=$(tput sgr0 2>/dev/null)

# Reference: https://stackoverflow.com/questions/14637979/how-to-permanently-set-path-on-linux-unix
shell=$(echo $SHELL | awk 'BEGIN {FS="/";} { print $NF }')
echo "Detected shell: ${bold}$shell${sgr0}"
if [ -f "${HOME}/.${shell}_profile" ]; then
    PROFILE=${HOME}/.${shell}_profile
elif [ -f "${HOME}/.${shell}_login" ]; then
    PROFILE=${HOME}/.${shell}_login
elif [ -f "${HOME}/.${shell}rc" ]; then
    PROFILE=${HOME}/.${shell}rc
else
    PROFILE=${HOME}/.profile
fi
echo "Shell profile:  ${bold}$PROFILE${sgr0}"

case :$PATH: in
    *:$bin_dir:*) : "PATH already contains $bin_dir" ;;
    *) printf 'export PATH=%s:$PATH\n' "$bin_dir" >> "$PROFILE"
        echo "$PROFILE has been modified to to add tiup to PATH"
        echo "open a new terminal or ${bold}source ${PROFILE}${sgr0} to use it"
        ;;
esac

echo "Installed path: ${bold}$bin_dir/tiup${sgr0}"
echo "==============================================="
echo "1. ${bold}source ${PROFILE}${sgr0}"
echo "2. Have a try:   ${bold}tiup playground${sgr0}"
echo "==============================================="

source $PROFILE
echo "$PROFILE has been modified to to add tiup to PATH"

cp -rp keys ~/.tiup/
tiup mirror merge /usr/local/ankeyin/tidb/tidb-community-toolkit-v8.1.0-linux-amd64
tiup mirror show
which tiup

#topo.yaml的配置文件也可在TIDB初安装的步骤中获取https://docs.pingcap.com/zh/tidb/stable/quick-start-with-tidb放置在/usr/local/ankeyin/tidb文件夹下,文章末尾也有相关配置
sed -i "s/10.0.1.1/$IP/g" /usr/local/ankeyin/tidb/topo.yaml

tiup cluster deploy master v8.1.0 /usr/local/ankeyin/tidb/topo.yaml --user root -y

tiup cluster start master --init 2>&1  | tee $log
InitialPassword=$(tail -3 $log | grep "The new password is:" | awk -F"'" '{print $2}')
echo "Detected initial password: $InitialPassword"

#可将初密码改为jq@aky#6512,此处也可以修改成别的
mysql -h "$IP"  -uroot -P 4000 -p"$InitialPassword" < $sqlfile 1> $log

tiup cluster enable master
tiup cluster display master

#这个步骤是ufw的deb包,可自行下载获取
cd /usr/local/ankeyin/dependent/ufw
dpkg -i *.deb
sudo ufw enable
sudo ufw allow 4000/tcp
sudo ufw reload

topo.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: "/usr/local/ankeyin/tidb/deploy"
 data_dir: "/usr/local/ankeyin/tidb/data"

# # Monitored variables are applied to all the machines.
monitored:
 node_exporter_port: 9091
 blackbox_exporter_port: 9115

server_configs:
 tidb:
   instance.tidb_slow_log_threshold: 300
   log.file.max-size: 100
   log.file.max-days: 3
   log.file.max-backups: 3
 tikv:
   readpool.storage.use-unified-pool: false
   readpool.coprocessor.use-unified-pool: true
   log.file.max-size: 100
   log.file.max-days: 3
   log.file.max-backups: 3
 pd:
   replication.enable-placement-rules: true
   replication.location-labels: ["host"]
   log.file.max-size: 100
   log.file.max-days: 3
   log.file.max-backups: 3
 tiflash:
   logger.level: "info"
 tiflash-learner:
   log.file.max-size: 100
   log.file.max-days: 3
   log.file.max-backups: 3
 cdc:
   log.file.max-size: 100
   log.file.max-days: 3
   log.file.max-backups: 3
pd_servers:
 - host: 10.0.1.1

tidb_servers:
 - host: 10.0.1.1

tikv_servers:
 - host: 10.0.1.1
   port: 20160
   status_port: 20180
   config:
     server.labels: { host: "logic-host-1" }

# - host: 10.0.1.1
#   port: 20161
#   status_port: 20181
#  config:
#    server.labels: { host: "logic-host-2" }

# - host: 10.0.1.1
#   port: 20162
#   status_port: 20182
#   config:
#     server.labels: { host: "logic-host-3" }

tiflash_servers:
 - host: 10.0.1.1

cdc_servers:
 - host: 10.0.1.1

monitoring_servers:
 - host: 10.0.1.1
   port: 9092
   storage_retention: 3d
   
grafana_servers:
 - host: 10.0.1.1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阮小怂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值