Heim  >  Artikel  >  Datenbank  >  Ausführliche Erläuterung der Installationsschritte für MySQL Dual-Machine Hot Standby

Ausführliche Erläuterung der Installationsschritte für MySQL Dual-Machine Hot Standby

藏色散人
藏色散人nach vorne
2021-11-18 14:50:292013Durchsuche

MySQL-Dual-Machine-Hot-Standby-Installation

1. MySQL installieren

#tar -xf mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar 
#yum localinstall *.rpm

1.1 MySQL-Konfiguration ändern

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
explicit_defaults_for_timestamp=true
tmpdir=/tmp

[client]
default-character-set=utf8mb4

[mysqld]
character_set_server=utf8mb4

1.2 Berechtigungsänderung

[root@172 ~]# chown -R mysql:mysql /data
[root@172 ~]# chmod 777 -R /data/
[root@172 ~]# chmod -R 777 /tmp

1.3 MySQL-Dienst starten

[root@172 ~]# service mysqld restart
Stopping mysqld:                                           [FAILED]
Initializing MySQL database:                               [  OK  ]
Installing validate password plugin:                       [  OK  ]
Starting mysqld:                                           [  OK  ]

1.4 Temporäres Passwort anzeigen

more /var/log/mysqld.log |grep temporary

1.5 Root-Passwort ändern

db1

ALTER USER 'root'@'localhost' IDENTIFIED BY '*****';
flush privileges;
exit;

db2

ALTER USER 'root'@'localhost' IDENTIFIED BY '*****';
flush privileges;
exit;

2. Master-Slave-Synchronisation konfigurieren

master1 172.28.8.187
master2 1 72.28.8.18 8

2.1 Konfigurieren Sie das verwendete Passwort von Master1, um sich bei Master2 anzumelden

Master1

create user 'repl' identified by '*****';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'172.28.8.188' IDENTIFIED BY '*****';
FLUSH PRIVILEGES;
mysql> create database mydb default charset utf8;
Testen Sie, ob sich der Repuser am 172.28.8.188 bei der Datenbank anmelden kann
mysql -urepl -p -h172.28.8.187

2.1.1 Master1 konfiguriert my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/data/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
explicit_defaults_for_timestamp=true
tmpdir=/tmp
character_set_server=utf8mb4

server-id=177
log-bin=/var/log/mysql/mysql-bin.log
read-only=0
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
expire_logs_days= 365
auto-increment-increment = 2
auto-increment-offset = 1

[client]
default-character-set=utf8mb4

2.2 Master2 konfiguriert my.cnf

#除server-id外,其他与master1保持一致

2.2.1 Master2 zu Master 1 Erstellen Sie ein Kontopasswort und autorisieren Sie es

Stellen Sie Master2 auf Synchronisierung ein von master1

create user 'repl' identified by '*****';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'172.28.8.187' IDENTIFIED BY '*****';
FLUSH PRIVILEGES;

Wenn es erscheint Die folgenden zwei Elemente zeigen an, dass die Konfiguration erfolgreich ist!

mysql> show master status;
+------------------+----------+--------------+--------------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------------+-------------------+
| mysql-bin.000001 |      154 | mydb         | mysql,information_schema |                   |
+------------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

3. Dual-Master-SynchronisationstestGeben Sie die MySQL-Datenbank „master1“ ein.

mysql> show master status;
+------------------+----------+--------------+--------------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB         | Executed_Gtid_Set |
+------------------+----------+--------------+--------------------------+-------------------+
| mysql-bin.000001 |      154 | mydb         | mysql,information_schema |                   |
+------------------+----------+--------------+--------------------------+-------------------+
1 row in set (0.00 sec)

Geben Sie „master2“ ein, um zu überprüfen, ob eine CRM-Datenbank und eine Mitarbeitertabelle vorhanden sind.

mysql>CHANGE MASTER TO MASTER_HOST='172.28.8.188',MASTER_PORT=3306,MASTER_USER='repl',MASTER_PASSWORD='b4l:GGtG3s0*',MASTER_LOG_FILE='mysql-bin.000002',MASTER_LOG_POS=860;
mysql> SHOW SLAVE STATUS\G
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS\G
Überprüfen Sie in Master1, ob gerade Daten in Master2 eingefügt wurden.

mysql>CHANGE MASTER TO MASTER_HOST='172.28.8.187',MASTER_PORT=3306,MASTER_USER='repl',MASTER_PASSWORD='2S1*8pr+BzqH^8T`',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=1497;
mysql> SHOW SLAVE STATUS\G
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS\G

Empfohlenes Lernen: „MySQL-Video-Tutorial

Das obige ist der detaillierte Inhalt vonAusführliche Erläuterung der Installationsschritte für MySQL Dual-Machine Hot Standby. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:segmentfault.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen