1 # 下载Tidb-Ansible 版本
cd /home/tidb && git clone -b release-2.0 https://github.com/pingcap/tidb-ansible.git
2 # 安装ansible及依赖
cd /home/tidb/tidb-ansible/ && pip install -r ./requirements.txt
在中控机上配置部署机器ssh互信及sudo 规则
# 配置hosts.ini
su tidb && cd /home/tidb/tidb-ansible
vim hosts.ini
[servers]
172.16.5.50
172.16.5.51
172.16.5.52
[all:vars]
username = tidb
ntp_server = pool.ntp.org
# 配置ssh 互信
ansible-playbook -i hosts.ini create_users.yml -u root -k
在目标机器上安装ntp服务
1 # 中控机器上给目标主机安装ntp服务
2 cd /home/tidb/tidb-ansible
3 ansible-playbook -i hosts.ini deploy_ntp.yml -u tidb -b
目标机器上调整cpufreq
1 # 查看cpupower 调节模式,目前虚拟机不支持,调节10服务器cpupower
2 cpupower frequency-info --governors
3 analyzing CPU 0:
4 available cpufreq governors: Not Available
5 # 配置cpufreq调节模式
6 cpupower frequency-set --governor performance
目标机器上添加数据盘ext4 文件系统挂载
# 创建分区表
parted -s -a optimal /dev/nvme0n1 mklabel gpt -- mkpart primary ext4 1 -1
# 手动创建分区
parted dev/sdb
mklabel gpt
mkpart primary 0KB 210GB
# 格式化分区
mkfs.ext4 /dev/sdb
# 查看数据盘分区 UUID
[root@tidb-tikv1 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs f41c3b1b-125f-407c-81fa-5197367feb39 /boot
├─sda2 xfs 8119193b-c774-467f-a057-98329c66b3b3 /
├─sda3
└─sda5 xfs 42356bb3-911a-4dc4-b56e-815bafd08db2 /home
sdb ext4 532697e9-970e-49d4-bdba-df386cac34d2
# 分别在三台机器上,编辑 /etc/fstab 文件,添加 nodelalloc 挂载参数
vim /etc/fstab
UUID=8119193b-c774-467f-a057-98329c66b3b3 / xfs defaults 0 0
UUID=f41c3b1b-125f-407c-81fa-5197367feb39 /boot xfs defaults 0 0
UUID=42356bb3-911a-4dc4-b56e-815bafd08db2 /home xfs defaults 0 0
UUID=532697e9-970e-49d4-bdba-df386cac34d2 /data ext4 defaults,nodelalloc,noatime 0 2
# 挂载数据盘
mkdir /data
mount -a
mount -t ext4
/dev/sdb on /data type ext4 (rw,noatime,seclabel,nodelalloc,data=ordered)
分配机器资源,编辑inventory.ini 文件
# 单机Tikv实例
Name HostIP Services
tidb-tikv1 172.16.5.50 PD1, TiDB1, TiKV1
tidb-tikv2 172.16.5.51 PD2, TiKV2
tidb-tikv3 172.16.5.52 PD3, TiKV3
# 编辑inventory.ini 文件
cd /home/tidb/tidb-ansible
vim inventory.ini
## TiDB Cluster Part
[tidb_servers]
172.16.5.50
172.16.5.51
[tikv_servers]
172.16.5.50
172.16.5.51
172.16.5.52
[pd_servers]
172.16.5.50
172.16.5.51
172.16.5.52
## Monitoring Part
# prometheus and pushgateway servers
[monitoring_servers]
172.16.5.50
# node_exporter and blackbox_exporter servers
[monitored_servers]
172.16.5.50
172.16.5.51
172.16.5.52
[all:vars]
#deploy_dir = /home/tidb/deploy
deploy_dir = /data/deploy
# 检测ssh互信
[tidb@tidb-tikv1 tidb-ansible]$ ansible -i inventory.ini all -m shell -a 'whoami'
172.16.5.51 | SUCCESS | rc=0 >>
tidb
172.16.5.52 | SUCCESS | rc=0 >>
tidb
172.16.5.50 | SUCCESS | rc=0 >>
tidb
# 检测tidb 用户 sudo 免密码配置
[tidb@tidb-tikv1 tidb-ansible]$ ansible -i inventory.ini all -m shell -a 'whoami' -b
172.16.5.52 | SUCCESS | rc=0 >>
root
172.16.5.51 | SUCCESS | rc=0 >>
root
172.16.5.50 | SUCCESS | rc=0 >>
root
# 执行 local_prepare.yml playbook,联网下载 TiDB binary 到中控机
ansible-playbook local_prepare.yml
# 初始化系统环境,修改内核参数
ansible-playbook bootstrap.yml
2.2、安装Tidb集群
1 ansible-playbook deploy.yml
2.3、启动Tidb集群
1 ansible-playbook start.yml
2.4、测试集群
# 使用 MySQL 客户端连接测试,TCP 4000 端口是 TiDB 服务默认端口
mysql -u root -h 172.16.5.50 -P 4000
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| INFORMATION_SCHEMA |
| PERFORMANCE_SCHEMA |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
# 通过浏览器访问监控平台
地址::3000 默认帐号密码是:admin/admin
# 单机Tikv实例
Name HostIP Services
tidb-tikv1 172.16.5.50 PD1, TiDB1, TiKV1
tidb-tikv2 172.16.5.51 PD2, TiKV2
tidb-tikv3 172.16.5.52 PD3, TiKV3
# 新增一台TIDB节点
添加一个 TiDB 节点(tidb-tikv4),IP 地址为 172.16.5.53
# 编辑inventory.ini 文件
cd /home/tidb/tidb-ansible
vim inventory.ini
------------------start---------------------------
## TiDB Cluster Part
[tidb_servers]
172.16.5.50
172.16.5.51
172.16.5.53
[tikv_servers]
172.16.5.50
172.16.5.51
172.16.5.52
[pd_servers]
172.16.5.50
172.16.5.51
172.16.5.52
## Monitoring Part
# prometheus and pushgateway servers
[monitoring_servers]
172.16.5.50