以下の内容はhttps://dshimizu.hatenablog.com/entry/2024/05/05/220000より取得しました。


TiDB を Amazon Linux 2023 にインストールして触ってみた

TiDB を Amazon Linux 2023 にインストールして触ってみました。

TiDB とは

TiDBは、PingCAP社が開発しているオープンソースMySQL互換データベースで、分散データベースと呼ばれるものになるようです。

TiDB のアーキテクチャ

概要図はドキュメントやGitHubに記載されていました。

コンポーネントについてはまだ詳しくわかってませんが、ざっくり以下のような役割を持つものであるようです。

  • TiDB server ... SQL リクエストを受け付けるコンポーネントのようで、主にはプロキシのような役割なのかと思います
  • Placement Driver (PD) server ... PDサーバーはクラスタマネージャーの役割で、クラスターのメタデータ、TiKVノードに対する配置するデータのスケジューリングや負荷分散を管理するものであるようです。クラスターを組むためには奇数台配置する必要があるようです
  • Storage server

試す

とりあえず手元でインストールして触れるようにしてみます。

環境

インストールした環境は下記のようなものです。

$ cat /etc/amazon-linux-release
Amazon Linux release 2023.4.20240513 (Amazon Linux)

$ uname -a
Linux ip-172-26-9-142.ap-northeast-1.compute.internal 6.1.90-99.173.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May  7 11:11:31 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
$ cat /proc/meminfo | grep MemT
MemTotal:       16157992 kB
$ cat /proc/cpuinfo | grep CPU
model name  : Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
model name  : Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
model name  : Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
model name  : Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz

下記の要求スペックを見るとかなりのリソースが必要そうですが、まっさらな状態のAmazon Linux 2023で一応動きました。

インストール

以下を見るとローカルでテストクラスターを起動するスクリプトが用意されているようです。これを使ってみます。

スクリプトを取得して実行します。

$ 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 5152k  100 5152k    0     0  41.4M      0 --:--:-- --:--:-- --:--:-- 41.5M
WARN: adding root certificate via internet: https://tiup-mirrors.pingcap.com/root.json
You can revoke this by remove /home/ec2-user/.tiup/bin/7b8e153f2e2d0928.root.json
Successfully set mirror to https://tiup-mirrors.pingcap.com
Detected shell: bash
Shell profile:  /home/ec2-user/.bash_profile
/home/ec2-user/.bash_profile has been modified to add tiup to PATH
open a new terminal or source /home/ec2-user/.bash_profile to use it
Installed path: /home/ec2-user/.tiup/bin/tiup
===============================================
Have a try:     tiup playground
===============================================

シェルを再読み込みします。

$ source ~/.bash_profile

起動

起動してみます。 以下のコマンドを実行すると 1 つの TiDB インスタンス、1 つの TiKV インスタンス、1 つの PD インスタンス、および 1 つの TiFlash インスタンスを含む最新バージョンの TiDB クラスターを起動することになるようです。

$ tiup playground

A new version of playground is available:  -> v1.15.1

    To update this component:   tiup update playground
    To update all components:   tiup update --all

The component `playground` version  is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/playground-v1.15.1-linux-amd64.tar.gz 8.15 MiB / 8.15 MiB 100.00% ? MiB/s

Note: Version constraint  is resolved to v8.0.0. If you'd like to use other versions:

    Use exact version:      tiup playground v7.1.0
    Use version range:      tiup playground ^5
    Use nightly:            tiup playground nightly

Start pd instance:v8.0.0
The component `pd` version v8.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/pd-v8.0.0-linux-amd64.tar.gz 51.42 MiB / 51.42 MiB 100.00% 476.90 MiB/s
Start tikv instance:v8.0.0
The component `tikv` version v8.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tikv-v8.0.0-linux-amd64.tar.gz 301.35 MiB / 301.35 MiB 100.00% 216.42 MiB/s
Start tidb instance:v8.0.0
The component `tidb` version v8.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tidb-v8.0.0-linux-amd64.tar.gz 80.72 MiB / 80.72 MiB 100.00% 315.64 MiB/s
Waiting for tidb instances ready
127.0.0.1:4000 ... Done
The component `prometheus` version v8.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/prometheus-v8.0.0-linux-amd64.tar.gz 121.03 MiB / 121.03 MiB 100.00% 155.93 MiB/s
download https://tiup-mirrors.pingcap.com/grafana-v8.0.0-linux-amd64.tar.gz 50.16 MiB / 50.16 MiB 100.00% 745.46 MiB/s
Start tiflash instance:v8.0.0
The component `tiflash` version v8.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tiflash-v8.0.0-linux-amd64.tar.gz 251.36 MiB / 251.36 MiB 100.00% 208.15 MiB/s
Waiting for tiflash instances ready
127.0.0.1:3930 ... Done

🎉 TiDB Playground Cluster is started, enjoy!

Connect TiDB:    mysql --comments --host 127.0.0.1 --port 4000 -u root
TiDB Dashboard:  http://127.0.0.1:2379/dashboard
Grafana:         http://127.0.0.1:3000

起動したプロセスを見ると、TiDB のコンポーネントの他に prometheus や grafana が実行されていました。

