TiUP를 사용하여 TiDB 클러스터 배포

실제 운영 환경에서 설치하는 방법이다.

TiUP는 TiDB 4.0에 도입된 클러스터 운영 유지보수 도구이다. TiUP는 Golang으로 작성된 클러스터 관리 구성 요소인 TiUP 클러스터 를 제공한다. TiUP 클러스터를 사용하면 TiDB 클러스터의 배포, 시작, 중지, 삭제, 스케일링 및 업그레이드를 포함한 일상적인 데이터베이스 작업을 쉽게 수행하고 TiDB 클러스터의 매개 변수를 관리할 수 있다.

TiUP는 TiDB, TiFlash, TiDB Binlog, TiCDC 및 모니터링 시스템 배포를 지원한다. 이 문서에서는 다양한 토폴로지의 TiDB 클러스터를 배포하는 방법을 소개한다.

1단계: 전제조건 및 사전 확인

다음 문서를 확인하여라.

2단계. 제어 시스템에 TiUP 배포

온라인 배포 및 오프라인 배포의 두 가지 방법 중 하나로 제어 시스템에 TiUP를 배포할 수 있다.

TiUP 도구 설치

1. TiUP 도구 설치한다.

먼저, 온라인 환경에서 다음 명령을 실행하여 TiUP을 설치한다.

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
% curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100 6988k  100 6988k    0     0  3433k      0  0:00:02  0:00:02 --:--:-- 3442k
WARN: adding root certificate via internet: https://tiup-mirrors.pingcap.com/root.json
You can revoke this by remove /Users/user/.tiup/bin/7b8e153f2e2d0928.root.json
Successfully set mirror to https://tiup-mirrors.pingcap.com
Detected shell: zsh
Shell profile:  /Users/user/.zshrc
/Users/user/.zshrc has been modified to add tiup to PATH
open a new terminal or source /Users/user/.zshrc to use it
Installed path: /Users/user/.tiup/bin/tiup
===============================================
Have a try:     tiup playground
===============================================

2. 전역 환경 변수를 다시 선언한다.

source .bash_profile
% source .bash_profile

3. TiUP이 설치되어 있는지 확인한다.

which tiup
% which tiup
/Users/user/.tiup/bin/tiup

TiUP 온라인 클러스터 배포

1. TiUP 클러스터 구성 요소를 설치한다.

tiup cluster
% tiup cluster
tiup is checking updates for component cluster ...timeout!
The component `cluster` version  is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/cluster-v1.11.0-darwin-arm64.tar.gz 8.31 MiB / 8.31 MiB 100.00% 6.73 MiB/s
Starting component `cluster`: /Users/user/.tiup/components/cluster/v1.11.0/tiup-cluster
Deploy a TiDB cluster for production

Usage:
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

... 중간 생략 ...

Use "tiup cluster help [command]" for more information about a command.

최초에 실행을 하였다면 서버에서 다운로드를 받는 것을 볼 수 있다.

2. 이미 TiUP 클러스터가 설치가 되어 있다면 아래와 같이 TiUP 명령어로 구성 요소를 최신 버전으로 업데이트한다.

tiup update --self && tiup update cluster
% tiup update --self && tiup update cluster
download https://tiup-mirrors.pingcap.com/tiup-v1.11.0-darwin-arm64.tar.gz 6.82 MiB / 6.82 MiB 100.00% 2.76 MiB/s
Updated successfully!
component cluster version v1.11.0 is already installed
Updated successfully!

위와 같이 “Update successfully!” 표시되었다면, TiUP 클러스터가 성공적으로 업데이트된 것이다.

3. TiUP 클러스터의 현재 버전을 확인한다.

tiup --binary cluster
% tiup --binary cluster
/Users/user/.tiup/components/cluster/v1.11.0/tiup-cluster

TiUP 오프라인 클러스터 배포

TiUP을 사용하여 오프라인 환경에서 TiDB 클러스터를 배포하려면 아래와 같이 수행한다.

1. TiUP 오프라인 구성 요소 패키지 준비

TiUP 오프라인 구성 요소 패키지를 준비하려면, tiup mirror clone를 사용하여 오프라인 구성 요소 패키지를 가져올 수 있다.

1-1. TiUP을 사용하여 mirror를 받아온다.

인터넷에 접근이 가능한 시스템에서 필요한 구성 요소를 가져온다.

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

실제 실행하면 아래와 같이 수행된다.

% tiup mirror clone tidb-community-server-v1.11.0-linux-amd64 v1.11.0 --os=linux --arch=amd64
Start to clone mirror, targetDir is tidb-community-server-v1.11.0-linux-amd64, source mirror is https://tiup-mirrors.pingcap.com, selectedVersions are [v1.11.0]
If this does not meet expectations, please abort this process, read `tiup mirror clone --help` and run again
Arch [amd64]
OS [linux]
PCC linux/amd64 v1.11.0 not found, using 1.0.1 instead.
alertmanager linux/amd64 v1.11.0 not found, using v0.17.0 instead.
blackbox_exporter linux/amd64 v1.11.0 not found, using v0.21.1 instead.
br linux/amd64 v1.11.0 not found, using v6.3.0 instead.

