LoginSignup
5
4

More than 3 years have passed since last update.

TiDB 4.0 の tiup コマンド1発でローカル Linux にマルチプロセス版の DB クラスタとモニタリングツール一式をインストールする

Last updated at Posted at 2020-09-08

TiDB とは

TiDBは 中国のスタートアップ企業 PingCAP が開発したオープンソースの MySQL 互換分散SQLデータベースです。
2017年に GA になって以降も着々と開発が進められ、現在バージョン 4.0 がリリースされています。

日本ではまだ知名度は高くないですが、著名なところでは PayPay が採用したことで知られています
PayPay での TiDB なぜ選んだのか?どうやって運用しているのか?

tiup コマンド

バージョン 4.0 からは、それまでの docker や ansible といったインフラ運用、構成管理ツールに加えて、
さらに高度な自動構成を可能にしてくれる tiup コマンドがリリースされ、
そちらを使ってインストールが今後は主要になっていくと思われます。

今回、その驚ろくほど簡単な tiup を使ったシングルマシンでのインストールについて紹介します。

動作環境

  • Ubuntu 20.04
  • 無指定の Latest で今回導入されたのは tidb 4.0.5
  • (結果中の /home/nobuh は実行したユーザーのホームディレクトリです)

インストール

curl で tiup をインストールします

$ 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 4412k  100 4412k    0     0  2068k      0  0:00:02  0:00:02 --:--:-- 2068k
WARN: adding root certificate via internet: https://tiup-mirrors.pingcap.com/root.json
You can revoke this by remove /home/nobuh/.tiup/bin/7b8e153f2e2d0928.root.json
Set mirror to https://tiup-mirrors.pingcap.com success
Detected shell: bash
Shell profile:  /home/nobuh/.bashrc
/home/nobuh/.bashrc has been modified to to add tiup to PATH
open a new terminal or source /home/nobuh/.bashrc to use it
Installed path: /home/nobuh/.tiup/bin/tiup
===============================================
Have a try:     tiup playground
===============================================

.bashrc にインストールされたようなので exec $SHELL -ltiup にパスが通っているのを確認します


$ exec $SHELL -l
$ which tiup
/home/nobuh/.tiup/bin/tiup

パスが通ったら tiup playground を実行すると

  • 設定済み Prometeus と Grafana
  • クラスタ管理の Placement Driver (PD)
  • RocksDB の KVS TiKV
  • MySQL互換サーバーの TiDB
  • 列DBの TiFlash

を一気にインストールしてくれます

$ tiup playground
The component `playground` is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/playground-v1.1.1-linux-amd64.tar.gz 8.21 MiB / 8.21 MiB 100.00% 5.94 MiB p/s                                                                
Starting component `playground`: 
Use the latest stable version: v4.0.5

    Specify version manually:   tiup playground <version>
    The stable version:         tiup playground v4.0.0
    The nightly version:        tiup playground nightly

Playground Bootstrapping...
The component `prometheus` is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/prometheus-v4.0.5-linux-amd64.tar.gz 39.84 MiB / 39.84 MiB 100.00% 6.99 MiB p/s                                                              
download https://tiup-mirrors.pingcap.com/grafana-v4.0.5-linux-amd64.tar.gz 54.24 MiB / 54.24 MiB 100.00% 7.25 MiB p/s                                                                 
Start pd instance...
The component `pd` is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/pd-v4.0.5-linux-amd64.tar.gz 37.74 MiB / 37.74 MiB 100.00% 7.37 MiB p/s                                                                      
Start tikv instance...
The component `tikv` is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tikv-v4.0.5-linux-amd64.tar.gz 134.43 MiB / 134.43 MiB 100.00% 7.30 MiB p/s                                                                  
Start tidb instance...
The component `tidb` is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tidb-v4.0.5-linux-amd64.tar.gz 38.75 MiB / 38.75 MiB 100.00% 6.55 MiB p/s                                                                    
...
Waiting for tikv 127.0.0.1:20160 ready 
Start tiflash instance...
The component `tiflash` is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tiflash-v4.0.5-linux-amd64.tar.gz 352.59 MiB / 352.59 MiB 100.00% 7.70 MiB p/s                                                               
Waiting for tiflash 127.0.0.1:3930 ready ........
CLUSTER START SUCCESSFULLY, Enjoy it ^-^
To connect TiDB: mysql --host 127.0.0.1 --port 4000 -u root
To view the dashboard: http://127.0.0.1:2379/dashboard
To view the Prometheus: http://127.0.0.1:9090
To view the Grafana: http://127.0.0.1:3000

これですべて完了です。各役割のサーバーが1プロセスづつ起動されたシングルマシン、マルチプロセスの構成でクラスタが立ち上がっています。

まずは基本の mysql-client

ubuntu に mysql client をインストールします

$ sudo apt install mysql-client-core-8.0

tiup playground で起動した直後は root のパスなしでアクセスになります

$ mysql -h 127.0.0.1 --port 4000 -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.25-TiDB-v4.0.5 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> status;
--------------
mysql  Ver 8.0.21-0ubuntu0.20.04.4 for Linux on x86_64 ((Ubuntu))

Connection id:      3
Current database:   
Current user:       root@127.0.0.1
SSL:            Not in use
Current pager:      stdout
Using outfile:      ''
Using delimiter:    ;
Server version:     5.7.25-TiDB-v4.0.5 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
Protocol version:   10
Connection:     127.0.0.1 via TCP/IP
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
TCP port:       4000
Binary data as:     Hexadecimal
--------------

とりあえず status を打ってみたところですが、SQL や運用コマンドのシンタックス的には MySQL 5.7 と互換性があるかたちになっています

TiDB Dashboard

TiDB 4.0 のウリの一つが Dashboard です。http://127.0.0.1:2379/dashboard にブラウザでアクセスします。

ログインでは root のパスなしでアクセス出来ます。

クラスタの状態からクエリのパフォーマンス、スロークエリ一覧、など必要な情報にワンストップでアクセス出来るコンパネが用意されていいます。

Screenshot from 2020-09-08 23-03-32.png

分散DBの場合キーの偏り具合の維持管理が重要なポイントになりますが、そのためのツール Key Visualizer も提供されています

Screenshot from 2020-09-08 23-05-33.png

さらに詳細を確認できる設定済み Grafana

ダッシュボードに加えてさらに詳細情報もモニタリング一式が設定済みとなっている Grafana も用意されています。

http://127.0.0.1:3000/ でアクセスすると Grafana のログインになります。ユーザー admin パスワード admin で初回アクセスすると、パスワードの変更画面になりますので、お好きなパスワードを設定してください

Grafana には以下のパネルが設定済みとなっています

Screenshot from 2020-09-08 23-12-09.png

このうち Instance Memory Detail と Transaction のところを見てみるとこのようになっています。主要なものが設定済みになっていますのでとても便利です。

Screenshot from 2020-09-08 23-13-30.png

Prometeus の直接利用も可能

Dashboard に Search Logs 機能もあり、Grafana もありますのであまり使うことが無いかもしれないですが、バックエンドの Prometeus にも http://127.0.0.1:9090/ で直接アクセス可能になっています

Screenshot from 2020-09-08 23-15-24.png

まとめ

今回、TiDB の中味、SQL 的なところは触れずに、tiup playground コマンド一発ですべてのサーバーとツールが1マシン内に用意 されるところを紹介しました。

MySQL 互換のオープンソースで、ビッグデータにも対応可能な分散 SQL を手元で扱えるのはとても快感です。ぜひお試しください!

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4