入库检查 - 物理机 & 系统安装数据库前预检查
Contents
[NOTE] Updated March 5, 2019. This article may have outdated content or subject matter.
0x01 precheck
本篇文档产生原因来自 Step 7: Configure the CPUfreq governor mode on the target machine
根据 TiDB-ansible 安装时的报错反推物理机安装 TiDB 时需要干点啥……
0x02 OS
结合官方文档 使用 TiDB Ansible 部署 TiDB 集群 文档先整理已知信息
Net / Port
物理机、虚拟机、云主机部署时,一定要确保内网防火墙开通以下端口,如果不了解 源地址 和 目的地地址 可以在内网 any to any 放行。
组件 | 端口变量 | 默认端口 | 说明 |
---|---|---|---|
TiDB | tidb_port | 4000 | 应用及 DBA 工具访问通信端口 |
TiDB | tidb_status_port | 10080 | TiDB 状态信息上报通信端口【与 Prometheus 通信】 |
TiKV | tikv_port | 20160 | TiKV 通信端口 |
TiKV | tikv_status_port | 20180 | 上报 TiKV 状态的通信端口【与 Prometheus 通信】 |
PD | pd_client_port | 2379 | 提供 TiDB 和 PD 通信端口【与 Prometheus 通信】 |
PD | pd_peer_port | 2380 | PD 集群节点间通信端口 |
Pump | pump_port | 8250 | Pump 通信端口【Binlog 组件】、【与 Prometheus 通信】 |
Prometheus | prometheus_port | 9090 | Prometheus 服务通信端口 |
Node_exporter | node_exporter_port | 9100 | TiDB 集群每个节点的系统信息上报通信端口 |
Blackbox_exporter | blackbox_exporter_port | 9115 | Blackbox_exporter 通信端口,用于 TiDB 集群端口监控 |
Grafana | grafana_port | 3000 | Web 监控服务对外服务和客户端(浏览器)访问端口 |
Kafka_exporter | kafka_exporter_port | 9308 | Kafka_exporter 通信端口,用于监控 binlog Kafka 集群【默认不安装】 |
Pushgateway | pushgateway_port | 9091 | TiDB, TiKV, PD 监控聚合和上报端口【默认不安装】 |
SSH-key
按照文档中第 2 步:在中控机上创建 tidb 用户,并生成 SSH key 做好 中控机 到 部署节点 SSH-key 免密互信,做这一步时需要 linux root 用户密码权限;如果公司内部使用 jump server 堡垒机,辣么可能需要手动创建一个小用户并设置 sudo 免密了【jump server 管理员可以批量创建用户】
如果不让配置 ssh-key 互信 & sudo 免密,那就需要了解下 ansible 的使用技巧了。比如:
如果目标密码统一可以使用 -k 参数传递 ssh-remote user 密码
1 2
-k, --ask-pass ask for connection password -u REMOTE_USER, --user=REMOTE_USER
如果密码不统一,可以在 inventory 配置密码
- 此处使用明文密码,密码中包含
# $ !
等特殊字符可能会导致 ssh 登陆失败
1 2 3
ansible_host=192.168.1.10 ansible_connection=ssh ansible_ssh_user=vagrant ansible_ssh_pass=vagrant10 ansible_host=192.168.1.11 ansible_connection=ssh ansible_ssh_user=vagrant ansible_ssh_pass=vagrant11 ansible_host=192.168.1.12 ansible_connection=ssh ansible_ssh_user=vagrant ansible_ssh_pass=vagrant12
- 此处使用明文密码,密码中包含
remote user 提权参数
- 注意区分 sudo 与 su 的使用姿势,以及 sudo 目标用户
1 2 3 4 5 6 7 8 9 10 11 12
-s, --sudo run operations with sudo (nopasswd) (deprecated, use become) -U SUDO_USER, --sudo-user=SUDO_USER desired sudo user (default=root) (deprecated, use become) -S, --su run operations with su (deprecated, use become) -R SU_USER, --su-user=SU_USER run operations with su as this user (default=None) (deprecated, use become) -b, --become run operations with become (does not imply password prompting) -K, --ask-become-pass
NTP
centos 7 ntp 默认服务换成了 Chrony 服务;然 tidb-ansible 中使用的是 ntpd 服务。
如果公司主机系统内网已经有 NTP server 信息了,可以在 tidb-ansible/inventory.ini
中设置 enable_ntpd = True 变量为 False。
如果公司内网没有 NTP ,且内网没有 Yum 源,辣么就需要手动安装该服务了。
分布式系统需要一个隐藏性标准用来做信息实时判断,时间显然是最好的判断方式
CPU mode
为了让 CPU 发挥最大性能,请将 CPUfreq 调节器模式设置为 performance 模式。如需了解 CPUfreq 的更多信息,可查看使用 CPUFREQ 调控器文档。
通过 bios 调整主板参数,如果不方便重启服务器时可以通过以下命令暂时规避(重启后服务器后失效)
ansible all -m shell -a "cpupower frequency-set --governor performance" -b
Disk mount
- tikv 数据目录挂载属性必须包含 nodelalloc 参数
UUID=c51eb23b-195c-4061-92a9-3fad812cc12f /data1 ext4 defaults,nodelalloc,noatime 0 2
Disk fio
磁盘性能检测,通过学习 ansible-playbook / tidb 看下是怎么操作的,代码块在这里 tidb-ansible/role/machine benchmark。
该检测项仅针对 tikv_servers 主机
default values (roles/machine_benchmark/defaults/main.yml)
1 2 3 4 5 6 7 8 9 10 11 12 13
# fio randread iops min_ssd_randread_iops: 40000 # fio mixed randread and sequential write min_ssd_mix_randread_iops: 10000 min_ssd_mix_write_iops: 10000 # fio mixed randread and sequential write lat max_ssd_mix_randread_lat: 250000 max_ssd_mix_write_lat: 30000 # fio test file size benchmark_size: 10G
测试使用 fio 命令,使用 psync IO 引擎,使用绕过内存缓存读写,使用基准 32k 大小,
随机读测试 fio_randread.yml
- 如果测试结果中 iops 小于 40000 将会报错
1
./fio -ioengine=psync -bs=32k -fdatasync=1 -thread -rw=randread -size={{ benchmark_size }} -filename=fio_randread_test.txt -name='fio randread test' -iodepth=4 -runtime=60 -numjobs=4 -group_reporting --output-format=json --output=fio_randread_result.json
混合场景:随机读 顺序写 fio_randread_write.yml
- 随机读 iops 小于 10000 、顺序写小于 10000
1
./fio -ioengine=psync -bs=32k -fdatasync=1 -thread -rw=randrw -percentage_random=100,0 -size={{ benchmark_size }} -filename=fio_randread_write_test.txt -name='fio mixed randread and sequential write test' -iodepth=4 -runtime=60 -numjobs=4 -group_reporting --output-format=json --output=fio_randread_write_test.json
混合场景读写延迟:fio_randread_write_latency.yml
- 随机读大于 25w ns(0.25 毫秒)、顺序写大于 30000 ns(0.03 毫秒)
1
./fio -ioengine=psync -bs=32k -fdatasync=1 -thread -rw=randrw -percentage_random=100,0 -size={{ benchmark_size }} -filename=fio_randread_write_latency_test.txt -name='fio mixed randread and sequential write test' -iodepth=1 -runtime=60 -numjobs=1 -group_reporting --output-format=json --output=fio_randread_write_latency_test.json"
sysctl
关注 roles/bootstrap/tasks/root_tasks.yml,学习 tidb-ansible 修改了那些系统参数
selinux
1 2 3 4 5
cat /etc/selinux/config # 查看 selinux 状态 vi /etc/selinux/config # 编辑 selinux 配置文件,将以下参数调整为 disable / 重启系统后生效 SELINUX=disabled
Firewalld
1 2 3 4 5 6 7 8 9
systemctl status firewalld.service # 查看防火墙状态 systemctl stop firewalld.service # 关闭防火墙服务 systemctl disable firewalld.service # 关闭开机启动 iptable-save # 查看 iptable 配置,按需清理 iptable 规则
swap
1 2 3
swapoff -a # 使用命令关闭 swap 服务 # 修改 /etc/fstab 卸载 swap 分区
sysctl
1 2 3 4 5
{ name: 'net.core.somaxconn', value: 32768 } { name: 'vm.swappiness', value: 0 } { name: 'net.ipv4.tcp_syncookies', value: 0 } { name: 'fs.file-max', value: 1000000 } { name: 'net.ipv4.tcp_tw_recycle', value: 0 }
[never]表示透明大页禁用
1 2
echo never > /sys/kernel/mm/transparent_hugepage/enabled echo never > /sys/kernel/mm/transparent_hugepage/defrag
irqbalance
- Irqbalance is a daemon to help balance the cpu load generated by interrupts across all of a systems cpus.
ulimit
1 2 3
{{ deploy_user }} soft nofile 1000000 {{ deploy_user }} hard nofile 1000000 {{ deploy_user }} soft stack 10240
0x03 VIP
手动测试 / 如果需要跨机房部署就需要针对性测试网络延迟、网络带宽等信息
Net nc
假设机房分别部署在 上海 & 北京 两地,由于距离较远;而分布式应用对网络质量要求比较高。所以可以通过 ping、nc、iftop 等工具手动复检。
|
|
0x04 Demo
intel P4610 磁盘性能测试
|
|
某 PCIe SATA 6Gb/s 磁盘背板挂载 SSD 测试
|
|