... 중간 생략 ...

download https://tiup-mirrors.pingcap.com/tispark-v2.4.1-any-any.tar.gz 22.36 MiB / 22.36 MiB 100.00% 8.30 MiB/s
download https://tiup-mirrors.pingcap.com/tiup-v1.11.0-linux-amd64.tar.gz 6.92 MiB / 6.92 MiB 100.00% 5.94 MiB/s
download https://tiup-mirrors.pingcap.com/tiup-linux-amd64.tar.gz 6.92 MiB / 6.92 MiB 100.00% 5.84 MiB/s

위 명령은 현재 디렉터리 tidb-community-server-${version}-linux-amd64라는 디렉터리를 만든다. 이 디렉터리에는 클러스터를 시작하는데 필요한 구성 요소 패키지가 포함되어 있다.

1-2. tar 명령을 사용하여 구성 요소 패키지를 압축하여 격리된 환경의 제어 컴퓨터로 패키지를 전송한다.
tar czvf tidb-community-server-${version}-linux-amd64.tar.gz tidb-community-server-${version}-linux-amd64
% tar czvf tidb-community-server-v1.11.0-linux-amd64.tar.gz tidb-community-server-v1.11.0-linux-amd64

압축으로 생성된 tidb-community-server-${version}-linux-amd64.tar.gz파일은 독립적인 오프라인 환경 패키지이다.

1-3. 오프라인 미러를 사용자 지정하거나, 기존 오프라인 미러의 내용을 조정한다.

기존 오프라인 미러를 조정하려면(예: 구성 요소의 새 버전 추가) 다음 단계를 수행한다.

오프라인 미러를 가져올 때 구성 요소 및 버전 정보와 같은 매개 변수를 통해 특정 정보를 지정하여 불완전한 오프라인 미러를 얻을 수 있다.
예를 들어, 다음 명령을 실행하여 TiUP v1.10.0와 TiUP Cluster v1.10.0의 오프라인 미러만 포함하는 오프라인 미러를 가져올 수 있다.

tiup mirror clone tiup-custom-mirror-v1.10.0 --tiup v1.10.0 --cluster v1.10.0

--os 특정 플랫폼에 대한 구성 요소만 필요한 경우 또는 --arch 매개 변수를 사용하여 지정할 수 있다.

앞에 “1-2"를 참조하여, 이 미완성의 오프라인 미러를 격리된 환경의 제어 시스템에 전송한다.

격리된 환경에서 제어 시스템의 현재 오프라인 미러 경로를 확인한다. TiUP 도구가 최신 버전인 경우에는 다음 명령을 실행하여 현재 미러 주소를 가져올 수 있다.

tiup mirror show
% tiup mirror show
https://tiup-mirrors.pingcap.com

위 명령의 출력에 해당 show 명령이 없다고 표시되었다면, 이전 버전의 TiUP를 사용 중일 수 있다.
그런 경우에는 $HOME/.tiup/tiup.toml파일 내용을 확인하면, 현재 미러 주소를 확인할 수 있다.

% cat ~/.tiup/tiup.toml
mirror = "https://tiup-mirrors.pingcap.com"

이 미러 주소를 기록해 두어라. 다음 단계에서 ${base_mirror} 이 주소를 참조하는 데 사용된다.

미완성된 오프라인 미러를 기존 오프라인 미러에 병합한다. 먼저 현재 오프라인 미러의 keys디렉터리를 $HOME/.tiup 디렉터리에 복사한다.

cp -r ${base_mirror}/keys $HOME/.tiup/

그런 다음 TiUP 명령을 사용하여 미완성된 오프라인 미러를 사용 중인 미러에 병합한다.

tiup mirror merge tiup-custom-mirror-v1.10.0

위 단계가 완료되면 tiup list 명령을 실행하여 결과를 확인한다. 이 문서의 예에서는 tiup list tiup, tiup list cluster 클러스터의 출력은 v1.10.0의 해당 구성 요소를 사용할 수 있음을 보여준다.

오프라인 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 명령을 실행한다.

3단계. 클러스터 토폴로지 파일 초기화

다음 명령을 실행하여 클러스터 토폴로지 파일을 만든다.

tiup cluster template > topology.yaml
% tiup cluster template > topology.yaml
tiup is checking updates for component cluster ...
Starting component `cluster`: /Users/user/.tiup/components/cluster/v1.11.0/tiup-cluster template

다음 두 가지 일반적인 시나리오에서는 명령을 실행하여 권장되는 토폴로지 템플릿을 생성할 수 있다.

  • 하이브리드 배포의 경우: 여러 인스턴스가 단일 컴퓨터에 배포된다. 자세한 내용은 하이브리드 배포 토폴로지를 참조하여라.
    tiup cluster template --full > topology.yaml
    
  • 지리적으로 분산된 배포의 경우: TiDB 클러스터는 지리적으로 분산된 데이터 센터에 배포된다. 자세한 내용은 지리적으로 분산된 배포 토폴로지를 참조하여라.
    tiup cluster template --multi-dc > topology.yaml
    

