Build MariaDB replication on CentOS

I have never configured mysql replication by myself. I have been free for these two days. I installed the free VMWare Workstation Player on my computer, then downloaded the latest version of CentOS and started to configure it. Only the commands used are recorded, right as a running account.

1 Base System#

1.1 system message##

# ip addr //View IP address

1.2 Install required software##

# yum searchifconfig
# yum installnet-tools
# yum installvim
# yum installtelnet
# yum installwget
# yum installgpm     //Mouse driver
# systemctlenable gpm
# systemctlstart gpm

1.3 Three server information##

Main server: 192.168.5.128/24

Slave server 1: 192.168.5.129/24

Slave server 2: 192.168.5.130/24

2 MariaDB

Mainly refer to the third edition of the book "High Performance MySQL". Mysql is introduced in the book, but CentOS integrates the YUM source of MariaDB by default, so I am too lazy to change it, just use MariaDB directly.

2.1 Database installation##

# yum installmariadb-server; mariadb-client
# vim/etc/my.cnf.d/server.cnf
[ mysqld]
init_connect =’SET collation_connection = utf8_unicode_ci’
init_connect =‘SET NAMES utf8’
character-set-server= utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
# vim/etc/my.cnf.d/client.cnf
[ client]default-character-set= utf8
# vim/etc/my.cnf.d/mysql-client.cnf
[ client]default-character-set= utf8
# systemctlstart mariadb
# systemctlenable mariadb  //Automatically start when the system starts//Initialize mysql instance
# mysql_secure_installation
//Allow root remote login
# mysql -uroot-p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY'123456';
mysql> flush privileges ;

2.2 Firewall enable database port##

//Centos7 firewall open port number
# firewall-cmd--zone=public--add-port=3306/tcp --permanent
# firewall-cmd--reload              //Restart firewall
# firewall-cmd--list-ports     //View open ports
# firewall-cmd--state          //View the default firewall status

2.3 MySQL configuration master-slave replication##

2.3.1 All servers create replication accounts###

# mysql -uroot-p
mysql> GRANTREPLICATION SLAVE,-> REPLICATION CLIENT ON *.*-> TO repl@'192.168.5.%' IDENTIFIEDBY 'password';

2.3.2 Main server configuration###

# vim/etc/my.cnf.d/server.cnf
log_bin =mysql-bin
server_id =128//Use the last 8 bits of the IP address directly
sync_binlog =1

2.3.3 Configuration from the server###

# vim/etc/my.cnf.d/server.cnf
# SQL replication slave settings
log_bin =mysql-bin
server_id =129//Use the last 8 bits of the IP address directly
relay_log =/var/lib/mysql/mysql-relay-bin
log_slave_updates=1
read_only =1

2.3.4 Start replication from the server###

# mysql -uroot-p
//Set how to connect to the main library
mysql> CHANGEMASTER TO MASTER_HOST='192.168.5.128',-> MASTER_USER='repl',-> MASTER_PASSWORD='password',-> MASTER_LOG_FILE='mysql-bin.000001',-> MASTER_LOG_POS=0;//Start replication
mysql> startslave;//View replication status
mysql> showslave status \G;
Slave_ IO_Running: Yes
Slave_ SQL_Running: Yes
Seconds_ Behind_Master:0//Check whether the database of the main library has been copied
mysql> showdatabases;
mysql> use …;
mysql> showtables;

Recommended Posts

Build MariaDB replication on CentOS
Jenkins build on centos
Build Elasticsearch 6.2.4 (centos) based on docker
Build Nginx environment on Linux (CentOS)
Build Discuz Forum based on CentOS
How to install MariaDB on CentOS 8
Build WeChat applet service based on CentOS
Build WeChat applet service based on CentOS
CentOS7 build FastDFS distributed file system (on)
CentOS 7.2 install MariaDB
CentOS7 build jenkins
Centos build lnmp
Centos7 build python3.8.5+scrapy+gerapy
Build Nginx based on Centos 7 (including virtual host)
How to build a LAMP environment on centos7.2
CentOS7.3 64 bit, build Zabbix3.4
Install Docker on Centos7
CentOS build private git
install LNMP on centos7.4
Centos7 YUM install MariaDB 10.0
Install Java on Centos 7
Xfs configuration on centos7
CentOS6.7 build LNMP environment
Configure Ocserv on CentOS 6
Centos6.9 build rabbitmq 3.6.8 cluster
Nodejs install on centos7
Centos7.6 build LNMP environment
Install RabbitMQ on CentOS 7
Install Node.js on Centos
Centos7 build Kubernetes cluster
Maven install on centos7
Install MongoDB on CentOS 7
Install Surelog on CentOS8
Build Hadoop in CentOS
Deploy vuepress on centos7
Centos7 YUM install MariaDB 10.0
Openjdk install on centos7
Centos7 build DNS service
Install Jenkins on centos7
Use RapidSVN on CentOS7
Install MariaDB under MariaDB Centos7
install RabbitMQ on centos
Install RabbitMQ on CentOS 7
install Docker on centos6.5
install oracle on centos
Install Elasticsearch 6 on centos7
Install RabbitMQ on CentOS7
Deploy Jenkin on centos7
CentOS 7 build LNMP environment
3 minutes to teach you to build gitea on Centos server
Build docker environment under Centos6.5
CentOs7.3 build Solr stand-alone service
Build OpenV** Server under CentOS7
CentOs7.3 build RabbitMQ 3.6 stand-alone service
Build zabbix monitoring zabbix4.2 in CentOS7.6
First try to build a Ceph storage cluster on Centos7
Install ElasticSearch 7.x on CentOS 7
Build OpenLDAP server under CentOS7
Glusterfs cluster installation on Centos7
Build zabbix monitoring zabbix4.2 in CentOS7.6
Install MySQL 8.0.16 on Linux Centos