How to Quick Install MySQL TiDB on a Single Instance.

原理架構什麼的,不在這次討論範圍

就是先試試 Pingcap TiDB 的初次體驗而已

安裝方式很多種,要用 Ansible deploy 也可以,直接執行也沒問題

就是先在 Single VM Instance (1 core / 1G Ram / 8G Disk on SSD) 上先測試一下 TiDB 長什麼樣子

先把檔案抓回來,撰文時的 latest 已經是 TiDB v3.0.14

wget http://download.pingcap.org/tidb-latest-linux-amd64.tar.gz
wget http://download.pingcap.org/tidb-latest-linux-amd64.sha256
sha256sum -c tidb-latest-linux-amd64.sha256

tar -xzf tidb-latest-linux-amd64.tar.gz

環境設定部署一下

tee -a /etc/security/limits.d/tidb.conf <<EOF
root        soft        nofile        1000000
root        hard        nofile        1000000
root        soft        core          unlimited
root        soft        stack         10240
EOF

tee -a /etc/sysctl.conf <<EOF
net.core.somaxconn=32768
vm.swappiness=0
net.ipv4.tcp_syncookies=0
fs.file-max=1000000
EOF

sysctl -w net.core.somaxconn=32768
sysctl -w vm.swappiness=0
sysctl -w net.ipv4.tcp_syncookies=0
sysctl -w fs.file-max=1000000

接著把服務執行起來就好,有空的話,再看看 log 裡面發生了什麼事

./tidb-v3.0.14-linux-amd64/bin/pd-server --data-dir=pd --log-file=pd.log &
./tidb-v3.0.14-linux-amd64/bin/tikv-server --pd="127.0.0.1:2379" --data-dir=tikv --log-file=tikv.log &
./tidb-v3.0.14-linux-amd64/bin/tidb-server --store=tikv --path="127.0.0.1:2379" --log-file=tidb.log &

個人習慣 mycli, 改用 port 4000 接入,預設 root 也不用密碼,就能看到 mysql 5.7.25-TiDB-v3.0.14 的基礎資訊了

$ mycli -h 192.168.1.1 --port=4000 -uroot
mysql 5.7.25-TiDB-v3.0.14
mycli 1.20.1
Chat: https://gitter.im/dbcli/mycli
Mail: https://groups.google.com/forum/#!forum/mycli-users
Home: http://mycli.net
Thanks to the contributor - Mike Palandra
mysql root@192.168.1.1:(none)>

default schema 也不陌生,就是大小寫的差異而已

mysql root@192.168.1.1:(none)> show databases;
+--------------------+
| Database           |
+--------------------+
| INFORMATION_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql              |
| test               |
+--------------------+
4 rows in set
Time: 0.056s

先試試看塞個 50 萬筆資料

sysbench /usr/share/sysbench/oltp_read_write.lua \
--tables=5 \
--table_size=100000 \
--mysql-host=192.168.1.1 \
--mysql-port=4000 \
--mysql-user=root \
--mysql-db=test \
--threads=5 \
prepare

結果需要 5min

$ time sysbench /usr/share/sysbench/oltp_read_write.lua --tables=5 --table_size=100000 --mysql-host=192.168.1.1 --mysql-port=4000 --mysql-user=root --mysql-db=test
--threads=5 prepare
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Initializing worker threads...

Creating table 'sbtest2'...
Creating table 'sbtest5'...
Creating table 'sbtest3'...
Creating table 'sbtest4'...
Creating table 'sbtest1'...
Inserting 100000 records into 'sbtest2'
Inserting 100000 records into 'sbtest1'
Inserting 100000 records into 'sbtest4'
Inserting 100000 records into 'sbtest5'
Inserting 100000 records into 'sbtest3'
Creating a secondary index on 'sbtest2'...
Creating a secondary index on 'sbtest1'...
Creating a secondary index on 'sbtest4'...
Creating a secondary index on 'sbtest5'...
Creating a secondary index on 'sbtest3'...

real    5m43.113s
user    0m2.182s
sys     0m0.278s

相較預設的 mysql 5.7,沒有比較就沒有傷害

$ time sysbench /usr/share/sysbench/oltp_read_write.lua --tables=5 --table_size=100000 --mysql-host=192.168.1.2 --mysql-port=3306 --mysql-password=0000 --mysql-user=root --mysql-db=test --threads=5 prepare
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)

Initializing worker threads...

Creating table 'sbtest5'...
Creating table 'sbtest1'...
Creating table 'sbtest3'...
Creating table 'sbtest2'...
Creating table 'sbtest4'...
Inserting 100000 records into 'sbtest2'
Inserting 100000 records into 'sbtest3'
Inserting 100000 records into 'sbtest5'
Inserting 100000 records into 'sbtest1'
Inserting 100000 records into 'sbtest4'
Creating a secondary index on 'sbtest2'...
Creating a secondary index on 'sbtest4'...
Creating a secondary index on 'sbtest5'...
Creating a secondary index on 'sbtest1'...
Creating a secondary index on 'sbtest3'...

real    0m17.666s
user    0m2.272s
sys     0m0.323s

大致上到這裡結束

就是 port 從 3306 轉到 4000 的差別

主要啟動 TiDB Service 會需要搭配其他服務

相較 systemctl 控制,TiDB 就更吃維護經驗了

也因為 Service Component 拆細的關係,相較 HA 與服務活用性都更高些

相關參考資料也可以看看 Ref: Percona / Tocker

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *