Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Centos7 maiadb Master-Slave replication Building

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Demand:

Due to the use of saltstack, deployment environment, first manually built the next master-slave environment, found that the original word information can not be found, so this time quickly record to the blog!

Environment:

The ip addresses of the two devices are:

Node1:192.168.56.11

Node2:192.168.56.12

System: Centos7

Software package: mariadb installed using the yum that comes with the system

=

Installation:

Install the database mariadb on two devices respectively. If you use yum to install it, you can replace it with an internal yum source to operate.

Command: yum install-y mariadb mariadb-server

Configuration:

Configure master configuration on node1 first

[root@salt-node1 ~] # vim / etc/ my.cnf [mysqld] innodb_file_per_table=NOlog-bin=/var/lib/mysql/master-bin # here if you do not specify a path, the default is to generate binlog_format=mixedserver-id = 1cm under datadir. This master node must be the only datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group # customize your systemd unit file for mariadb according to the# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]log-error=/var/log/mariadb/mariadb.logpid-file=/var/run/mariadb/mariadb.pid## include all files from the config directory#!includedir / etc/my.cnf.d

Restart the mysql service on node1

Systemctl restart mariadb.service

Log in to mysql:

Mysql-uroot-p I did not set a password for the test here.

Create an account and grant permissions to replication. This account is required when copying data from the slave library and the master-slave library.

Grant replication slave on *. * to 'root'@'192.168.56.%' identified by' 123456'

Lock:

In practical work, it is necessary to disable the writing of the database and lock the database.

FLUSH TABLES WITH READ LOCK

Record the binlog log file and location information of the master library (this information is to be used when configuring the slave library)

MariaDB [(none)] > show master status +-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +- -+-+ | master-bin.000001 | 398 | +- -+ 1 row in set (0.00 sec)

Back up the data from the master database:

Mysqldump-uroot-p-- all-databases > / tmp/db.sql

=

Let's start to configure the slave library:

Import data into the slave library

Mysql-uroot-p show slave status\ G * * 1. Row * * Slave_IO_State: Waiting for master to send event Master_Host: 192.168.56.11 Master_User: root Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-bin.000001 Read_Master_Log_Pos: 485 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 617 Relay_Master_Log_File: master-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 485 Relay_Log_Space: 905 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 111 row in set (0.00 sec) ERROR: No query specified Slave_IO_Running: Yes # this must be yes If not, you need to troubleshoot Slave_SQL_Running: Yes # here must be yes, if not, you need to troubleshoot

Master-slave verification

# main database creation database MariaDB [(none)] > create database jiayou; Query OK, 1 row affected (0.00 sec) # check whether the database is synchronized from the library MariaDB [(none)] > show databases +-+ | Database | +-+ | information_schema | | gg | | jiayou | | kk | | mysql | | performance_schema | | salt | | test | +- -+ 8 rows in set (0.00 sec)

Sometimes there will be some problems, you can refer to the following blog, you are lazy to write

Http://blog.csdn.net/mingliangniwo/article/details/54606894?locationNum=8&fps=1

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report