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

Setting up Centos7.5 production environment MySQL 5.7 master and slave

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Environment:

Two servers:

192.168.19.77 4 core, 16 GB internal network isolation, no access to external network

192.168.19.78 4 core, 16 GB internal network isolation, no access to external network

one。 First, there is a machine on the external network. Download the software package of the MySQL 5.7official website.

Download link on the official website:

For convenience, I will directly post the download link address of the official software package needed to install MySQL5.7.

Using the official RPM package installation, you need to install five packages, which are the following five links, all of which are official links

Https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-common-5.7.23-1.el7.x86_64.rpmhttps://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-libs-5.7.23-1.el7.x86_64.rpmhttps://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-client-5.7.23-1.el7.x86_64. Rpm https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.23-1.el7.x86_64.rpmhttps://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-devel-5.7.23-1.el7.x86_64.rpm II. Install MySQL

Using the FTP software, upload the software package to the / tmp directory of the two database servers on the intranet

Before installing rpm, uninstall the MariaDB database and libs

# yum remove mariadb mariadb-server mariadb-devel mariadb-libs

Install MySQL

# rpm-ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm # rpm-ivh mysql-community-common-5.7.23-1.el7.x86_64.rpm # rpm-ivh mysql-community-libs-5.7.23-1.el7.x86_64.rpm # rpm-ivh mysql-community-client-5.7.23-1.el7.x86_64.rpm # rpm-ivh mysql-community -server-5.7.23-1.el7.x86_64.rpm # rpm-ivh mysql-community-devel-5.7.23-1.el7.x86_64.rpm

three。 Custom configuration database

Point the data and logs of the database to the data storage directory, and then add the master-slave parameters.

My.cnf of 192.168.19.77 primary server

[root@mysql-m ~] # cat / etc/ my.cnf [mysqld] datadir=/u1/mysql/datasocket=/u1/mysql/data/mysql.socklog-error=/u1/mysql/log/mysqld.logpid-file=/u1/mysql/pid/mysqld.piduser=mysqlserver-id=1port=3306## to open for slave synchronized libraries # binlog-do-db=## does not open slave synchronized libraries (multiple write multiple lines) binlog-ignore-db=mysqlbinlog-ignore-db=information_schemabinlog-ignore-db=performance_schemabinlog-ignore-db=sys## Binary log log-bin=/u1/mysql/binary/mysql1-bin## automatically cleans up log files from 7 days ago Expire_logs_days= 7 [client] socket=/u1/mysql/data/mysql.sock can be modified as needed.

192.168.19.77 my.cnf from the server

[root@mysql-m ~] # cat / etc/my.cnf [mysqld] datadir=/u1/mysql/datasocket=/u1/mysql/data/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0log-error=/u1/mysql/log/mysqld.logpid-file=/u1/mysql/pid/mysqld.piduser=mysqlserver-id=2port=3306## parameter read_only= 1master_info_repository=TABLErelay_log_info_repository=TABLE#relay_log_recovery=1 # slave forbids writing # super_read_only=1 # write [client] socket=/u1/mysql/data/mysql.sock prohibited on slave computer

Establish the directory specified by the configuration file

# mkdir-p / u1/mysql/ {data,logs,pid} # chown-R mysql.mysql / U1

Start the database and find the root password

# systemctl start mysqld-- find the root random password # egrep "root@localhost" / u1/mysql/log/mysqld.log | awk-F ":"'{print $4} 'zn9 > ALTER USER root@localhost identified by' TestMySQL5.7'; IV. Configure master and slave

Authorize the replication of accounts from the slave server on the master server

# mysql-uroot-pEnter password: mysql > grant replication slave on *. * to mysql_ab@'192.168.19.%' identified by 'mysql_AB5.7' Mysql > show master status\ gateway * 1. Row * * File: mysql1-bin.000001 Position: 1082 Binlog_Do_DB: Binlog_Ignore_DB: mysql,information_schema,performance_schema,sysExecuted_Gtid_Set: 1 row in set (0.00 sec)

Come to the slave server to configure to connect to the master server

# mysql-uroot-pEnter password: mysql > stop slave;mysql > chagne master to-> master_host='192.168.19.77',-> master_port=3306,-> master_user='mysql_ab',-> master_password='mysql_AB5.7',-> master_log_file='mysql1-bin.000001',-> master_log_pos=1082;mysql > start slave Mysql > show slave status\ gateway * 1. Row * * Slave_IO_State: Waiting for master to send event Master_Host: 192.168.19.77 Master_User: mysql_ab Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql1-bin.000001 Read_Master_Log_Pos: 1082 Relay_Log_File: dosercn10235b-relay-bin.000004 Relay_Log_Pos: 951 Relay_Master_Log_File: mysql1-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: 1082 Relay_Log_Space: 1166 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: 1 Master_UUID: 45d68d37-b6f9-11e8-a947-0050569afd93 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log Waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 Replicate_Rewrite _ DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec)

Configuration is complete, and the slave server is connected to the master server

five。 Verification

Create databases, tables, and insert data on the primary server

Mysql > CREATE DATABASE test_ab default charset utf8;mysql > CREATE TABLE test_ab.a1 (id int (2), name varchar (20); mysql > INSERT INTO test_ab.a1 (id,name) VALUES (1, "test 1"); mysql > select * from test_ab.a1 +-+-+ | id | name | +-+-+ | 1 | Test 1 | +-+-+ 1 row in set (0.00 sec)

Query the data from the server to verify that it has been copied

Mysql > select * from test;+-+-+ | id | name | +-+-+ | 1 | Test 1 | +-+-+ 1 row in set (0.00 sec)

So far, it's done.

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