CentOS8 configura MySQL dual active y mutual backup (instale centos8 y MySQL)

Instalar el sistema operativo centos8 y la configuración

Habilitar SSH

  1. Primero, asegúrese de que el servidor openssh está instalado en CentOS8, ingreseyum list installed | grep openssh-server
  2. Si no hay salida que muestre que openssh-server no está instalado, ingrese yum install openssh-server
  3. Busque el /etc/ssh/archivo de configuración del servicio sshd en el directorio y sshd_configse #Port 22eliminarán los comentarios .
  4. Inicie el servicio sshd, ingrese sudo service sshd start
  5. Compruebe si se ha iniciado el servicio sshd, ingreseps -e | grep sshd

Instalar MySQL y configurar

Descargar espejo

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

Imagen de instalación

rpm -ivh mysql80-community-release-el7-3.noarch.rpm

Actualizar paquetes MySQL en el sistema

Actualice MySQL y los componentes relacionados a través de los siguientes comandos:
Solución 1. Especifique para actualizar el servidor MySQL (recomendado):

yum update mysql-server
方案二.通过更新系统上的所有内容来更新MySQL(谨慎使用):
注意,这个方法需要谨慎使用,一般是在空白服务器的时候可以使用,因为有可能会把你系统中的其他软件都给升级了
yum update

Instalar el servicio MySQL

yum install mysql-server

Inicializar la base de datos.

mysqld --inicializar

Iniciar servicio

service mysqld start

El trabajo para mysqld.service falló porque el proceso de control salió con el código de error.
Consulte "systemctl status mysqld.service" y "journalctl -xe" para más detalles.

Si ocurre una excepción, ejecute la siguiente instrucción:

chown mysql:mysql -R /var/lib/mysql
service mysqld start
systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-09-26 17:42:23 CST; 6s ago
  Process: 30399 ExecStopPost=/usr/libexec/mysql-wait-stop (code=exited, status=0/SUCCESS)
  Process: 30550 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 30464 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
  Process: 30439 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 30501 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 38 (limit: 101224)
   Memory: 379.8M
   CGroup: /system.slice/mysqld.service
           └─30501 /usr/libexec/mysqld --basedir=/usr

9月 26 17:42:22 hx-mysql-01 systemd[1]: Starting MySQL 8.0 database server...
9月 26 17:42:23 hx-mysql-01 systemd[1]: Started MySQL 8.0 database server.

Cambiar contraseña inicial

Obtener contraseña

grep "password" /var/log/mysql/mysqld.log

2019-09-26T09: 41: 56.912605Z 5 [Nota] [MY-010454] [Servidor] Se genera una contraseña temporal para root @ localhost: ju7Ic # aQwyIJ

Iniciar sesión

mysql -u root -p
ALTER USER 'root'@'%' IDENTIFIED BY '-你的密码-';
flush privileges;
exit;

Reiniciar el servicio MySQL

service mysqld restart;

Configurar MySQL para que se inicie automáticamente

systemctl habilitar mysqld


Configurar doble maestro y copia de seguridad

  • Anfitrión 1: 172.29.60.145
  • Anfitrión 2: 172.29.60.146

Durante la instalación 172.29.60.145y 172.29.60.146finalización de la instalación de MySQL, no copie directamente el host virtual.

Configurar archivos maestros y esclavos

Operar en el host 172.29.60.145

Modificar/etc/my.cnf

