centos安装主从mysql集群

news2024/11/15 7:04:44

在 CentOS 系统上安装和配置 MySQL 主从复制环境的步骤与 Debian/Ubuntu 系统有所不同。以下是在 CentOS 系统上进行配置的详细步骤:

步骤 1:在主服务器上安装和配置 MySQL(10.206.0.13)

  1. 安装 MySQL 服务器:

    • 首先,添加 MySQL Yum 仓库:
      sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
      
    • 接着,安装 MySQL 服务器:
      sudo yum install mysql-server
      
  2. 启动 MySQL 服务并设置开机自启:

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
  3. 安全配置 MySQL:

    • 初始安装完成后,MySQL 生成一个临时密码。使用以下命令查看密码:
      sudo grep 'temporary password' /var/log/mysqld.log
      
    • 运行安全安装脚本来设置 root 密码并完成其他安全设置:
      sudo mysql_secure_installation
      
  4. 配置 MySQL 以支持复制:

    • 编辑 MySQL 配置文件:
      sudo vi /etc/my.cnf
      
    • [mysqld] 部分添加以下配置:
      server-id=1
      log_bin=mysql-bin
      binlog_do_db=mydb  # 替换为你的数据库名
      
    • 保存并关闭文件。
  5. 重启 MySQL 服务:

    sudo systemctl restart mysqld
    
  6. 创建复制用户:

    • 登录 MySQL:
      mysql -u root -p
      
    • 创建复制用户并授予权限:
      CREATE USER 'replica'@'10.206.0.8' IDENTIFIED BY 'password';  -- 设置一个安全的密码
      GRANT REPLICATION SLAVE ON *.* TO 'replica'@'10.206.0.8';
      FLUSH PRIVILEGES;
      SHOW MASTER STATUS;
      
    • 记录 FilePosition 的值,稍后在从服务器上配置时将需要这些信息。

