LoginSignup
4
2

TiDB 入門

Last updated at Posted at 2024-01-30

TiDBとは?

「TiDBはMySQL互換のスケーラブルなデータベースです。」(引用)
TiDBは既存のMySQLにはないNoSQLのようなスケーラビリティーや便利性を追求したRDBMSです。
-> 詳しくは Sakura Internet の記事をご覧ください。

TiDBの仕組み

TiDBには大まかに3つのコンポーネントがあります。(引用)

  • PD
    • クラスターのマスター的なコンポーネント
    • データの配置決めなど
    • トランザクションの管理など
  • TiDB
    • ここでのTiDBはコンポーネントの名前
    • SQLの解釈と処理
  • TiKV/TiFlash
    • レコードやインデックスを Key/Value として保存

構成

tidb-sakura-iaas.png

TiDB構築

1. tiup インストール

tiup のインストールはTiDBの管理用の端末に行ってください。
クラスターのノードに tiup を入れておく必要はありません。

#!/bin/fish
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
fish_add_path ~/.tiup/bin/
tiup completions fish > ~/.config/fish/completions/tiup.fish

2. ssh鍵をクラスターのノードに登録

クラスターの全てのノードに登録。

#!/bin/fish
ssh-keygen -t ed25519
ssh-copy-id -i ~/.ssh/id_ed25519.pub [リモートユーザー]@[リモートサーバーのホスト名]

3. tiup でデプロイ

#!/bin/fish
## Install cluster component
tiup cluster

## Update component
tiup update --self && tiup update cluster

## Check current version
tiup --binary cluster

## Create cluster topology file
tiup cluster template > topology.yaml

topology.yaml は下記のように記述し、適切に編集してください。

global:
  user: "tidb"
  ssh_port: 22
  deploy_dir: "/tidb-deploy"
  data_dir: "/tidb-data"
  listen_host: 10.0.1.10
server_configs: {}
pd_servers:
  - host: 10.0.1.10
tidb_servers:
  - host: 10.0.1.10
tikv_servers:
  - host: 10.0.1.11
  - host: 10.0.1.12
  - host: 10.0.1.13
monitoring_servers:
  - host: 10.0.1.10
grafana_servers:
  - host: 10.0.1.10
alertmanager_servers:
  - host: 10.0.1.10
#!/bin/bash
export SSH_USER=ubuntu
export SSH_IDF="~/.ssh/id_ed25519"
tiup cluster deploy tidb v7.5.0 ./topology.yaml --user $SSH_USER -i $SSH_IDF
tiup cluster start tidb
## `--init` を追加するとrootにパスワードが付与されます

これで完了!

4
2
1

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
4
2