作者: ShawnYan 原文来源: https://tidb.net/blog/529996b3
网传,ACE 装国产数据库花了两周,吃瓜群众纷纷表示惊讶,
都 4202 年了,DBaaS 概念已经不热了,安装数据库怎么还跟 10 年前一样需要持久战~
...
使用 TiUP 部署 TiDB v8.0.0 集群
回看两年前发的文章, TiUP:TiDBAer 必备利器
现在更加肯定 TiUP 真乃神器也,使用 TiUP 在本地模拟部署 TiDB v8.0.0 集群仅需 10 分钟。
具体演示如下:
1. 下载并安装 TiUP
- [root@shawnyan ~ 11:57:40]$ 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 5095k 100 5095k 0 0 5065k 0 0:00:01 0:00:01 --:--:-- 5069k
- Successfully set mirror to https://tiup-mirrors.pingcap.com
- Detected shell: bash
- Shell profile: /root/.bash_profile
- Installed path: /root/.tiup/bin/tiup
- ===============================================
- Have a try: tiup playground
- ===============================================
- [root@shawnyan ~ 11:57:46]$ source /root/.bash_profile
2. 调大 sshd 服务的连接数限制
由于是本地安装集群,会并发连接,调整最大会话数量到 20。
- vi /etc/ssh/sshd_config
- MaxSessions = 20
并重启 sshd 服务。
systemctl restart sshd
3. 创建集群拓扑文件
可用 tiup cluster template
命令生成拓扑模板。
[root@shawnyan ~ 11:59:00]$ vi topo.yaml
4. 部署集群
- [root@shawnyan ~ 12:00:40]$ tiup cluster deploy mytidb v8.0.0 ./topo.yaml --user root -p
- Input SSH password:
-
- + Detect CPU Arch Name
- + Detect CPU OS Name
- Please confirm your topology:
- Cluster type: tidb
- Cluster name: mytidb
- Cluster version: v8.0.0
- Role Host Ports OS/Arch Directories
- ---- ---- ----- ------- -----------
- pd 192.168.8.161 2379/2380 linux/x86_64 /tidb-deploy/pd-2379,/tidb-data/pd-2379
- tikv 192.168.8.161 20160/20180 linux/x86_64 /tidb-deploy/tikv-20160,/tidb-data/tikv-20160
- tikv 192.168.8.161 20161/20181 linux/x86_64 /tidb-deploy/tikv-20161,/tidb-data/tikv-20161
- tidb 192.168.8.161 4000/10080 linux/x86_64 /tidb-deploy/tidb-4000
- tiflash 192.168.8.161 9000/8123/3930/20170/20292/8234 linux/x86_64 /tidb-deploy/tiflash-9000,/tidb-data/tiflash-9000
- prometheus 192.168.8.161 9090/12020 linux/x86_64 /tidb-deploy/prometheus-9090,/tidb-data/prometheus-9090
- grafana 192.168.8.161 3000 linux/x86_64 /tidb-deploy/grafana-3000
- Attention:
- 1. If the topology is not what you expected, check your yaml file.
- 2. Please confirm there is no port/directory conflicts in same host.
- Do you want to continue? [y/N]: (default=N) y
- + Generate SSH keys ... Done
- + Download TiDB components
- + Initialize target host environments
- + Deploy TiDB instance
- + Copy certificate to remote host
- + Init instance configs
- + Init monitor configs
- Enabling component pd
- Enabling component tikv
- Enabling component tidb
- Enabling component tiflash
- Enabling component prometheus
- Enabling component grafana
- Enabling component node_exporter
- Enabling component blackbox_exporter
- Cluster `mytidb` deployed successfully, you can start it with command: `tiup cluster start mytidb --init`
集群安装完成,接下来启动集群。
5. 启动集群
- [root@shawnyan ~ 12:04:17]$ tiup cluster start mytidb --init
- Starting cluster mytidb...
- + [ Serial ] - SSHKeySet: privateKey=/root/.tiup/storage/cluster/clusters/mytidb/ssh/id_rsa, publicKey=/root/.tiup/storage/cluster/clusters/mytidb/ssh/id_rsa.pub
- + [Parallel] - UserSSH: user=tidb, host=192.168.8.161
- ...
- + [ Serial ] - StartCluster
- Starting component pd
- Starting component tikv
- Starting component tidb
- Starting component tiflash
- Starting component prometheus
- Starting component grafana
- Starting component node_exporter
- Starting component blackbox_exporter
- + [ Serial ] - UpdateTopology: cluster=mytidb
- Started cluster `mytidb` successfully
- The root password of TiDB database has been changed.
- The new password is: '2mKNM_976^-+1h8BEL'.
- Copy and record it to somewhere safe, it is only displayed once, and will not be stored.
- The generated password can NOT be get and shown again.
此时,TiDB 集群已启动成功,并且自动创建了 root 账号密码。
6. 查看 TiDB 集群状态
连接 TiDB,查看版本号。
- [root@shawnyan ~ 12:05:20]$ mysql -h 192.168.8.161 -P 4000 -u root -p
- Enter password:
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 3290431496
- Server version: 8.0.11-TiDB-v8.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible
-
- Copyright (c) 2000, 2024, Oracle and/or its affiliates.
-
- 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> select tidb_version()\G
- *************************** 1. row ***************************
- tidb_version(): Release Version: v8.0.0
- Edition: Community
- Git Commit Hash: 8ba1fa452b1ccdbfb85879ea94b9254aabba2916
- Git Branch: HEAD
- UTC Build Time: 2024-03-28 14:22:15
- GoVersion: go1.21.4
- Race Enabled: false
- Check Table Before Drop: false
- Store: tikv
- 1 row in set (0.00 sec)
-
- mysql> \q
- Bye
查看 TiDB 集群列表。
- [root@shawnyan ~ 12:05:46]$ tiup cluster list
- Name User Version Path PrivateKey
- ---- ---- ------- ---- ----------
- mytidb tidb v8.0.0 /root/.tiup/storage/cluster/clusters/mytidb /root/.tiup/storage/cluster/clusters/mytidb/ssh/id_rsa
查看集群拓扑结构和状态。
- [root@shawnyan ~ 12:05:54]$ tiup cluster display mytidb
- Cluster type: tidb
- Cluster name: mytidb
- Cluster version: v8.0.0
- Deploy user: tidb
- SSH type: builtin
- Dashboard URL: http://192.168.8.161:2379/dashboard
- Grafana URL: http://192.168.8.161:3000
- ID Role Host Ports OS/Arch Status Data Dir Deploy Dir
- -- ---- ---- ----- ------- ------ -------- ----------
- 192.168.8.161:3000 grafana 192.168.8.161 3000 linux/x86_64 Up - /tidb-deploy/grafana-3000
- 192.168.8.161:2379 pd 192.168.8.161 2379/2380 linux/x86_64 Up|L|UI /tidb-data/pd-2379 /tidb-deploy/pd-2379
- 192.168.8.161:9090 prometheus 192.168.8.161 9090/12020 linux/x86_64 Up /tidb-data/prometheus-9090 /tidb-deploy/prometheus-9090
- 192.168.8.161:4000 tidb 192.168.8.161 4000/10080 linux/x86_64 Up - /tidb-deploy/tidb-4000
- 192.168.8.161:9000 tiflash 192.168.8.161 9000/8123/3930/20170/20292/8234 linux/x86_64 Up /tidb-data/tiflash-9000 /tidb-deploy/tiflash-9000
- 192.168.8.161:20160 tikv 192.168.8.161 20160/20180 linux/x86_64 Up /tidb-data/tikv-20160 /tidb-deploy/tikv-20160
- 192.168.8.161:20161 tikv 192.168.8.161 20161/20181 linux/x86_64 Up /tidb-data/tikv-20161 /tidb-deploy/tikv-20161
- Total nodes: 7
- [root@shawnyan ~ 12:06:04]$
到此,仅用了不到 10 分钟,就部署完成了一套 TiDB 集群。
遥想当年写 Shell 脚本和 Ansible 脚本的岁月,有 TiUP 助力简直不要 Ti 幸福。
“带货”时间: