A Instalação do Servidor MySQL no Sistema Operacional Linux CentOS 8, o MySQL é um Sistema de Gerenciamento de Banco de Dados mais usado no mundo, disponíveis em varias versões, a que vamos instalar é a versão MySQL 8.0.21.
A plataforma usada no MySQL é Open Source onde o Wordpress, Joomla e Drupal usam para sua base de dados.
A instalação será realizada em linha de comando Linux a tela preta, onde gosto muito de trabalhar e vamos aproveitar o trabalho anterior para implementar vários serviços o trabalho anterior é Rede Básica com Armazenamento Storage iSCSI Linux, um projeto de rede que ajuda muitas pessoas em montar um rede básica para uma empresa.
Vou instalar o MySQL 8 com autenticação SSL/TLS depois fazer o backup com o comando MYSQLDUMP e uma demonstração de Clone de Feature, que foi aplicada a partir da versão 8.0.17 e no final vamos fazer uma demonstração de replicação de banco.
A imagem é para ilustrar todo o processo de instalação começando com a Instalação do MySQL 8.0.
Linux Na Janela
Usuario Admin: root - linuxnajanela
Usuario SSL: linuxnajanelassl - Linuxnajanela@123
Usuario: linuxnajanela - Linuxnajanela@123
usuario Replicação: linuxnajanelarepl - Linuxnajanela@123
Usuario Clone: clone_db - Linuxnajanela@123
Instalando o MySQL 8.0.
[root@linuxnajanela ~]# dnf module -y install mysql:8.0 [root@linuxnajanela ~]# nano /etc/my.cnf.d/mysql-server.cnf # linha 21 : configurar como padrão o charaset se precisar. [mysqld] character-set-server=utf8mb4 systemctl enable --now mysqld |
| [root@linuxnajanela ~]# firewall-cmd --add-service=mysql --permanent success [root@linuxnajanela ~]# firewall-cmd --reload success |
| [root@linuxnajanela ~]# mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? # habilitar a politica de senha ou não, vai ser definida pelo administrador Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file # seleciona a politica de senha dificil Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. # Configure MySQL root password New password: Re-enter new password: # confirmação da entrada de senha Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. # remover o usuário anonymous ou não Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. # disabilitar root login remotamente ou não Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. # remover o banco de teste ou não Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. # recarregar os previlégios das tabelas ou não Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done! # conectar no MySQL com root [root@linuxnajanela ~]# mysql -u root -p Enter password: # coloque a senha Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.17 Source distribution Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # mostrar a lista de usuários mysql> select user,host from mysql.user; # mostra os banco de dados mysql> show databases; mysql> create database linuxnajaneladb; mysql> create table linuxnajaneladb.linuxnajanela (id int, nome varchar(50), endereco varchar(50), primary key (id)); mysql> insert into linuxnajaneladb.linuxnajanela(id, nome, endereco) values("001", "Kelsey Santos", "Cuiabá - MT"); mysql> select * from linuxnajaneladb.linuxnajanela; # deleta o banco de dados criado mysql> drop database linuxnajaneladb; mysql> exit Bye |
Explicando como é a conexão como Configurar MySQL com SSL/TLS
Realizar Backup com o Comando mysqldump
# Bloquear todas as tabelas e realizar dump dos dados no MySQL # durante o processo de backup, o banco fica bloqueado e só é liberado após o termino do backup [root@linuxnajanela ~]# mysqldump -u root -p --lock-all-tables --all-databases --events > mysql_backup_data.sql Enter password: # dump de todo o banco sem bloqueio mais adiciona as transações # a integridade dos dados é garantida no comando --single-transaction [root@linuxnajanela ~]# mysqldump -u root -p --single-transaction --all-databases --events > mysql_backup_data.sql Enter password: linuxnajanela # dump de um banco de dados especifico [root@linuxnajanela ~]# mysqldump -u root -p linuxnajaneladb --single-transaction --events > mysql_backup_data.sql Enter password: |
Restaurando o banco de dados
# restaurar todos os bancos de dados em um simples restore [root@srvmysql2 ~]# mysql -u root -p < mysql_backup_data.sql Enter password: # para importar um banco especifico você precisa criar um banco vazio primeiro. [root@srvmysql2 ~]# mysql -u root -p linuxnajaneladb < mysql_backup_data.sql Enter password: |
Habilita a função de clone, lembrando que tem q observar a versão do MySQL.
# Verificar versão do MySQL [root@linuxnajanela ~]# mysqld --version /usr/libexec/mysqld Ver 8.0.17 for Linux on x86_64 (Source distribution) [root@linuxnajanela ~]# vi /etc/my.cnf.d/mysql-server.cnf # adiciona ao final da linha [mysqld] ..... ..... plugin-load=mysql_clone.so [root@linuxnajanela ~]# [root@linuxnajanela ~]# systemctl restart mysqld mysql -u root -p -e "select plugin_name, plugin_status, plugin_type from information_schema.plugins where plugin_name = 'clone';" Enter password: +-------------+---------------+-------------+ | plugin_name | plugin_status | plugin_type | +-------------+---------------+-------------+ | clone | ACTIVE | CLONE | +-------------+---------------+-------------+ |
[root@linuxnajanela ~]# mkdir /var/www/html/backupmysql [root@linuxnajanela ~]# chown mysql. /var/www/html/backupmysql [root@linuxnajanela ~]# [root@linuxnajanela ~]# mysql -u root -p -e "clone local data directory = '/var/www/html/backupmysql/';" ll /var/www/html/backupmysql/clone total 166916 drwxr-x---. 2 mysql mysql 89 Nov 26 19:55 '#clone' -rw-r-----. 1 mysql mysql 3367 Nov 26 19:55 ib_buffer_pool -rw-r-----. 1 mysql mysql 12582912 Nov 26 19:55 ibdata1 -rw-r-----. 1 mysql mysql 50331648 Nov 26 19:55 ib_logfile0 -rw-r-----. 1 mysql mysql 50331648 Nov 26 19:55 ib_logfile1 drwxr-x---. 2 mysql mysql 6 Nov 26 19:55 mysql -rw-r-----. 1 mysql mysql 24117248 Nov 26 19:55 mysql.ibd drwxr-x---. 2 mysql mysql 28 Nov 26 19:55 sys drwxr-x---. 2 mysql mysql 28 Nov 26 19:55 linuxnajaneladb -rw-r-----. 1 mysql mysql 10485760 Nov 26 19:55 undo_001 -rw-r-----. 1 mysql mysql 10485760 Nov 26 19:55 undo_002 |
# Este é o Donor [root@linuxnajanela ~]# mysql -u root -p Enter password: mysql> create user 'clone_db'@'%' identified by 'Linuxnajanela@123'; mysql> grant BACKUP_ADMIN on *.* to 'clone_db'@'%'; # Este é o Recipient[root@srvmysql2 ~]# Enter password: mysql> create user 'clone_db'@'%' identified by 'Linuxnajanela@123'; mysql> grant CLONE_ADMIN on *.* to 'clone_db'@'%'; mysql> set global clone_valid_donor_list = '172.16.0.41:3306'; mysql> select STATE from performance_schema.clone_status; mysql> clone instance from clone_db@172.16.0.41:3306 identified by 'Linuxnajanela@123' data directory = '/backup/'; |
Configurar Replicação do Banco de Dados em Outro Servidor.
Replicação MySQL 8.0
Configurando o Master
[root@linuxnajanela ~]# nano /etc/my.cnf.d/mysql-server.cnf [mysqld] log-bin=mysql-bin server-id=101 plugin-load=mysql_clone.so [root@linuxnajanela ~]# [root@linuxnajanela ~]# systemctl restart mysqld mysql -u root -p Enter password: mysql> create user 'Linuxnajanelarepl'@'%' identified by 'Linuxnajanela@123'; mysql> grant replication slave on *.* to Linuxnajanelarepl@'%'; mysql> flush privileges; mysql> exit Bye |
Configurando o SLAVE
[root@srvmysql2 ~]# nano /etc/my.cnf.d/mysql-server.cnf [mysqld] log-bin=mysql-bin server-id=102 plugin-load=mysql_clone.so read_only=1 report-host=172.16.0.42 [root@srvmysql2 ~]# [root@srvmysql2 ~]# systemctl restart mysqld mysql -u root -p Enter password: # Se não configurou ainda o clone ai abaixo só pra relembrar mysql> create user 'clone_db'@'%' identified by 'Linuxnajanela@123'; mysql> grant clone_admin on *.* to 'clone_db'@'%'; mysql> flush privileges; mysql> exit Bye |
Ainda no Servidor SLAVE
| [root@srvmysql2 ~]# mysql -u root -p Enter password: mysql> set global clone_valid_donor_list = '172.16.0.41:3306'; # Inicia o Clone mysql> clone instance from clone_db@172.16.0.41:3306 identified by 'Linuxnajanela@123'; # confirma o status # Se Ok mysql> select ID,STATE,SOURCE,DESTINATION,BINLOG_FILE,BINLOG_POSITION from performance_schema.clone_status; +------+-----------+----------------+----------------+------------------+-----------------+ | ID | STATE | SOURCE | DESTINATION | BINLOG_FILE | BINLOG_POSITION | +------+-----------+----------------+----------------+------------------+-----------------+ | 1 | Completed | 172.16.0.41:3306 | LOCAL INSTANCE | mysql-bin.000001 | 845 | +------+-----------+----------------+----------------+------------------+-----------------+ 1 row in set (0.01 sec) mysql> change master to -> master_host='172.16.0.41', # Master IP -> master_ssl=1, # SSL connection -> master_log_file='mysql-bin.000001', # [BINLOG_FILE] -> master_log_pos=845; # [BINLOG_POSITION] Query OK, 0 rows affected (0.35 sec) # start na replicação mysql> start slave user='Linuxnajanelarepl' password='Linuxnajanela@123'; Query OK, 0 rows affected, 1 warning (0.07 sec) mysql> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 172.16.0.41 Master_User: Linuxnajanelarepl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000001 |

Comentários
Postar um comentário