Skip to content

Classic MySQL Master Slave CentOS7

ZengJingtao edited this page Jun 8, 2023 · 1 revision

中文版 (Chinese)

This document deploys a cluster version of MyTopling running on a CentOS 7 system with a Dcompact server for enterprise users who cannot upgrade the system.

Note: The RHEL8 version binary package compiled according to this document cannot run on CentOS 7.

Compiling the MyTopling binary package of CentOS 7 is complicated, and the documentation is not provided for now. Enterprise version users please contact customer service to obtain the precompiled package mytopling-centos7-haswell.tar.gz.

See this document for the stand-alone version without Compact.

If conditions permit, it is recommended to use a new version of the operating system such as Almalinux 8 / RockyLinux 8.

1. Environmental verification

1.1 Check the kernel to ensure that the kernel is above 5.14

uname -a

If it is lower than 5.14, you can use the following command to upgrade:

sudo yum install elrepo-release -y
# Note that after installing the kernel, modify the default kernel and restart
sudo yum -y --disablerepo="*" --enablerepo="elrepo-kernel" install kernel-ml

Or when it is inconvenient to use elrepo-release to upgrade, you can use 5.14 kernel distributed by us:

sudo yum -y install https://topling-tools.oss-cn-qingdao.aliyuncs.com/kernel-ml-5.14.15-1.el7.elrepo.x86_64.rpm

The command to modify the default start-up kernel:

# View the list of installed kernels
grubby --info=ALL | grep -E "^kernel|^index" 
# Modify the default kernel according to the list printed in the previous article, the latest installed kernel is generally 0
grubby --set-default-index=<new_kernel_index>
reboot

Note 1: Each time yum update update kernel, it may change back to its own kernel after restarting. The server should be upgraded carefully

Note 2: Compatibility issues: when using the new kernel on CentOS 7, Illegal instruction errors will occur on some CPUs. It can run normally with the old kernel, but the old kernel do not have io uring.

Note 3: Although kenerl 5.1 supports io uring, io uring cannot get rid of mlock until kernel 5.12; MADV_POPULATE_READ is not supported until kernel 5.14.

1.2 Configure domain name resolution on the intranet (private dns can also be used)

sudo bash -c 'echo "<ip_of_master>" mytopling-instance-1.mytopling.in >> /etc/hosts'
sudo bash -c 'echo "<ip_of_slave>" mytopling-instance-2.mytopling.in >> /etc/hosts'
sudo bash -c 'echo "<ip_of_dcompact>" dcompact.mytopling.in >> /etc/hosts'

1.3 Make sure that the SSD/NVMe disk (disk1) has enabled Trim (the discard option of mount)

grep discard /etc/fstab

If the mount does not enable discard, the write operation of the SSD/NVMe disk will be greatly slowed down

1.4 Turn off firewall and selinux for the three hosts

sudo setenforce 0
sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
sudo systemctl disable --now firewalld

2. Install runtime dependencies and deploy

This chapter (2.x) runs on two MyTopling hosts (hosts where the master database and slave database are located) separately.

2.1 Installation NFS dependencies

sudo yum install epel-release -y 
sudo yum install -y libaio gflags libcurl nfs-utils
sudo yum install -y snappy zlib bzip2 lz4

2.2 Enable NFS sharing

Assume /disk1 is the formatted and mounted disk, execute on mytopling-instance-1:

mkdir -p /mnt/mynfs/datadir/mytopling-instance-1

execute on mytopling-instance-2:

mkdir -p /mnt/mynfs/datadir/mytopling-instance-2

Execute on the two hosts separately:

echo "/mnt/mynfs *(rw,async,no_root_squash,fsid=1)" >> /etc/exports
# Increase the number of server threads
sudo sed -i  's|#\[nfsd\]|\[nfsd\]|g' /etc/nfs.conf
sudo sed -i  's/# threads=8/threads=64/g' /etc/nfs.conf
sudo systemctl enable --now nfs-server

2.3 Deploy the MyTopling program

Map the shared disk to the corresponding location, which is the same as the program installation location, or mount the disk to /mnt/mynfs by yourself.

sudo mkdir /mnt/mynfs
# If your disk is not /disk1, replace disk1 with the actual mount location of your nvme disk
# Or you can directly mount the disk to /mnt/mynfs, then you don’t need to add content to fstab
sudo bash -c "echo '/disk1 /mnt/mynfs none defaults,bind 0 0'" >> /etc/fstab
mount -a

Install mytopling

# After running, /mnt/mynfs/opt/ should be the program file of MyTopling
tar xf mytopling-centos7-haswell.tar.gz -C /mnt/mynfs/opt

3. Initialize dcompact

There is no need to decompress the installation file on the dcompact server, which directly uses the executable file shared by the instance-1 server.

Execute the following commands in sequence on the dcompact server:

# Run the following command on the computing server
# Install dependencies
sudo yum install epel-release -y 
sudo yum install -y libaio gflags libcurl nfs-utils
sudo yum install -y snappy zlib bzip2 lz4

Optimize NFS client parameters and mount:

sudo echo "options sunrpc tcp_slot_table_entries=128" >> /etc/modprobe.d/sunrpc.conf
sudo echo "options sunrpc tcp_max_slot_table_entries=128" >>  /etc/modprobe.d/sunrpc.conf
sudo sysctl -w sunrpc.tcp_slot_table_entries=128

Deploy the program and mount NFS:

sudo mkdir /mnt/mynfs/opt -p
sudo mkdir /mnt/mynfs/datadir/{mytopling-instance-1,mytopling-instance-2} -p
sudo bash -c 'echo "mytopling-instance-1.mytopling.in:/mnt/mynfs/datadir/mytopling-instance-1 /mnt/mynfs/datadir/mytopling-instance-1/ auto rw,nolock,noac,noatime,nofail,_netdev 0 0" >> /etc/fstab'
sudo bash -c 'echo "mytopling-instance-2.mytopling.in:/mnt/mynfs/datadir/mytopling-instance-2 /mnt/mynfs/datadir/mytopling-instance-2/ auto rw,nolock,noac,noatime,nofail,_netdev 0 0" >> /etc/fstab'
# executable program file
sudo bash -c 'echo "mytopling-instance-1.mytopling.in:/mnt/mynfs/opt /mnt/mynfs/opt/ auto ro,nolock,noac,noatime,nofail,_netdev 0 0" >> /etc/fstab'
sudo mount -a
# Start calculation process
sudo bash /mnt/mynfs/opt/mytopling-deploy/Classic-MySQL-Master-Slave-Replication-Dcompact/start-dcompact.sh

4. Start the database

The required parameters have been set in the startup script, and binlog enables the GITD mode.

Execute on the host mytopling-instance-1.mytopling.in

sudo bash /mnt/mynfs/opt/mytopling-deploy/Classic-MySQL-Master-Slave-Replication-Dcompact/enterprise/start-mysqld-instance-1.sh

Execute on the host mytopling-instance-2.mytopling.in

sudo bash /mnt/mynfs/opt/mytopling-deploy/Classic-MySQL-Master-Slave-Replication-Dcompact/enterprise/start-mysqld-instance-2.sh

Directly execute /mnt/mynfs/opt/bin/mysql -uroot -S /var/lib/mysql/mysql.sock to connect

At this point, the two databases are in the initial state, and the master-slave needs to be manually configured, which is the same as the standard MySQL setting mode.

If the slave library has no longer set downstream, you can modify the parameters in the script to close binlog.