[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
binlog-ignore-db=mysql,test,infromation_schema,sys,performance_schema
binlog-do-db=test1
master-host=172.29.60.146
master-port=3306
master-user=root
master-pass=KONGKONG
master-retry-count=999
master-connect-retry=60
[mysqld]
log-bin=bin-log
server-id=145

Operar en el host 172.29.60.146

Modificar/etc/my.cnf

[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
binlog-ignore-db=mysql,test,infromation_schema,sys,performance_schema
binlog-do-db=test1
master-host=172.29.60.145
master-port=3306
master-user=root
master-pass=KONGKONG
master-retry-count=999
master-connect-retry=60
[mysqld]
log-bin=bin-log
server-id=146

Crear usuarios dedicados mutuos (repl)

Operar en el host 172.29.60.145

mysql -u root -p

mysql> CREATE USER 'repl'@'172.29.60.146' IDENTIFIED WITH mysql_native_password BY 'KONGKONG';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'172.29.60.146';
mysql> flush privileges;

Operar en el host 172.29.60.146

mysql -u root -p

mysql> CREATE USER 'repl'@'172.29.60.145' IDENTIFIED WITH mysql_native_password BY 'KONGKONG';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'172.29.60.145';
mysql> flush privileges;

Modificar marca de archivo de registro

Operar en el host 172.29.60.145

mysql> SHOW MASTER STATUS;
+----------------+----------+--------------+------------------+-------------------+
| File           | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------+----------+--------------+------------------+-------------------+
| bin-log.000002 |     3864 |              |                  |                   |
+----------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

Operar en el host 172.29.60.146

mysql> SHOW MASTER STATUS;
+----------------+----------+--------------+------------------+-------------------+
| File           | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+----------------+----------+--------------+------------------+-------------------+
| bin-log.000003 |     2443 |              |                  |                   |
+----------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

Operar en el host 172.29.60.145

STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='172.29.60.146',MASTER_USER='repl',MASTER_PASSWORD='KONGKONG',MASTER_LOG_FILE='bin-log.000003',MASTER_LOG_POS=2443;
START SLAVE;

Operar en el host 172.29.60.146

STOP SLAVE;
CHANGE MASTER TO MASTER_HOST='172.29.60.145',MASTER_USER='repl',MASTER_PASSWORD='KONGKONG',MASTER_LOG_FILE='bin-log.000002',MASTER_LOG_POS=3864;
START SLAVE;

Verifique si la configuración es exitosa

  • Slave_IO_Running : Sí
  • Slave_SQL_Running: Sí
    Si los dos parámetros anteriores son ambos Yes, la sincronización es exitosa.

Operar en el host 172.29.60.145

mysql> SHOW SLAVE STATUS;
+----------------------------------+---------------+-------------+-------------+---------------+-----------------+---------------------+------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+
| Slave_IO_State                   | Master_Host   | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File               | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID                          | Master_Info_File        | SQL_Delay | SQL_Remaining_Delay | Slave_SQL_Running_State                                | Master_Retry_Count | Master_Bind | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | Master_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position | Replicate_Rewrite_DB | Channel_Name | Master_TLS_Version | Master_public_key_path | Get_master_public_key |
+----------------------------------+---------------+-------------+-------------+---------------+-----------------+---------------------+------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+
| Waiting for master to send event | 172.29.60.146 | repl        |        3306 |            60 | bin-log.000004  |                 155 | hx-mysql-01-relay-bin.000002 |           320 | bin-log.000004        | Yes              | Yes               |                 |                     |                    |                        |                         |                             |          0 |            |            0 |                 155 |             534 | None            |                |             0 | No                 |                    |                    |                 |                   |                |                     0 | No                            |             0 |               |              0 |                |                             |              146 | 668ce869-f082-11e9-b456-ae0d77cbedee | mysql.slave_master_info |         0 |                NULL | Slave has read all relay log; waiting for more updates |              86400 |             |                         |                          |                |                    |                    |                   |             0 |                      |              |                    |                        |                     0 |
+----------------------------------+---------------+-------------+-------------+---------------+-----------------+---------------------+------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+
1 row in set (0.00 sec)

Operación: 172.29.60.146

mysql> SHOW SLAVE STATUS;
+----------------------------------+---------------+-------------+-------------+---------------+-----------------+---------------------+------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+
| Slave_IO_State                   | Master_Host   | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File               | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master | Master_SSL_Verify_Server_Cert | Last_IO_Errno | Last_IO_Error | Last_SQL_Errno | Last_SQL_Error | Replicate_Ignore_Server_Ids | Master_Server_Id | Master_UUID                          | Master_Info_File        | SQL_Delay | SQL_Remaining_Delay | Slave_SQL_Running_State                                | Master_Retry_Count | Master_Bind | Last_IO_Error_Timestamp | Last_SQL_Error_Timestamp | Master_SSL_Crl | Master_SSL_Crlpath | Retrieved_Gtid_Set | Executed_Gtid_Set | Auto_Position | Replicate_Rewrite_DB | Channel_Name | Master_TLS_Version | Master_public_key_path | Get_master_public_key |
+----------------------------------+---------------+-------------+-------------+---------------+-----------------+---------------------+------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+
| Waiting for master to send event | 172.29.60.145 | repl        |        3306 |            60 | bin-log.000003  |                 155 | hx-mysql-02-relay-bin.000002 |           320 | bin-log.000003        | Yes              | Yes               |                 |                     |                    |                        |                         |                             |          0 |            |            0 |                 155 |             534 | None            |                |             0 | No                 |                    |                    |                 |                   |                |                     0 | No                            |             0 |               |              0 |                |                             |              145 | 323720bf-f083-11e9-bc77-4e1da18bea09 | mysql.slave_master_info |         0 |                NULL | Slave has read all relay log; waiting for more updates |              86400 |             |                         |                          |                |                    |                    |                   |             0 |                      |              |                    |                        |                     0 |
+----------------------------------+---------------+-------------+-------------+---------------+-----------------+---------------------+------------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+-------------------------------+---------------+---------------+----------------+----------------+-----------------------------+------------------+--------------------------------------+-------------------------+-----------+---------------------+--------------------------------------------------------+--------------------+-------------+-------------------------+--------------------------+----------------+--------------------+--------------------+-------------------+---------------+----------------------+--------------+--------------------+------------------------+-----------------------+


Situación anormal

archivo de registro fuera de sincronización

Recibió el error grave 1236 del maestro al leer datos del registro binario: 'No se pudo encontrar el primer nombre del archivo de registro en el archivo de índice del registro binario'

  • El archivo de registro no está sincronizado, vuelva a ejecutar el paso tres

Esta operación no puede realizarse con un hilo esclavo io en ejecución; ejecute STOP SLAVE IO_THREAD FOR CHANNEL '' primero.

  • Ejecución: detener esclavo;

El subproceso de E / S esclava se detiene porque maestro y esclavo tienen identificadores de servidor MySQL iguales

修改/etc/my.cnf

[client-server]
!includedir /etc/my.cnf.d
binlog-ignore-db=mysql,test,infromation_schema,sys,performance_schema
binlog-do-db=test1
master-host=172.29.60.146
master-port=3306
master-user=root
master-pass=***
master-retry-count=999
master-connect-retry=60
[mysqld]
log-bin=bin-log
server-id=145

No se pudo ejecutar el evento Write_rows en la tabla test1.user; Entrada duplicada '12'

Debido a que el maestro desea eliminar un registro y el esclavo no puede encontrarlo, informa un error. En este caso, el maestro lo elimina, por lo que el esclavo puede omitirlo directamente. Comandos disponibles:

stop slave;
set global sql_slave_skip_counter=1;
start slave;
100 artículos originales publicados · Me gusta 106 · Visita 270,000+

Supongo que te gusta

Origin blog.csdn.net/lglglgl/article/details/102684131
Recomendado
Clasificación