ec2-user   70213  0.0  0.0 1240364 15920 pts/0   Sl+  00:32   0:00  |           \_ tiup playground
ec2-user   70223  0.1  0.1 1253220 30332 pts/0   Sl+  00:32   0:00  |               \_ /home/ec2-user/.tiup/components/playground/v1.15.1/tiup-playground
ec2-user   70233  5.3  0.8 11496500 135032 pts/0 Sl   00:32   0:19  |                   \_ /home/ec2-user/.tiup/components/pd/v8.0.0/pd-server --name=pd-0 --config=/home/ec2-user/.tiup/data/UCtQ4i4/pd-0/pd.toml --data-dir=/home/ec2-user/.tiup/data/UCtQ4i4/pd-0/data --peer-urls=http://127.0.0.1:2380 --advertise-peer-urls=http://127.0.0.1:2380 --client-urls=http://127.0.0.1:2379 --advertise-client-urls=http://127.0.0.1:2379 --log-file=/home/ec2-user/.tiup/data/UCtQ4i4/pd-0/pd.log --config=/home/ec2-user/.tiup/data/UCtQ4i4/pd-0/pd.toml --initial-cluster=pd-0=http://127.0.0.1:2380
ec2-user   70239  5.4 11.7 3482488 1893480 pts/0 Sl   00:32   0:19  |                   \_ /home/ec2-user/.tiup/components/tikv/v8.0.0/tikv-server --addr=127.0.0.1:20160 --advertise-addr=127.0.0.1:20160 --status-addr=127.0.0.1:20180 --pd-endpoints=http://127.0.0.1:2379 --config=/home/ec2-user/.tiup/data/UCtQ4i4/tikv-0/tikv.toml --data-dir=/home/ec2-user/.tiup/data/UCtQ4i4/tikv-0/data --log-file=/home/ec2-user/.tiup/data/UCtQ4i4/tikv-0/tikv.log
ec2-user   70258  5.7  2.1 2270976 344060 pts/0  Sl   00:32   0:21  |                   \_ /home/ec2-user/.tiup/components/tidb/v8.0.0/tidb-server -P 4000 --store=tikv --host=127.0.0.1 --status=10080 --path=127.0.0.1:2379 --log-file=/home/ec2-user/.tiup/data/UCtQ4i4/tidb-0/tidb.log --config=/home/ec2-user/.tiup/data/UCtQ4i4/tidb-0/tidb.toml
ec2-user   70395  1.0  1.2 1453084 198192 pts/0  Sl   00:33   0:03  |                   \_ /home/ec2-user/.tiup/components/prometheus/v8.0.0/prometheus/prometheus --config.file=/home/ec2-user/.tiup/data/UCtQ4i4/prometheus/prometheus.yml --web.external-url=http://127.0.0.1:9090 --web.listen-address=127.0.0.1:9090 --storage.tsdb.path=/home/ec2-user/.tiup/data/UCtQ4i4/prometheus/data
ec2-user   70396  0.9  0.4 4322212 71248 pts/0   Sl   00:33   0:03  |                   \_ /home/ec2-user/.tiup/components/prometheus/v8.0.0/ng-monitoring-server --pd.endpoints=127.0.0.1:2379 --address=127.0.0.1:12020 --advertise-address=127.0.0.1:12020 --storage.path=/home/ec2-user/.tiup/data/UCtQ4i4/prometheus/data --log.path=/home/ec2-user/.tiup/data/UCtQ4i4/prometheus/logs
ec2-user   70419  2.4  0.4 1753544 78312 pts/0   Sl   00:33   0:08  |                   \_ /home/ec2-user/.tiup/components/grafana/v8.0.0/bin/grafana-server --homepath /home/ec2-user/.tiup/data/UCtQ4i4/grafana --config /home/ec2-user/.tiup/data/UCtQ4i4/grafana/conf/custom.ini cfg:default.paths.logs=/home/ec2-user/.tiup/data/UCtQ4i4/grafana/log
ec2-user   70426 10.4  2.4 10353200 391856 pts/0 Sl   00:33   0:36  |                   \_ /home/ec2-user/.tiup/components/tiflash/v8.0.0/tiflash/tiflash server --config-file=/home/ec2-user/.tiup/data/UCtQ4i4/tiflash-0/tiflash.toml -- --path=/home/ec2-user/.tiup/data/UCtQ4i4/tiflash-0/data --listen_host=127.0.0.1 --logger.log=/home/ec2-user/.tiup/data/UCtQ4i4/tiflash-0/tiflash.log --logger.errorlog=/home/ec2-user/.tiup/data/UCtQ4i4/tiflash-0/tiflash_error.log --status.metrics_port=8234 --flash.service_addr=127.0.0.1:3930 --raft.pd_addr=127.0.0.1:2379 --flash.proxy.addr=127.0.0.1:20170 --flash.proxy.advertise-addr=127.0.0.1:20170 --flash.proxy.status-addr=127.0.0.1:20292 --flash.proxy.data-dir=/home/ec2-user/.tiup/data/UCtQ4i4/tiflash-0/proxy_data --flash.proxy.log-file=/home/ec2-user/.tiup/data/UCtQ4i4/tiflash-0/tiflash_tikv.log

接続

$ tiup client

A new version of client is available:  -> v1.15.1

    To update this component:   tiup update client
    To update all components:   tiup update --all

The component `client` version  is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/client-v1.15.1-linux-amd64.tar.gz 4.81 MiB / 4.81 MiB 100.00% ? MiB/s
Starting component client: /home/ec2-user/.tiup/components/client/v1.15.1/tiup-client
Connected with driver mysql (8.0.11-TiDB-v8.0.0)
Type "help" for help.

my:root@127.0.0.1:4000=>
my:root@127.0.0.1:4000=>  select version();
     version()
--------------------
 8.0.11-TiDB-v8.0.0
(1 row)

片付け

以下のコマンドで、インストールしたコンポーネントを削除できるようです。

% tiup uninstall --all
Uninstalled all components successfully!

参考




以上の内容はhttps://dshimizu.hatenablog.com/entry/2024/05/05/220000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14