useradd tidb
passwd tidb
touch /etc/sudoers.d/tidb
echo 'tidb ALL=(ALL) NOPASSWD: ALL' >/etc/sudoers.d/tidb
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
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)
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
yum -y install git
git clone -b release-2.0 https://github.com/pingcap/tidb-ansible.git
cd tidb-ansible
ansible-playbook local_prepare.yml
复制tidb-ansible目录到中控机的/home/tidb目录下,并设置属主为tidb用户。
cp -r tidb-ansible /home/tidb/
chown -R tidb /home/tidb/tidb-ansible
TiDB对应的是Google F1,是一层无状态的SQL层,负责与客户端交互,对客户端体现的是MySQL网络协议,且客户端需要通过一个本地负载均衡器将SQL请求转发到本地或最近的数据中心中的TiDB服务器。TiDB服务器负责解析用户的SQL语句,生成分布式的查询计划,并翻译成底层Key-Value操作发送给TiKV
TiDB架构采用PD集群来管理整个分布式数据库,PD服务器在TiKV节点之间以Region作为单位进行调度,将部分数据迁移到新添加的节点上,完成集群调度和负载均衡。
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
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) }…
ansible-playbook deploy.yml
sudo yum install fontconfig open-sans-fonts
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