【TiDB】07-tiup工具安装及使用

目录

1、在线安装

1.2、脚本代码如下 

2、离线安装

2.1、下载安装包

2.2、安装脚本

3、卸载

4、常用命令


TiDB 提供了丰富的工具,可以帮助你进行部署运维、数据管理(例如,数据迁移、备份恢复、数据校验)、在 TiKV 上运行 Spark SQL。请根据需要选择适用的工具。

TiUP 是在物理机或虚拟机上的 TiDB 包管理器,管理着 TiDB 的众多的组件,如 TiDB、PD、TiKV 等。当你想要运行 TiDB 生态中任何组件时,只需要执行一行 TiUP 命令即可。

TiUP cluster 是 TiUP 提供的使用 Golang 编写的集群管理组件,通过 TiUP cluster 组件就可以进行日常的运维工作,包括部署、启动、关闭、销毁、弹性扩缩容、升级 TiDB 集群,以及管理 TiDB 集群参数。

基本信息:

1、在线安装

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

默认安装路径 /root/.tiup

命令执行成功后,需要手动让环境变量生效

source /root/.bashrc

1.2、脚本代码如下 

#!/bin/sh

repo='https://tiup-mirrors.pingcap.com'
if [ -n "$TIUP_MIRRORS" ]; then
    repo=$TIUP_MIRRORS
fi

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"

# https://tiup-mirrors.pingcap.com/tiup-linux-amd64.tar.gz?20240812112625
install_binary() {
    curl "$repo/tiup-$os-$arch.tar.gz?$(date "+%Y%m%d%H%M%S")" -o "/tmp/tiup-$os-$arch.tar.gz" || return 1
    tar -zxf "/tmp/tiup-$os-$arch.tar.gz" -C "$bin_dir" || return 1
    rm "/tmp/tiup-$os-$arch.tar.gz"
    return 0
}

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

chmod 755 "$bin_dir/tiup"

"$bin_dir/tiup" mirror set $repo

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

# Refrence: 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 '\nexport PATH=%s:$PATH\n' "$bin_dir" >> "$PROFILE"
        echo "$PROFILE has been modified 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 "Have a try:     ${bold}tiup playground${sgr0}"
echo "==============================================="

2、离线安装

借由1.2中的代码整理

2.1、下载安装包

根据实际服务器的操作系统与内核,兼容amd、arm

https://tiup-mirrors.pingcap.com/tiup-linux-amd64.tar.gz?20240812112625

2.2、安装脚本

安装位置只能是 /root/.tiup

将2.1的安装包与执行脚本放在同一目录下

然后执行

sh install.sh
#!/bin/sh

repo='https://tiup-mirrors.pingcap.com'
if [ -n "$TIUP_MIRRORS" ]; then
    repo=$TIUP_MIRRORS
fi

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"

install_binary() {
    #curl "$repo/tiup-$os-$arch.tar.gz?$(date "+%Y%m%d%H%M%S")" -o "/tmp/tiup-$os-$arch.tar.gz" || return 1
    tar -zxf "./tiup-$os-$arch.tar.gz" -C "$bin_dir" || return 1
    # rm "/tmp/tiup-$os-$arch.tar.gz"
    return 0
}

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

chmod 755 "$bin_dir/tiup"

"$bin_dir/tiup" mirror set $repo

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

# Refrence: 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 '\nexport PATH=%s:$PATH\n' "$bin_dir" >> "$PROFILE"
        echo "$PROFILE has been modified to add tiup to PATH"
        echo "open a new terminal or ${bold}source ${PROFILE}${sgr0} to use it"
        ;;
esac

source ${PROFILE}

echo "Installed path: ${bold}$bin_dir/tiup${sgr0}"
echo "==============================================="
echo "Have a try:     ${bold}tiup playground${sgr0}"
echo "==============================================="

3、卸载

tiup uninstall --all
tiup uninstall --self

然后根据提示,删除缓存目录

最后移除 环境变量配置

vim /root/.bashrc

4、常用命令

  • 可用的命令
    • install:用于安装组件
    • list:查看可用组件列表
    • uninstall:卸载组件
    • update:更新组件版本
    • status:查看组件运行记录
    • clean:清除组件运行记录
    • mirror:从官方镜像克隆一个私有镜像
    • help:输出帮助信息
  • 可用的组件
    • playground:在本机启动集群
    • client:连接本机的集群
    • cluster:部署用于生产环境的集群
    • bench:对数据库进行压力测试

4.1、修改集群配置

# 进入修改配置页面,操作与Vim编辑器一致
# 注意输入 Y
tiup cluster edit-config cluster-name 

# 保存退出后
tiup cluster reload  cluster-name  [-N <nodes>] [-R <roles>]

参考文章:

TiDB 工具功能概览 | PingCAP 归档文档站

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

宣晨光

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

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

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

打赏作者

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

抵扣说明:

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

余额充值