cat topology.yaml를 실행하여 구성 파일의 내용을 확인한다. 파일에 주석을 내용을 빼면 아래와 같다.

global:
  user: "tidb"
  ssh_port: 22
  deploy_dir: "/tidb-deploy"
  data_dir: "/tidb-data"
server_configs: {}
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
monitoring_servers:
  - host: 10.0.1.4
grafana_servers:
  - host: 10.0.1.4
alertmanager_servers:
  - host: 10.0.1.4

4단계. 배포 명령 실행

deploy명령을 실행하기 전에 check및 check –apply명령을 사용하여 클러스터의 잠재적 위험을 감지하고 자동으로 복구한다.

  1. 잠재적 위험을 확인한다.
    tiup cluster check ./topology.yaml --user root [-p] [-i /home/root/.ssh/gcp_rsa]
    
  2. 자동 복구를 사용한다.
    tiup cluster check ./topology.yaml --apply --user root [-p] [-i /home/root/.ssh/gcp_rsa]
    
  3. TiDB 클러스터를 배포한다.
    tiup cluster deploy tidb-test v6.0.0 ./topology.yaml --user root [-p] [-i /home/root/.ssh/gcp_rsa]
    

위의 tiup cluster deploy명령으로 :

  • `tidb-test는 배포할 TiDB 클러스터의 이름이다.
  • v6.1.0는 배포할 TiDB 클러스터의 버전이다. tiup list tidb실행하면 지원되는 최신 버전을 확인할 수 있다.
  • topology.yaml는 초기 설정 파일이다.
  • --user root는 대상 컴퓨터에 root사용자로 로그인하여 클러스터 배포를 완료함을 나타낸다. root 사용자는 대상 컴퓨터에 ssh에 대한 sudo 권한이 있어야 한다. 또는 권한이 ssh 있는 sudo 다른 사용자를 사용하여 배포를 완료할 수 있다.
  • [-i][-p]선택 사항입니다. 암호 없이 대상 컴퓨터에 로그인을 설정한 경우에는 이러한 매개 변수가 필요하지 않습니다. 그렇지 않은 경우 두 매개 변수 중 하나를 선택합니다. [-i]는 대상 시스템에 액세스할 수 있는 루트 사용자(또는 –user지정된 다른 사용자)의 개인 키입니다. [-p]는 대화식으로 사용자 암호를 입력하는 데 사용된다. 출력 로그 끝에 Deployed cluster tidb-test successfully가 표시됩니다. 이는 배포가 성공했음을 나타낸다.

5단계. TiUP에서 관리하는 클러스터 확인

tiup cluster list

TiUP는 여러 TiDB 클러스터의 관리를 지원한다. 위의 명령은 TiUP에서 현재 관리하는 모든 클러스터에 대한 정보를 출력한다. 여기에는 클러스터 이름, 배포 사용자, 버전 및 개인 키 정보가 포함된다.

6단계. 배포된 TiDB 클러스터의 상태 확인

예를 들어, 다음 명령을 실행하여 tidb-test 클러스터의 상태를 확인한다.

tiup cluster display tidb-test

예상되는 출력에는 인스턴스 ID, 역할, 호스트, 수신 대기 포트, 상태(클러스터가 아직 시작되지 않았기 때문에 상태는 Down/inactive이다) 및 디렉터리 정보가 포함된다.

7단계. TiDB 클러스터 시작

TiUP cluster v1.9.0부터 새로운 시작 방법으로 안전 시작이 도입되었다. 이 방법으로 데이터베이스를 시작하면 데이터베이스 보안이 향상된다. 이 방법을 사용하는 것이 좋다.

안전한 시작 후 TiUP는 TiDB 루트 사용자의 암호를 자동으로 생성하고 명령줄 인터페이스에서 암호를 반환한다.

방법 1: 안전한 시작

tiup cluster start tidb-test --init

출력이 다음과 같으면 시작이 성공한 것이다.

Started cluster `tidb-test` successfully.
The root password of TiDB database has been changed.
The new password is: 'y_+3Hwp=*AWz8971s6'.
Copy and record it to somewhere safe, it is only displayed once, and will not be stored.
The generated password can NOT be got again in future.

방법 2: 표준 시작

tiup cluster start tidb-test

출력 로그에 Started cluster 'tidb-test' successfully가 포함되어 있으면 시작이 성공한 것이다. 표준 시작 후 암호 없이 루트 사용자를 사용하여 데이터베이스에 로그인할 수 있다.

8단계. TiDB 클러스터의 실행 상태 확인

tiup cluster display tidb-test

출력 로그에 Up 상태가 표시되면 클러스터가 제대로 작동하는 것이다.

참조




최종 수정 : 2022-11-19