TiUP安装TiDB4.0集群
作者:周万春
微信:lovemysql3306
1、操作系统建议
CentOS Linux 7.4 及以上
2、安装结构生产建议
组件 CPU 内存 硬盘类型 网络 实例数量(最低要求)
TiDB 16核+ 32GB+ SAS 万兆网卡(2 块最佳) 2
PD 4核+ 8GB+ SSD 万兆网卡(2 块最佳) 3
TiKV 16核+ 32GB+ SSD 万兆网卡(2 块最佳) 3
TiFlash 48核+ 128GB+ SSD 万兆网卡(2 块最佳) 2
TiCDC 16核+ 64GB+ SSD 万兆网卡(2 块最佳) 2
监控 8核+ 16GB+ SAS 千兆网卡 1
3、VMware模拟安装TiDB最简单的集群环境:
就一台机器:192.168.10.11,2c8g,disk 100G,
TiDB 1
PD 1
TiKV 1
1 监控
配置/etc/hosts主机名解析
cat >> /etc/hosts <<EOF
192.168.10.11 db01
EOF
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
firewall-cmd --state
关闭selinux
sed 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config -i
setenforce 0
getenforce
sestatus
设置CPU最大性能模式
cpupower frequency-info --governors
cpupower frequency-info --policy
cpupower frequency-set --governor performance
关闭swap
echo "vm.swappiness = 0" >> /etc/sysctl.conf
sysctl -p
vim /etc/fstab
注释#swap
swapoff -a && swapon -a && free -h
配置资源限制
cat >> /etc/security/limits.conf <<EOF
tidb soft nofile 1000000
tidb hard nofile 1000000
tidb soft stack 10240
EOF
配置sudo授权
useradd tidb
echo "mysql" | passwd --stdin tidb
echo "tidb ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
配置tidb用户ssh互信
su - tidb
ssh-keygen
cd .ssh/
cp -a id_rsa.pub authorized_keys
chmod 600 authorized_keys
scp -rp ~/.ssh/ tidb@192.168.10.12:/home/tidb/ cp到所有目标主机
连自身,连远程
ssh 192.168.10.11 hostname; hostname
数据盘准备:
nvme ssd ext4
lsblk,lsblk -f
blkid
分区:
fdisk / parted --> parted -s -a optimal /dev/nvme0n1 mklabel gpt -- mkpart primary ext4 1 -1
建议直接格式化:
mkfs.ext4 /dev/nvme0n1
blkid /dev/nvme0n1|awk -F[\ \"] '{print $2$3" /data ext4 defaults,nodelalloc,noatime 0 0"}' >> /etc/fstab
mkdir -p /data
mount -a
mount -t ext4
df -Th
配置NTP服务
yum install -y ntp ntpdate
中控机:vim /etc/ntp.conf
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 127.127.1.0 iburst
目标机:vim /etc/ntp.conf
#restrict default nomodify notrap nopeer noquery
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server 192.168.10.11
restrict 192.168.10.11 nomodify notrap noquery
systemctl start ntpd
systemctl enable ntpd
ntpstat
手工配置时间一样
date -s "2020-11-11 00:00:00"
date "+%F %T"; ssh 192.168.10.11 'date "+%F %T"'
准备规划集群拓扑结构
# vim install_tidb.yaml
global:
user: "tidb"
ssh_port: 22
deploy_dir: "/data/tidb-deploy"
data_dir: "/data/tidb-data"
monitored:
node_exporter_port: 9100
blackbox_exporter_port: 9115
deploy_dir: "/data/tidb-deploy/monitored-9100"
data_dir: "/data/tidb-data/monitored-9100"
log_dir: "/data/tidb-deploy/monitored-9100/log"
server_configs:
tidb:
log.level: error
log.slow-threshold: 500
binlog.enable: false
binlog.ignore-error: false
performance.max-procs: 0
performance.txn-total-size-limit: 10737418240
prepared-plan-cache.enabled: true
tikv-client.max-batch-wait-time: 0
tikv:
pessimistic-txn.enabled: true
pessimistic-txn.pipelined: true
server.grpc-compression-type: none
server.grpc-concurrency: 4
raftstore.apply-pool-size: 2
raftstore.store-pool-size: 2
rocksdb.max-sub-compactions: 1
storage.block-cache.capacity: "4GB" #MEM_TOTAL * 0.5 / TiKV 实例数量
storage.block-cache.shared: true
readpool.unified.max-thread-count: 2 #cores * 0.8 / TiKV 数量
readpool.storage.use-unified-pool: false
readpool.coprocessor.use-unified-pool: true
pd:
replication.enable-placement-rules: true
schedule.leader-schedule-limit: 4
schedule.region-schedule-limit: 2048
schedule.replica-schedule-limit: 64
replication.location-labels: ["dc","zone","host"]
tidb_servers:
- host: 192.168.10.11
ssh_port: 22
port: 4000
status_port: 10080
deploy_dir: "/data/tidb-deploy/tidb-4000"
log_dir: "/data/tidb-deploy/tidb-4000/log"
numa_node: "0,1"
tikv_servers:
- host: 192.168.10.11
ssh_port: 22
port: 20160
status_port: 20180
deploy_dir: "/data/tidb-deploy/tikv-20160"
data_dir: "/data/tidb-data/tikv-20160"
log_dir: "/data/tidb-deploy/tikv-20160/log"
config:
server.labels: { dc: "dc1", zone: "zone1", host: "host-192.168.10.11" }
pd_servers:
- host: 192.168.10.11
ssh_port: 22
name: "pd-192.168.10.11-2379"
client_port: 2379
peer_port: 2380
deploy_dir: "/data/tidb-deploy/pd-2379"
data_dir: "/data/tidb-data/pd-2379"
log_dir: "/data/tidb-deploy/pd-2379/log"
monitoring_servers:
- host: 192.168.10.11
ssh_port: 22
port: 9090
deploy_dir: "/data/tidb-deploy/prometheus-8249"
data_dir: "/data/tidb-data/prometheus-8249"
log_dir: "/data/tidb-deploy/prometheus-8249/log"
grafana_servers:
- host: 192.168.10.11
ssh_port: 22
port: 3000
deploy_dir: "/data/tidb-deploy/grafana-3000"
alertmanager_servers:
- host: 192.168.10.11
ssh_port: 22
web_port: 9093
cluster_port: 9094
deploy_dir: "/data/tidb-deploy/alertmanager-9093"
data_dir: "/data/tidb-data/alertmanager-9093"
log_dir: "/data/tidb-deploy/alertmanager-9093/log"
离线安装集群
su - tidb
wget -c https://download.pingcap.org/tidb-community-server-v4.0.8-linux-amd64.tar.gz -P /disk/
tar -xf /disk/tidb-community-server-v4.0.8-linux-amd64.tar.gz -C /disk/
sh /disk/tidb-community-server-v4.0.8-linux-amd64/local_install.sh
source /home/tidb/.bash_profile
type tiup
export TIUP_MIRRORS=/disk/tidb-community-server-v4.0.8-linux-amd64/
tiup cluster deploy tidb-gg v4.0.8 /disk/install_tidb.yaml --user tidb
tiup list tidb
tiup cluster list
tiup cluster start tidb-gg
tiup cluster display tidb-gg
上传MySQL二进制包
wget -c https://mirrors.cloud.tencent.com/mysql/downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -P /disk/
wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -P /disk/
mkdir -p /u01/app/mysql
tar -xf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /u01/app/mysql/
ln -s /u01/app/mysql/mysql-5.7.25-linux-glibc2.12-x86_64 /usr/local/mysql
cat >> /etc/profile <<'EOF'
# mysql
export PATH=/usr/local/mysql/bin:$PATH
EOF
source /etc/profile
mysql -uroot -p -h192.168.10.11 -P4000
alter user user() identified by '123';
flush privileges;
访问监控:
监控:http://192.168.10.11:3000/login
监控规则:192.168.10.11:9090
TiDB Dashboard:http://192.168.10.11:2379/dashboard/