步骤 2:在从服务器上安装和配置 MySQL(10.206.0.8)

  1. 安装 MySQL 服务器:

    • 添加 MySQL Yum 仓库:
      sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
      
    • 安装 MySQL 服务器:
      sudo yum install mysql-server
      
  2. 启动 MySQL 服务并设置开机自启:

    sudo systemctl start mysqld
    sudo systemctl enable mysqld
    
  3. 安全配置 MySQL:

    • 查看初始临时密码:
      sudo grep 'temporary password' /var/log/mysqld.log
      
    • 运行安全安装脚本:
      sudo mysql_secure_installation
      
  4. 配置 MySQL 以支持复制:

    • 编辑 MySQL 配置文件:
      sudo vi /etc/my.cnf
      
    • [mysqld] 部分添加以下配置:
      server-id=2
      relay_log=mysql-relay-bin
      
    • 保存并关闭文件。
  5. 重启 MySQL 服务:

    sudo systemctl restart mysqld
    
  6. 配置从服务器以连接到主服务器:

    • 登录 MySQL:
      mysql -u root -p
      
    • 设置复制并开始复制过程:
      CHANGE MASTER TO
      MASTER_HOST='10.206.0.13',
      MASTER_USER='replica',
      MASTER_PASSWORD='password',  -- 主服务器上设置的密码
      MASTER_LOG_FILE='之前记录的文件名',
      MASTER_LOG_POS=之前记录的位置;
      
      START SLAVE;
      
      SHOW SLAVE STATUS\G
      
    • 确保 `Slave_IO_R

主服务器的安装记录

Welcome to TencentOS 3 64bit
Version 3.1 20230621
tlinux3.1-64bit-5.4.119-19.0009.28-20230621
Last failed login: Sat Jan 20 14:01:05 CST 2024 from 85.209.11.254 on ssh:notty
There were 66324 failed login attempts since the last successful login.
Last login: Sun Jan  7 16:08:16 2024 from 114.84.30.36
[root@node1 ~]# sudo apt update
sudo: apt: command not found
[root@node1 ~]# ls
Changelog  tmp.log
[root@node1 ~]# cd /home
[root@node1 home]# ls
postgresql-master
[root@node1 home]# docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED       STATUS       PORTS                                       NAMES
3e97b56c1293   postgres   "docker-entrypoint.s…"   12 days ago   Up 12 days   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   postgres-master
[root@node1 home]# mkdir mysql-master
[root@node1 home]# ls
mysql-master  postgresql-master
[root@node1 home]# cd mysql-master/
[root@node1 mysql-master]# ls
[root@node1 mysql-master]# cd sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
-bash: cd: too many arguments
[root@node1 mysql-master]# sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Repository docker-ce-stable is listed more than once in the configuration
Repository docker-ce-stable-source is listed more than once in the configuration
Repository docker-ce-test is listed more than once in the configuration
Repository docker-ce-test-source is listed more than once in the configuration
TencentOS Server 3.1 - TencentOS                                                                                          46 kB/s | 3.8 kB     00:00    
TencentOS Server 3.1 - Updates                                                                                            44 kB/s | 3.8 kB     00:00    
TencentOS Server 3.1 - Updates                                                                                            11 MB/s |  30 MB     00:02    
TencentOS Server 3.1 - TencentOS-AppStream                                                                                55 kB/s | 4.2 kB     00:00    
TencentOS Server 3.1 - TencentOS-AppStream                                                                                15 MB/s |  20 MB     00:01    
TencentOS Server 3.1 - Base                                                                                               41 kB/s | 3.0 kB     00:00    
TencentOS Server 3.1 - AppStream                                                                                          32 kB/s | 2.9 kB     00:00    
TencentOS Server 3.1 - Extras                                                                                             35 kB/s | 3.0 kB     00:00    
TencentOS Server 3.1 - Extras                                                                                            127 kB/s |  25 kB     00:00    
TencentOS Server 3.1 - PowerTools                                                                                         31 kB/s | 3.0 kB     00:00    
Docker CE Stable - x86_64                                                                                                 47 kB/s | 3.5 kB     00:00    
Extra Packages for TencentOS Server 3.1 - x86_64                                                                         257 kB/s | 4.7 kB     00:00    
Extra Packages for TencentOS Server 3.1 - x86_64                                                                          27 MB/s |  16 MB     00:00    
Extra Packages for TencentOS Server 3.1 Modular - x86_64                                                                 186 kB/s | 3.0 kB     00:00    
Kubernetes                                                                                                                20 kB/s | 1.4 kB     00:00    
mysql80-community-release-el7-3.noarch.rpm                                                                               5.7 kB/s |  25 kB     00:04    
Dependencies resolved.
=========================================================================================================================================================
 Package                                          Architecture                  Version                        Repository                           Size
=========================================================================================================================================================
Installing:
 mysql80-community-release                        noarch                        el7-3                          @commandline                         25 k

Transaction Summary
=========================================================================================================================================================
Install  1 Package

Total size: 25 k
Installed size: 31 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                 1/1 
  Installing       : mysql80-community-release-el7-3.noarch                                                                                          1/1 
  Verifying        : mysql80-community-release-el7-3.noarch                                                                                          1/1 

Installed:
  mysql80-community-release-el7-3.noarch                                                                                                                 

Complete!
[root@node1 mysql-master]# sudo yum install mysql-server
Repository docker-ce-stable is listed more than once in the configuration
Repository docker-ce-stable-source is listed more than once in the configuration
Repository docker-ce-test is listed more than once in the configuration
Repository docker-ce-test-source is listed more than once in the configuration
MySQL 8.0 Community Server                                                                                               1.1 MB/s | 3.3 MB     00:03    
MySQL Connectors Community                                                                                                68 kB/s |  68 kB     00:00    
MySQL Tools Community                                                                                                    472 kB/s | 1.1 MB     00:02    
Dependencies resolved.
=========================================================================================================================================================
 Package                        Architecture            Version                                               Repository                            Size
=========================================================================================================================================================
Installing:
 mysql-server                   x86_64                  8.0.32-1.module+el8.8.0+484+537fff7e                  TencentOS-AppStream                   32 M
Installing dependencies:
 mecab                          x86_64                  0.996-2.module+el8.8.0+484+537fff7e                   TencentOS-AppStream                  392 k
 mysql-errmsg                   x86_64                  8.0.32-1.module+el8.8.0+484+537fff7e                  TencentOS-AppStream                  628 k
 protobuf-lite                  x86_64                  3.5.0-15.tl3                                          Updates                              148 k

Transaction Summary
=========================================================================================================================================================
Install  4 Packages

Total download size: 33 M
Installed size: 171 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): protobuf-lite-3.5.0-15.tl3.x86_64.rpm                                                                             635 kB/s | 148 kB     00:00    
(2/4): mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64.rpm                                                              1.2 MB/s | 392 kB     00:00    
(3/4): mysql-errmsg-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64.rpm                                                      1.6 MB/s | 628 kB     00:00    
(4/4): mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64.rpm                                                       17 MB/s |  32 MB     00:01    
---------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                     16 MB/s |  33 MB     00:02     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                 1/1 
  Installing       : mysql-errmsg-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        1/4 
  Installing       : mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64                                                                                2/4 
  Running scriptlet: mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64                                                                                2/4 
  Installing       : protobuf-lite-3.5.0-15.tl3.x86_64                                                                                               3/4 
  Running scriptlet: mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        4/4 
  Installing       : mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        4/4 
  Running scriptlet: mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        4/4 
ValueError: File context for /var/log/mysql(/.*)? already defined

  Verifying        : protobuf-lite-3.5.0-15.tl3.x86_64                                                                                               1/4 
  Verifying        : mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64                                                                                2/4 
  Verifying        : mysql-errmsg-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        3/4 
  Verifying        : mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        4/4 

Installed:
  mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64                            mysql-errmsg-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                   
  mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                    protobuf-lite-3.5.0-15.tl3.x86_64                                          

Complete!
[root@node1 mysql-master]# sudo systemctl start mysqld
[root@node1 mysql-master]# sudo systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@node1 mysql-master]# sudo systemctl enable mysqld
[root@node1 mysql-master]# sudo grep 'temporary password' /var/log/mysqld.log
grep: /var/log/mysqld.log: No such file or directory
[root@node1 mysql-master]# sudo grep 'shtc@2024' /var/log/mysqld.log
grep: /var/log/mysqld.log: No such file or directory
[root@node1 mysql-master]# cd /var
[root@node1 var]# ls
account  adm  cache  crash  db  empty  ftp  games  gopher  kerberos  lib  local  lock  log  mail  nis  opt  preserve  run  spool  tmp  yp
[root@node1 var]# cd lo
local/ lock/  log/   
[root@node1 var]# cd lo
local/ lock/  log/   
[root@node1 var]# cd log
[root@node1 log]# ls
anaconda           cloud-init.log         dnf.librepo.log      lastlog            messages-20231231  secure            spooler-20240107
audit              cloud-init-output.log  dnf.log              maillog            messages-20240107  secure-20231224   spooler-20240114
boot.log           containers             dnf.rpm.log          maillog-20231224   messages-20240114  secure-20231231   sssd
boot.log-20231214  cron                   hawkey.log           maillog-20231231   mysql              secure-20240107   wtmp
boot.log-20231220  cron-20231224          hawkey.log-20231217  maillog-20240107   pods               secure-20240114
btmp               cron-20231231          hawkey.log-20231224  maillog-20240114   private            spooler
btmp-20240101      cron-20240107          iptraf-ng            messages           qcloud_action.log  spooler-20231224
chrony             cron-20240114          kdump.log            messages-20231224  sa                 spooler-20231231
[root@node1 log]# cd mysql
[root@node1 mysql]# ls
mysqld.log
[root@node1 mysql]# sudo grep 'shtc@2024' /var/log/mysql/mysqld.log
[root@node1 mysql]# sudo 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?

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

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password: 

Re-enter new password: 
Sorry, passwords do not match.

New password: 

Re-enter new password: 

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.

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.

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.


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.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
[root@node1 mysql]# 
[root@node1 mysql]# sudo vi /etc/my.cnf
[root@node1 mysql]# sudo vi /etc/my.cnf
[root@node1 mysql]# cd  /etc/my.cnf.d/
[root@node1 my.cnf.d]# ls
client.cnf  mysql-default-authentication-plugin.cnf  mysql-server.cnf
[root@node1 my.cnf.d]# vi mysql-server.cnf 
[root@node1 my.cnf.d]# sudo systemctl restart mysqld
[root@node1 my.cnf.d]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 Source distribution

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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.

mysql> CREATE USER 'replica'@'10.206.0.8' IDENTIFIED BY 'Shtc@2024';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO 'replica'@'10.206.0.8';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

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

mysql> 

从服务器的安装记录

Welcome to TencentOS 3 64bit
Version 3.1 20230621
tlinux3.1-64bit-5.4.119-19.0009.28-20230621
Last failed login: Sat Jan 20 14:19:36 CST 2024 from 157.245.199.76 on ssh:notty
There were 52883 failed login attempts since the last successful login.
Last login: Sun Jan  7 16:09:23 2024 from 114.84.30.36
[root@node2 ~]# sudo yum install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Repository docker-ce-stable is listed more than once in the configuration
Repository docker-ce-stable-source is listed more than once in the configuration
Repository docker-ce-test is listed more than once in the configuration
Repository docker-ce-test-source is listed more than once in the configuration
TencentOS Server 3.1 - TencentOS                                                                                          48 kB/s | 3.8 kB     00:00    
TencentOS Server 3.1 - Updates                                                                                            46 kB/s | 3.8 kB     00:00    
TencentOS Server 3.1 - Updates                                                                                            26 MB/s |  30 MB     00:01    
TencentOS Server 3.1 - TencentOS-AppStream                                                                                51 kB/s | 4.2 kB     00:00    
TencentOS Server 3.1 - TencentOS-AppStream                                                                                20 MB/s |  20 MB     00:01    
TencentOS Server 3.1 - Base                                                                                               38 kB/s | 3.0 kB     00:00    
TencentOS Server 3.1 - AppStream                                                                                          35 kB/s | 2.9 kB     00:00    
TencentOS Server 3.1 - Extras                                                                                             37 kB/s | 3.0 kB     00:00    
TencentOS Server 3.1 - Extras                                                                                            123 kB/s |  25 kB     00:00    
TencentOS Server 3.1 - PowerTools                                                                                         37 kB/s | 3.0 kB     00:00    
Docker CE Stable - x86_64                                                                                                 43 kB/s | 3.5 kB     00:00    
Extra Packages for TencentOS Server 3.1 - x86_64                                                                         241 kB/s | 4.7 kB     00:00    
Extra Packages for TencentOS Server 3.1 - x86_64                                                                          26 MB/s |  16 MB     00:00    
Extra Packages for TencentOS Server 3.1 Modular - x86_64                                                                 136 kB/s | 3.0 kB     00:00    
Kubernetes                                                                                                                47 kB/s | 1.4 kB     00:00    
mysql80-community-release-el7-3.noarch.rpm                                                                               7.6 kB/s |  25 kB     00:03    
Dependencies resolved.
=========================================================================================================================================================
 Package                                          Architecture                  Version                        Repository                           Size
=========================================================================================================================================================
Installing:
 mysql80-community-release                        noarch                        el7-3                          @commandline                         25 k

Transaction Summary
=========================================================================================================================================================
Install  1 Package

Total size: 25 k
Installed size: 31 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                 1/1 
  Installing       : mysql80-community-release-el7-3.noarch                                                                                          1/1 
  Verifying        : mysql80-community-release-el7-3.noarch                                                                                          1/1 

Installed:
  mysql80-community-release-el7-3.noarch                                                                                                                 

Complete!
[root@node2 ~]# sudo yum install mysql-server
Repository docker-ce-stable is listed more than once in the configuration
Repository docker-ce-stable-source is listed more than once in the configuration
Repository docker-ce-test is listed more than once in the configuration
Repository docker-ce-test-source is listed more than once in the configuration
MySQL 8.0 Community Server                                                                                                95 kB/s | 3.3 MB     00:35    
MySQL Connectors Community                                                                                                16 kB/s |  68 kB     00:04    
MySQL Tools Community                                                                                                     80 kB/s | 1.1 MB     00:14    
Dependencies resolved.
=========================================================================================================================================================
 Package                        Architecture            Version                                               Repository                            Size
=========================================================================================================================================================
Installing:
 mysql-server                   x86_64                  8.0.32-1.module+el8.8.0+484+537fff7e                  TencentOS-AppStream                   32 M
Installing dependencies:
 mecab                          x86_64                  0.996-2.module+el8.8.0+484+537fff7e                   TencentOS-AppStream                  392 k
 mysql-errmsg                   x86_64                  8.0.32-1.module+el8.8.0+484+537fff7e                  TencentOS-AppStream                  628 k
 protobuf-lite                  x86_64                  3.5.0-15.tl3                                          Updates                              148 k

Transaction Summary
=========================================================================================================================================================
Install  4 Packages

Total download size: 33 M
Installed size: 171 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): protobuf-lite-3.5.0-15.tl3.x86_64.rpm                                                                             670 kB/s | 148 kB     00:00    
(2/4): mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64.rpm                                                              1.2 MB/s | 392 kB     00:00    
(3/4): mysql-errmsg-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64.rpm                                                      1.4 MB/s | 628 kB     00:00    
(4/4): mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64.rpm                                                       10 MB/s |  32 MB     00:03    
---------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                    9.8 MB/s |  33 MB     00:03     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                 1/1 
  Installing       : mysql-errmsg-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        1/4 
  Installing       : mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64                                                                                2/4 
  Running scriptlet: mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64                                                                                2/4 
  Installing       : protobuf-lite-3.5.0-15.tl3.x86_64                                                                                               3/4 
  Running scriptlet: mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        4/4 
  Installing       : mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        4/4 
  Running scriptlet: mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        4/4 
ValueError: File context for /var/log/mysql(/.*)? already defined

  Verifying        : protobuf-lite-3.5.0-15.tl3.x86_64                                                                                               1/4 
  Verifying        : mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64                                                                                2/4 
  Verifying        : mysql-errmsg-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        3/4 
  Verifying        : mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                                                                        4/4 

Installed:
  mecab-0.996-2.module+el8.8.0+484+537fff7e.x86_64                            mysql-errmsg-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                   
  mysql-server-8.0.32-1.module+el8.8.0+484+537fff7e.x86_64                    protobuf-lite-3.5.0-15.tl3.x86_64                                          

Complete!
[root@node2 ~]# sudo systemctl start mysqld
[root@node2 ~]# sudo systemctl enable mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@node2 ~]# sduo grep 'shtc@2024' /var/log/mysql/mysqld.log 
bash: sduo: command not found...
Similar command is: 'sudo'
[root@node2 ~]# grep 'shtc@2024' /var/log/mysql/mysqld.log 
[root@node2 ~]# sudo 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?

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

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password: 

Re-enter new password: 

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.

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.

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.


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.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
[root@node2 ~]# sudo vi /etc/my.cnf
[root@node2 ~]# cd  /etc/my.cnf/
-bash: cd: /etc/my.cnf/: Not a directory
[root@node2 ~]# cd /etc/my.cnf.d/
[root@node2 my.cnf.d]# ls
client.cnf  mysql-default-authentication-plugin.cnf  mysql-server.cnf
[root@node2 my.cnf.d]# vi mysql-server.cnf 
[root@node2 my.cnf.d]# sudo systemctl restart mysqld
[root@node2 my.cnf.d]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 Source distribution

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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.

mysql> CHANGE MASTER TO
    -> MASTER_HOST='10.206.0.13',
    -> MASTER_USER='replica',
    -> MASTER_PASSWORD='password',  -- 主服务器上设置的密码
    -> MASTER_LOG_FILE='之前记录的文件名',
    -> MASTER_LOG_POS=之前记录的位置;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '之前记录的位置' at line 6
mysql> 
mysql> START SLAVE;
ERROR 1200 (HY000): The server is not configured as slave; fix in config file or with CHANGE MASTER TO
mysql> 
mysql> SHOW SLAVE STATUS\G
Empty set, 1 warning (0.00 sec)

mysql> CHANGE MASTER TO
    -> MASTER_HOST='10.206.0.13',
    -> MASTER_USER='replica',
    -> MASTER_PASSWORD='Shtc@2024',
    -> MASTER_LOG_FILE='mysql-bin.000001',
    -> MASTER_LOG_POS=851;
Query OK, 0 rows affected, 8 warnings (0.02 sec)

mysql> START SLAVE;
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> show SLAVE STATUS\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 10.206.0.13
                  Master_User: replica
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 851
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 326
        Relay_Master_Log_File: mysql-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: 851
              Relay_Log_Space: 536
              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: 0
Master_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: 65496a81-b75a-11ee-8979-5254005b393e
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica 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: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set, 1 warning (0.00 sec)

ERROR: 
No query specified

mysql> show SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for source to send event
                  Master_Host: 10.206.0.13
                  Master_User: replica
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 851
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 326
        Relay_Master_Log_File: mysql-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: 851
              Relay_Log_Space: 536
              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: 0
Master_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: 65496a81-b75a-11ee-8979-5254005b393e
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica 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: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set, 1 warning (0.00 sec)

mysql> 

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1398444.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

NeRF资料整理

文章目录 1.NeRF原理讲解2.NeRF中用到的NDC空间坐标系3.NeRF中的sample_pdf概率采样函数 1.NeRF原理讲解 nerf 原理讲解:这个视频对NeRF中体渲染公式的讲解和推导非常好,言简意赅,而且和论文、代码都可以对应上。 2.NeRF中用到的NDC空间坐标…

【AI】ChatGPT和文心一言那个更好用

大家好,我是全栈小5,欢迎阅读文章! 此篇是【话题达人】序列文章,这一次的话题是《自然语言处理的发展》 文章将以博主的角度进行讲述,理解和水平有限,不足之处,望指正。 目录 背景自我介绍面试题…

linux 定时任务 crontab 使用笔记

最近在服务器上跑撸茅台的脚本,需要使用定时任务每天早上9点准时预约一次抢茅台的脚本,因此需要用到 crontab 命令。crontab主要是用于设置周期性执行命令,比如每分钟、每小时或者每周执行一个固定的命令,该命令从标准输入设备读取…

靶场实战(18):OSCP备考之VulnHub MY CMSMS

打靶思路 资产发现 主机发现服务发现漏洞发现(获取权限) 80端口/HTTP服务 组件漏洞URL漏洞3306端口/MySQL服务 组件漏洞口令漏洞80端口/HTTP服务 URL漏洞URL漏洞提升权限 www-data用户 sudosuidcron内核提权信息收集armour用户 sudo 1、资产发现 1.1…

Pytest系列(2) - assert断言详细使用

前言 与unittest不同,pytest使用的是python自带的assert关键字来进行断言assert关键字后面可以接一个表达式,只要表达式的最终结果为True,那么断言通过,用例执行成功,否则用例执行失败 assert小栗子 想在抛出异常之…

基于ssm+vue的宠物医院系统(前后端分离)

博主主页:猫头鹰源码 博主简介:Java领域优质创作者、CSDN博客专家、公司架构师、全网粉丝5万、专注Java技术领域和毕业设计项目实战 主要内容:毕业设计(Javaweb项目|小程序等)、简历模板、学习资料、面试题库、技术咨询 文末联系获取 项目背景…

01 MyBatisPlus快速入门

1. MyBatis-Plus快速入门 版本 3.5.31并非另起炉灶 , 而是MyBatis的增强 , 使用之前依然要导入MyBatis的依赖 , 且之前MyBatis的所有功能依然可以使用.局限性是仅限于单表操作, 对于多表仍需要手写 项目结构: 先导入依赖,比之前多了一个mybatis-plus…

肌营养不良患者生活质量的“提升”

肌营养不良患者基本上是生活无法自理的,那么作为肌营养不良患者的家属,提升病人的生活质量就迫在眉睫。看了这篇文章你就知道该怎么做了。 ①保持生活环境整洁 肌营养不良患者本身体质较弱,而且后期会卧病在床,为了防止并发症的发…

【机组】算术逻辑单元带进位运算实验的解密与实战

​🌈个人主页:Sarapines Programmer🔥 系列专栏:《机组 | 模块单元实验》⏰诗赋清音:云生高巅梦远游, 星光点缀碧海愁。 山川深邃情难晤, 剑气凌云志自修。 ​ 目录 🌺一、 实验目…

Python初识——小小爬虫

一、找到网页端url 打开浏览器,打开百度官方网页点击图片,打开百度图片 鼠标齿轮向下滑,点击宠物图片 进入宠物图片网页,在网页空白处点击鼠标右键,弹出的框中最下方显示“检查”选项,点击(我是…

AIGC - 视频生成模型的相关算法进展

欢迎关注我的CSDN:https://spike.blog.csdn.net/ 本文地址:https://spike.blog.csdn.net/article/details/135688206 视频生成技术确实是一个很有潜力的颠覆性技术领域,可以作为企业创新梯队的重点关注方向,最近发展很快&#xff…

使用 FFmpeg 轻松调整视频的大小/缩放/更改分辨率

在此 FFmpeg 教程中,我们学习使用 FFmpeg 的命令行工具更改视频的分辨率(或调整视频的大小/缩放)。 更改视频的分辨率(也称为调整大小或缩放)是视频编辑、处理和压缩中非常常见的操作。对于 ABR 视频流尤其如此&#…

激光无人机打击系统——光束控制和指向系统

激光无人机(UAV)打击系统中的光束控制和指向系统通常包括以下几个关键组件和技术: 激光发射器:这是系统的核心,负责生成高能量的激光束。常用的激光类型包括固体激光器、化学激光器、光纤激光器等,选择取决…

组件(Component):可重用的元素

目标效果:点击粉色按钮后,出现一行“为什么非要点我?”的文字。 用组件的方式实现:首先单击项目文件夹01,然后右键弹窗中点击“添加新文件” 。 选择 QML File 文件: 文件名就叫Button,然后把代…

基于springboot+vue摄影分享管理系统

摘要 摄影分享管理系统是一款全栈应用,采用了Spring Boot和Vue.js作为技术基础。旨在为摄影爱好者提供便捷而强大的平台,用户可以在这里展示、分享和管理自己的摄影作品。系统具备完善的用户管理功能,包括注册、登录和个人信息编辑&#xff0…

css 3D立体动画效果怎么转这个骰子才能看到5

css 3D立体动画效果怎么转这个骰子才能看到5 <!DOCTYPE html> <html lang"zh-CN"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><meta http-equ…

【C++】unordered_map,unordered_set模拟实现

unordered_map&#xff0c;unordered_set模拟实现 插入普通迭代器const迭代器unordered_map的[ ]接口实现查找修改哈希桶完整代码unordered_map完整代码unordered_set完整代码 喜欢的点赞&#xff0c;收藏&#xff0c;关注一下把&#xff01; 上一篇文章我们把unordered_map和u…

阿里云服务器怎么样?阿里云服务器优势、价格及常见问题

阿里云服务器ECS英文全程Elastic Compute Service&#xff0c;云服务器ECS是一种安全可靠、弹性可伸缩的云计算服务&#xff0c;阿里云提供多种云服务器ECS实例规格&#xff0c;如ECS经济型e实例、通用算力型u1、ECS计算型c7、通用型g7、GPU实例等&#xff0c;阿里云服务器网al…

中仕教育:三支一扶的优势有哪些?

"三支"指的是支农、支教、支医&#xff0c;"一扶"则是扶持基层。这是一项为了解决农村地区教育、医疗和农业发展问题&#xff0c;同时提供一定的就业保障的政策&#xff0c;大专学历即可报考。 "三支一扶"有哪些优势? 参与"三支一扶&quo…

《WebKit 技术内幕》之四(3): 资源加载和网络栈

3. 网络栈 3.1 WebKit的网络设施 WebKit的资源加载其实是交由各个移植来实现的&#xff0c;所以WebCore其实并没有什么特别的基础设施&#xff0c;每个移植的网络实现是非常不一样的。 从WebKit的代码结构中可以看出&#xff0c;网络部分代码的确比较少的&#xff0c;它们都在…