TIDB安裝

所有機器添加tidb用戶,添加sudo權限

useradd tidb

passwd tidb

touch /etc/sudoers.d/tidb

echo 'tidb ALL=(ALL) NOPASSWD: ALL' >/etc/sudoers.d/tidb

ssh添加

su - tidb

ssh-keygen

cat ~/.ssh/id_rsa.pub >~/.ssh/authorized_keys

chmod 600 /home/tidb/.ssh/authorized_keys

ssh-copy-id -i ~/.ssh/id_rsa.pub 127.0.0.1

ssh-copy-id -i ~/.ssh/id_rsa.pub 127.0.0.2

ssh-copy-id -i ~/.ssh/id_rsa.pub 127.0.0.3

安裝Ansible及其依賴軟件包

(1)安裝PIP

yum -y install wget

wget https://download.pingcap.org/pip-rpms.el7.tar.gz

tar -xzvf pip-rpms.el7.tar.gz

cd pip-rpms.el7

chmod u+x install_pip.sh

./install_pip.sh

pip -V
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)

(2)安裝Ansible

wget https://download.pingcap.org/ansible-2.5.0-pip.tar.gz

tar -xzvf ansible-2.5.0-pip.tar.gz

cd ansible-2.5.0-pip/

chmod +x install_ansible.sh

mkdir ~/.pip

vi ~/.pip/pip.conf //更改pip源爲國內源
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com

pip install paramiko

pip install cryptography

./install_ansible.sh

下載TiDB-Ansible安裝包

(1)下載2.0 GA版本

yum -y install git

git clone -b release-2.0 https://github.com/pingcap/tidb-ansible.git

(2)下載TiDB binary

cd tidb-ansible

ansible-playbook local_prepare.yml

(3)複製目錄

複製tidb-ansible目錄到中控機的/home/tidb目錄下,並設置屬主爲tidb用戶。

cp -r tidb-ansible /home/tidb/

chown -R tidb /home/tidb/tidb-ansible

分配機器資源

Tidb

TiDB對應的是Google F1,是一層無狀態的SQL層,負責與客戶端交互,對客戶端體現的是MySQL網絡協議,且客戶端需要通過一個本地負載均衡器將SQL請求轉發到本地或最近的數據中心中的TiDB服務器。TiDB服務器負責解析用戶的SQL語句,生成分佈式的查詢計劃,並翻譯成底層Key-Value操作發送給TiKV

Pd

TiDB架構採用PD集羣來管理整個分佈式數據庫,PD服務器在TiKV節點之間以Region作爲單位進行調度,將部分數據遷移到新添加的節點上,完成集羣調度和負載均衡。

Tikv

TiKV則是真正存儲數據的地方,對應的是Google Spanner,是一個分佈式Key-Value數據庫,支持彈性水平擴展、自動的災難恢復和故障轉移,以及ACID跨行事務。

編輯inventory.ini文件,路徑爲tidb-ansible/inventory.ini,在該文件內進行各個組件的角色分配。

Host Tidb Pd Tikv Grafana Tispark Tidb-ansible
127.0.0.1
127.0.0.2
127.0.0.3
cd /home/tidb/

vi tidb-ansible/inventory.ini

[tidb_servers]
127.0.0.1

[tikv_servers]
127.0.0.1
127.0.0.2
127.0.0.3

[pd_servers]
127.0.0.2

[spark_master]

[spark_slaves]

## Monitoring Part
# prometheus and pushgateway servers
[monitoring_servers]
127.0.0.1

[grafana_servers]
127.0.0.1

# node_exporter and blackbox_exporter servers
[monitored_servers]
127.0.0.1
127.0.0.2
127.0.0.3

[alertmanager_servers]
127.0.0.1

修改 deploy_dir

vi tidb-ansible/inventory.ini

[all:vars]
deploy_dir = /data/deploy

實施部署

確認服務運行用戶

tidb-ansible/inventory.ini文件,確保ansible_user項配置爲tidb,即使用tidb用戶作爲服務運行用戶

cat tidb-ansible/inventory.ini

## Connection
# ssh via normal user
ansible_user = tidb

確認操作權限配置

[tidb@vm76 tidb-ansible]$ ansible -i inventory.ini all -m shell -a 'whoami'
127.0.0.1 | SUCCESS | rc=0 >>
tidb

127.0.0.2 | SUCCESS | rc=0 >>
tidb

127.0.0.3 | SUCCESS | rc=0 >>
tidb


[tidb@vm76 tidb-ansible]$ ansible -i inventory.ini all -m shell -a 'whoami' -b
127.0.0.1 | SUCCESS | rc=0 >>
root

127.0.0.2 | SUCCESS | rc=0 >>
root

127.0.0.3 | SUCCESS | rc=0 >>
root

初始化系統環境,修改內核參數

vi bootstrap.yml

# -{ role: check_system_optional, when: not dev_mode|default(false) }…

#-{ role: machine_benchmark, when: not dev_mode|default(false) }…

部署TiDB集羣軟件

ansible-playbook deploy.yml

安裝Grafana

sudo yum install fontconfig open-sans-fonts

啓動TiDB集羣

ansible-playbook start.yml

連接測試

[tidb@vm76 tidb-ansible]$ mysql -u root -h 127.0.0.1 -P 4000
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.10-TiDB-v2.0.11 MySQL Community Server (Apache License 2.0)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| INFORMATION_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql              |
| test               |
+--------------------+
4 rows in set (0.00 sec)

MySQL [(none)]> 

訪問監控平臺

http://127.0.0.1:3000

admin admin
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章