docker+mysql+主主配置+keepalived实现IP漂移

4 篇文章 0 订阅
1 篇文章 0 订阅

数据库安装

[root@667182a79e0d ~]#
[root@667182a79e0d ~]# mkdir /etc/mysql
[root@667182a79e0d ~]# cd etc/mysql/
-bash: cd: etc/mysql/: No such file or directory
[root@667182a79e0d ~]# cd /etc/mysql/
[root@667182a79e0d mysql]# yum install wget -y
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                   Arch                                        Version                                                 Repository                                 Size
===============================================================================================================================================================================================
Installing:
 wget                                      x86_64                                      1.14-18.el7_6.1                                         base                                      547 k

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

Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm                                                                                                                                         | 547 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7_6.1.x86_64                                                                                                                                                 1/1
install-info: No such file or directory for /usr/share/info/wget.info.gz
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                                                                                                                                 1/1

Installed:
  wget.x86_64 0:1.14-18.el7_6.1

Complete!
[root@667182a79e0d mysql]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
--2020-06-18 10:16:39--  https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm [following]
--2020-06-18 10:16:44--  https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.86.185.42
Connecting to repo.mysql.com (repo.mysql.com)|104.86.185.42|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26024 (25K) [application/x-redhat-package-manager]
Saving to: 'mysql80-community-release-el7-3.noarch.rpm'

100%[=====================================================================================================================================================>] 26,024       141KB/s   in 0.2s

2020-06-18 10:16:45 (141 KB/s) - 'mysql80-community-release-el7-3.noarch.rpm' saved [26024/26024]

[root@667182a79e0d mysql]# yum localinstall mysql80-community-release-el7-3.noarch.rpm
Loaded plugins: fastestmirror, ovl
Examining mysql80-community-release-el7-3.noarch.rpm: mysql80-community-release-el7-3.noarch
Marking mysql80-community-release-el7-3.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql80-community-release.noarch 0:el7-3 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                             Arch                             Version                          Repository                                                         Size
===============================================================================================================================================================================================
Installing:
 mysql80-community-release                           noarch                           el7-3                            /mysql80-community-release-el7-3.noarch                            31 k

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

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

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

Complete!
[root@667182a79e0d mysql]#
[root@667182a79e0d mysql]# yum search mysql
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com
mysql-connectors-community                                                                                                                                              | 2.5 kB  00:00:00
mysql-tools-community                                                                                                                                                   | 2.5 kB  00:00:00
mysql80-community                                                                                                                                                       | 2.5 kB  00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db                                                                                                                     |  57 kB  00:00:00
(2/3): mysql-tools-community/x86_64/primary_db                                                                                                                          |  72 kB  00:00:00
(3/3): mysql80-community/x86_64/primary_db                                                                                                                              | 107 kB  00:00:01
===================================================================================== N/S matched: mysql ======================================================================================
MySQL-python.x86_64 : An interface to MySQL
akonadi-mysql.x86_64 : Akonadi MySQL backend support
apr-util-mysql.x86_64 : APR utility library MySQL DBD driver
dovecot-mysql.x86_64 : MySQL back end for dovecot
freeradius-mysql.x86_64 : MySQL support for freeradius
libdbi-dbd-mysql.x86_64 : MySQL plugin for libdbi
mysql-community-client.i686 : MySQL database client applications and tools
mysql-community-client.x86_64 : MySQL database client applications and tools
mysql-community-common.i686 : MySQL database common files for server and client libs
mysql-community-common.x86_64 : MySQL database common files for server and client libs
mysql-community-devel.i686 : Development header files and libraries for MySQL database client applications
mysql-community-devel.x86_64 : Development header files and libraries for MySQL database client applications
mysql-community-embedded-compat.i686 : MySQL embedded compat library
mysql-community-embedded-compat.x86_64 : MySQL embedded compat library
mysql-community-libs.i686 : Shared libraries for MySQL database client applications
mysql-community-libs.x86_64 : Shared libraries for MySQL database client applications
mysql-community-libs-compat.i686 : Shared compat libraries for MySQL 5.6.37 database client applications
mysql-community-libs-compat.x86_64 : Shared compat libraries for MySQL 5.6.45 database client applications
mysql-community-release.noarch : MySQL repository configuration for yum
mysql-community-test.x86_64 : Test suite for the MySQL database server
mysql-connector-c++.x86_64 : MySQL database connector for C++
mysql-connector-c++-debuginfo.x86_64 : Debug information for package mysql-connector-c++
mysql-connector-c++-devel.x86_64 : Development header files and libraries for MySQL C++ client applications
mysql-connector-c++-jdbc.x86_64 : MySQL Driver for C++ which mimics the JDBC 4.0 API
mysql-connector-java.noarch : Standardized MySQL database driver for Java
mysql-connector-odbc.x86_64 : An ODBC 8.0 driver for MySQL - driver package
mysql-connector-odbc-debuginfo.x86_64 : Debug information for package mysql-connector-odbc
mysql-connector-odbc-setup.x86_64 : An ODBC 8.0 driver for MySQL - setup library
mysql-connector-python.noarch : Standardized MySQL database driver for Python
mysql-connector-python.x86_64 : Standardized MySQL database driver for Python
mysql-connector-python-cext.x86_64 : Standardized MySQL driver for Python with C Extension
mysql-connector-python-debuginfo.x86_64 : Debug information for package mysql-connector-python
mysql-connector-python3.x86_64 : Standardized MySQL database driver for Python 3
mysql-connector-python3-cext.x86_64 : Standardized MySQL driver for Python with C Extension
mysql-ref-manual-8.0-en-html-chapter.noarch : The MySQL Reference Manual (HTML, English)
mysql-ref-manual-8.0-en-pdf.noarch : The MySQL Reference Manual (PDF, English)
mysql-router.x86_64 : MySQL Router
mysql-router-community.x86_64 : MySQL Router
mysql-router-debuginfo.x86_64 : Debug information for package mysql-router
mysql-shell.x86_64 : Command line shell and scripting environment for MySQL
mysql-shell-debuginfo.x86_64 : Debug information for package mysql-shell
mysql-utilities.noarch : Collection of utilities used for maintaining and administering MySQL servers
mysql-utilities-extra.noarch : Additional files for mysql-utilities
mysql-workbench-community.x86_64 : A MySQL visual database modeling, administration, development and migration tool
mysql-workbench-community-debuginfo.x86_64 : Debug information for package mysql-workbench-community
mysql80-community-release.noarch : MySQL repository configuration for yum
pcp-pmda-mysql.x86_64 : Performance Co-Pilot (PCP) metrics for MySQL
perl-DBD-MySQL.x86_64 : A MySQL interface for Perl
php-mysql.x86_64 : A module for PHP applications that use MySQL databases
php-mysqlnd.x86_64 : A module for PHP applications that use MySQL databases
qt-mysql.i686 : MySQL driver for Qt's SQL classes
qt-mysql.x86_64 : MySQL driver for Qt's SQL classes
qt3-MySQL.i686 : MySQL drivers for Qt 3's SQL classes
qt3-MySQL.x86_64 : MySQL drivers for Qt 3's SQL classes
qt5-qtbase-mysql.i686 : MySQL driver for Qt5's SQL classes
qt5-qtbase-mysql.x86_64 : MySQL driver for Qt5's SQL classes
redland-mysql.x86_64 : MySQL storage support for Redland
rsyslog-mysql.x86_64 : MySQL support for rsyslog
mariadb.x86_64 : A community developed branch of MySQL
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
mysql-community-server.x86_64 : A very fast and reliable SQL database server

  Name and summary matches only, use "search all" for everything.
[root@667182a79e0d mysql]# yum install mysql-community-server
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:8.0.20-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 8.0.20-1.el7 for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 8.0.11 for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: perl(strict) for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: perl(Getopt::Long) for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: net-tools for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.2)(64bit) for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: libnuma.so.1(libnuma_1.1)(64bit) for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.4)(64bit) for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: libaio.so.1(LIBAIO_0.1)(64bit) for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: /usr/bin/perl for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: libnuma.so.1()(64bit) for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Processing Dependency: libaio.so.1()(64bit) for package: mysql-community-server-8.0.20-1.el7.x86_64
--> Running transaction check
---> Package libaio.x86_64 0:0.3.109-13.el7 will be installed
---> Package mysql-community-client.x86_64 0:8.0.20-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 8.0.11 for package: mysql-community-client-8.0.20-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:8.0.20-1.el7 will be installed
---> Package net-tools.x86_64 0:2.0-0.25.20131004git.el7 will be installed
---> Package numactl-libs.x86_64 0:2.0.12-5.el7 will be installed
---> Package perl.x86_64 4:5.16.3-295.el7 will be installed
--> Processing Dependency: perl-libs = 4:5.16.3-295.el7 for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Socket) >= 1.3 for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Scalar::Util) >= 1.10 for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl-macros for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl-libs for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(threads::shared) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(threads) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(constant) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Time::Local) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Time::HiRes) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Storable) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Socket) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Scalar::Util) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Pod::Simple::XHTML) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Pod::Simple::Search) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Filter::Util::Call) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(File::Temp) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(File::Spec::Unix) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(File::Spec::Functions) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(File::Spec) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(File::Path) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Exporter) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Cwd) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: perl(Carp) for package: 4:perl-5.16.3-295.el7.x86_64
--> Processing Dependency: libperl.so()(64bit) for package: 4:perl-5.16.3-295.el7.x86_64
---> Package perl-Getopt-Long.noarch 0:2.40-3.el7 will be installed
--> Processing Dependency: perl(Pod::Usage) >= 1.14 for package: perl-Getopt-Long-2.40-3.el7.noarch
--> Processing Dependency: perl(Text::ParseWords) for package: perl-Getopt-Long-2.40-3.el7.noarch
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:8.0.20-1.el7 will be installed
---> Package perl-Carp.noarch 0:1.26-244.el7 will be installed
---> Package perl-Exporter.noarch 0:5.68-3.el7 will be installed
---> Package perl-File-Path.noarch 0:2.09-2.el7 will be installed
---> Package perl-File-Temp.noarch 0:0.23.01-3.el7 will be installed
---> Package perl-Filter.x86_64 0:1.49-3.el7 will be installed
---> Package perl-PathTools.x86_64 0:3.40-5.el7 will be installed
---> Package perl-Pod-Simple.noarch 1:3.28-4.el7 will be installed
--> Processing Dependency: perl(Pod::Escapes) >= 1.04 for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
--> Processing Dependency: perl(Encode) for package: 1:perl-Pod-Simple-3.28-4.el7.noarch
---> Package perl-Pod-Usage.noarch 0:1.63-3.el7 will be installed
--> Processing Dependency: perl(Pod::Text) >= 3.15 for package: perl-Pod-Usage-1.63-3.el7.noarch
--> Processing Dependency: perl-Pod-Perldoc for package: perl-Pod-Usage-1.63-3.el7.noarch
---> Package perl-Scalar-List-Utils.x86_64 0:1.27-248.el7 will be installed
---> Package perl-Socket.x86_64 0:2.010-5.el7 will be installed
---> Package perl-Storable.x86_64 0:2.45-3.el7 will be installed
---> Package perl-Text-ParseWords.noarch 0:3.29-4.el7 will be installed
---> Package perl-Time-HiRes.x86_64 4:1.9725-3.el7 will be installed
---> Package perl-Time-Local.noarch 0:1.2300-2.el7 will be installed
---> Package perl-constant.noarch 0:1.27-2.el7 will be installed
---> Package perl-libs.x86_64 4:5.16.3-295.el7 will be installed
---> Package perl-macros.x86_64 4:5.16.3-295.el7 will be installed
---> Package perl-threads.x86_64 0:1.87-4.el7 will be installed
---> Package perl-threads-shared.x86_64 0:1.43-6.el7 will be installed
--> Running transaction check
---> Package perl-Encode.x86_64 0:2.51-7.el7 will be installed
---> Package perl-Pod-Escapes.noarch 1:1.04-295.el7 will be installed
---> Package perl-Pod-Perldoc.noarch 0:3.20-4.el7 will be installed
--> Processing Dependency: perl(parent) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
--> Processing Dependency: perl(HTTP::Tiny) for package: perl-Pod-Perldoc-3.20-4.el7.noarch
--> Processing Dependency: groff-base for package: perl-Pod-Perldoc-3.20-4.el7.noarch
---> Package perl-podlators.noarch 0:2.5.1-3.el7 will be installed
--> Running transaction check
---> Package groff-base.x86_64 0:1.22.2-8.el7 will be installed
---> Package perl-HTTP-Tiny.noarch 0:0.033-3.el7 will be installed
---> Package perl-parent.noarch 1:0.225-244.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================
 Package                                           Arch                              Version                                                Repository                                    Size
===============================================================================================================================================================================================
Installing:
 mysql-community-server                            x86_64                            8.0.20-1.el7                                           mysql80-community                            488 M
Installing for dependencies:
 groff-base                                        x86_64                            1.22.2-8.el7                                           base                                         942 k
 libaio                                            x86_64                            0.3.109-13.el7                                         base                                          24 k
 mysql-community-client                            x86_64                            8.0.20-1.el7                                           mysql80-community                             47 M
 mysql-community-common                            x86_64                            8.0.20-1.el7                                           mysql80-community                            609 k
 mysql-community-libs                              x86_64                            8.0.20-1.el7                                           mysql80-community                            4.5 M
 net-tools                                         x86_64                            2.0-0.25.20131004git.el7                               base                                         306 k
 numactl-libs                                      x86_64                            2.0.12-5.el7                                           base                                          30 k
 perl                                              x86_64                            4:5.16.3-295.el7                                       base                                         8.0 M
 perl-Carp                                         noarch                            1.26-244.el7                                           base                                          19 k
 perl-Encode                                       x86_64                            2.51-7.el7                                             base                                         1.5 M
 perl-Exporter                                     noarch                            5.68-3.el7                                             base                                          28 k
 perl-File-Path                                    noarch                            2.09-2.el7                                             base                                          26 k
 perl-File-Temp                                    noarch                            0.23.01-3.el7                                          base                                          56 k
 perl-Filter                                       x86_64                            1.49-3.el7                                             base                                          76 k
 perl-Getopt-Long                                  noarch                            2.40-3.el7                                             base                                          56 k
 perl-HTTP-Tiny                                    noarch                            0.033-3.el7                                            base                                          38 k
 perl-PathTools                                    x86_64                            3.40-5.el7                                             base                                          82 k
 perl-Pod-Escapes                                  noarch                            1:1.04-295.el7                                         base                                          51 k
 perl-Pod-Perldoc                                  noarch                            3.20-4.el7                                             base                                          87 k
 perl-Pod-Simple                                   noarch                            1:3.28-4.el7                                           base                                         216 k
 perl-Pod-Usage                                    noarch                            1.63-3.el7                                             base                                          27 k
 perl-Scalar-List-Utils                            x86_64                            1.27-248.el7                                           base                                          36 k
 perl-Socket                                       x86_64                            2.010-5.el7                                            base                                          49 k
 perl-Storable                                     x86_64                            2.45-3.el7                                             base                                          77 k
 perl-Text-ParseWords                              noarch                            3.29-4.el7                                             base                                          14 k
 perl-Time-HiRes                                   x86_64                            4:1.9725-3.el7                                         base                                          45 k
 perl-Time-Local                                   noarch                            1.2300-2.el7                                           base                                          24 k
 perl-constant                                     noarch                            1.27-2.el7                                             base                                          19 k
 perl-libs                                         x86_64                            4:5.16.3-295.el7                                       base                                         689 k
 perl-macros                                       x86_64                            4:5.16.3-295.el7                                       base                                          44 k
 perl-parent                                       noarch                            1:0.225-244.el7                                        base                                          12 k
 perl-podlators                                    noarch                            2.5.1-3.el7                                            base                                         112 k
 perl-threads                                      x86_64                            1.87-4.el7                                             base                                          49 k
 perl-threads-shared                               x86_64                            1.43-6.el7                                             base                                          39 k

Transaction Summary
===============================================================================================================================================================================================
Install  1 Package (+34 Dependent packages)

Total download size: 553 M
Installed size: 2.5 G
Is this ok [y/d/N]: y
Downloading packages:
(1/35): libaio-0.3.109-13.el7.x86_64.rpm                                                                                                                                |  24 kB  00:00:00
(2/35): groff-base-1.22.2-8.el7.x86_64.rpm                                                                                                                              | 942 kB  00:00:00
warning: /var/cache/yum/x86_64/7/mysql80-community/packages/mysql-community-common-8.0.20-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY19 kB/s | 1.4 MB  01:19:13 ETA
Public key for mysql-community-common-8.0.20-1.el7.x86_64.rpm is not installed
(3/35): mysql-community-common-8.0.20-1.el7.x86_64.rpm                                                                                                                  | 609 kB  00:00:01
(4/35): mysql-community-libs-8.0.20-1.el7.x86_64.rpm                                                                                                                    | 4.5 MB  00:00:02
(5/35): net-tools-2.0-0.25.20131004git.el7.x86_64.rpm                                                                                                                   | 306 kB  00:00:00
(6/35): numactl-libs-2.0.12-5.el7.x86_64.rpm                                                                                                                            |  30 kB  00:00:00
(7/35): perl-Carp-1.26-244.el7.noarch.rpm                                                                                                                               |  19 kB  00:00:00
(8/35): perl-Exporter-5.68-3.el7.noarch.rpm                                                                                                                             |  28 kB  00:00:00
(9/35): perl-File-Path-2.09-2.el7.noarch.rpm                                                                                                                            |  26 kB  00:00:00
(10/35): perl-File-Temp-0.23.01-3.el7.noarch.rpm                                                                                                                        |  56 kB  00:00:00
(11/35): perl-Filter-1.49-3.el7.x86_64.rpm                                                                                                                              |  76 kB  00:00:00
(12/35): perl-Getopt-Long-2.40-3.el7.noarch.rpm                                                                                                                         |  56 kB  00:00:00
(13/35): perl-HTTP-Tiny-0.033-3.el7.noarch.rpm                                                                                                                          |  38 kB  00:00:00
(14/35): perl-PathTools-3.40-5.el7.x86_64.rpm                                                                                                                           |  82 kB  00:00:00
(15/35): perl-Pod-Escapes-1.04-295.el7.noarch.rpm                                                                                                                       |  51 kB  00:00:00
(16/35): perl-Pod-Perldoc-3.20-4.el7.noarch.rpm                                                                                                                         |  87 kB  00:00:00
(17/35): perl-Pod-Simple-3.28-4.el7.noarch.rpm                                                                                                                          | 216 kB  00:00:00
(18/35): perl-Pod-Usage-1.63-3.el7.noarch.rpm                                                                                                                           |  27 kB  00:00:00
(19/35): perl-Encode-2.51-7.el7.x86_64.rpm                                                                                                                              | 1.5 MB  00:00:01
(20/35): perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm                                                                                                                 |  36 kB  00:00:00
(21/35): perl-Socket-2.010-5.el7.x86_64.rpm                                                                                                                             |  49 kB  00:00:00
(22/35): perl-Storable-2.45-3.el7.x86_64.rpm                                                                                                                            |  77 kB  00:00:00
(23/35): perl-Time-HiRes-1.9725-3.el7.x86_64.rpm                                                                                                                        |  45 kB  00:00:00
(24/35): perl-Text-ParseWords-3.29-4.el7.noarch.rpm                                                                                                                     |  14 kB  00:00:00
(25/35): perl-Time-Local-1.2300-2.el7.noarch.rpm                                                                                                                        |  24 kB  00:00:00
(26/35): perl-constant-1.27-2.el7.noarch.rpm                                                                                                                            |  19 kB  00:00:00
(27/35): perl-macros-5.16.3-295.el7.x86_64.rpm                                                                                                                          |  44 kB  00:00:00
(28/35): perl-parent-0.225-244.el7.noarch.rpm                                                                                                                           |  12 kB  00:00:00
(29/35): perl-libs-5.16.3-295.el7.x86_64.rpm                                                                                                                            | 689 kB  00:00:00
(30/35): perl-threads-1.87-4.el7.x86_64.rpm                                                                                                                             |  49 kB  00:00:00
(31/35): perl-podlators-2.5.1-3.el7.noarch.rpm                                                                                                                          | 112 kB  00:00:00
(32/35): perl-5.16.3-295.el7.x86_64.rpm                                                                                                                                 | 8.0 MB  00:00:02
(33/35): perl-threads-shared-1.43-6.el7.x86_64.rpm                                                                                                                      |  39 kB  00:00:00
(34/35): mysql-community-client-8.0.20-1.el7.x86_64.rpm                                                                                                                 |  47 MB  00:00:16
(35/35): mysql-community-server-8.0.20-1.el7.x86_64.rpm                                                                                                                 | 488 MB  00:01:58
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                          4.5 MB/s | 553 MB  00:02:02
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql80-community-release-el7-3.noarch (@/mysql80-community-release-el7-3.noarch)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql-community-common-8.0.20-1.el7.x86_64                                                                                                                                 1/35
  Installing : mysql-community-libs-8.0.20-1.el7.x86_64                                                                                                                                   2/35
  Installing : mysql-community-client-8.0.20-1.el7.x86_64                                                                                                                                 3/35
  Installing : numactl-libs-2.0.12-5.el7.x86_64                                                                                                                                           4/35
  Installing : libaio-0.3.109-13.el7.x86_64                                                                                                                                               5/35
  Installing : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                                                                  6/35
  Installing : groff-base-1.22.2-8.el7.x86_64                                                                                                                                             7/35
  Installing : 1:perl-parent-0.225-244.el7.noarch                                                                                                                                         8/35
  Installing : perl-HTTP-Tiny-0.033-3.el7.noarch                                                                                                                                          9/35
  Installing : perl-podlators-2.5.1-3.el7.noarch                                                                                                                                         10/35
  Installing : perl-Pod-Perldoc-3.20-4.el7.noarch                                                                                                                                        11/35
  Installing : 1:perl-Pod-Escapes-1.04-295.el7.noarch                                                                                                                                    12/35
  Installing : perl-Text-ParseWords-3.29-4.el7.noarch                                                                                                                                    13/35
  Installing : perl-Encode-2.51-7.el7.x86_64                                                                                                                                             14/35
  Installing : perl-Pod-Usage-1.63-3.el7.noarch                                                                                                                                          15/35
  Installing : 4:perl-libs-5.16.3-295.el7.x86_64                                                                                                                                         16/35
  Installing : 4:perl-macros-5.16.3-295.el7.x86_64                                                                                                                                       17/35
  Installing : perl-Storable-2.45-3.el7.x86_64                                                                                                                                           18/35
  Installing : perl-Exporter-5.68-3.el7.noarch                                                                                                                                           19/35
  Installing : perl-constant-1.27-2.el7.noarch                                                                                                                                           20/35
  Installing : perl-Socket-2.010-5.el7.x86_64                                                                                                                                            21/35
  Installing : perl-Time-Local-1.2300-2.el7.noarch                                                                                                                                       22/35
  Installing : perl-Carp-1.26-244.el7.noarch                                                                                                                                             23/35
  Installing : perl-PathTools-3.40-5.el7.x86_64                                                                                                                                          24/35
  Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64                                                                                                                                25/35
  Installing : perl-threads-shared-1.43-6.el7.x86_64                                                                                                                                     26/35
  Installing : perl-threads-1.87-4.el7.x86_64                                                                                                                                            27/35
  Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                                                                                                                                     28/35
  Installing : perl-Filter-1.49-3.el7.x86_64                                                                                                                                             29/35
  Installing : perl-File-Temp-0.23.01-3.el7.noarch                                                                                                                                       30/35
  Installing : perl-File-Path-2.09-2.el7.noarch                                                                                                                                          31/35
  Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch                                                                                                                                       32/35
  Installing : perl-Getopt-Long-2.40-3.el7.noarch                                                                                                                                        33/35
  Installing : 4:perl-5.16.3-295.el7.x86_64                                                                                                                                              34/35
  Installing : mysql-community-server-8.0.20-1.el7.x86_64                                                                                                                                35/35
  Verifying  : perl-HTTP-Tiny-0.033-3.el7.noarch                                                                                                                                          1/35
  Verifying  : perl-threads-shared-1.43-6.el7.x86_64                                                                                                                                      2/35
  Verifying  : perl-Storable-2.45-3.el7.x86_64                                                                                                                                            3/35
  Verifying  : 1:perl-Pod-Escapes-1.04-295.el7.noarch                                                                                                                                     4/35
  Verifying  : perl-Exporter-5.68-3.el7.noarch                                                                                                                                            5/35
  Verifying  : perl-constant-1.27-2.el7.noarch                                                                                                                                            6/35
  Verifying  : perl-PathTools-3.40-5.el7.x86_64                                                                                                                                           7/35
  Verifying  : mysql-community-client-8.0.20-1.el7.x86_64                                                                                                                                 8/35
  Verifying  : perl-Socket-2.010-5.el7.x86_64                                                                                                                                             9/35
  Verifying  : 1:perl-parent-0.225-244.el7.noarch                                                                                                                                        10/35
  Verifying  : mysql-community-common-8.0.20-1.el7.x86_64                                                                                                                                11/35
  Verifying  : 4:perl-libs-5.16.3-295.el7.x86_64                                                                                                                                         12/35
  Verifying  : groff-base-1.22.2-8.el7.x86_64                                                                                                                                            13/35
  Verifying  : perl-File-Temp-0.23.01-3.el7.noarch                                                                                                                                       14/35
  Verifying  : net-tools-2.0-0.25.20131004git.el7.x86_64                                                                                                                                 15/35
  Verifying  : 1:perl-Pod-Simple-3.28-4.el7.noarch                                                                                                                                       16/35
  Verifying  : perl-Time-Local-1.2300-2.el7.noarch                                                                                                                                       17/35
  Verifying  : libaio-0.3.109-13.el7.x86_64                                                                                                                                              18/35
  Verifying  : 4:perl-macros-5.16.3-295.el7.x86_64                                                                                                                                       19/35
  Verifying  : 4:perl-5.16.3-295.el7.x86_64                                                                                                                                              20/35
  Verifying  : perl-Carp-1.26-244.el7.noarch                                                                                                                                             21/35
  Verifying  : mysql-community-server-8.0.20-1.el7.x86_64                                                                                                                                22/35
  Verifying  : perl-Scalar-List-Utils-1.27-248.el7.x86_64                                                                                                                                23/35
  Verifying  : perl-Pod-Usage-1.63-3.el7.noarch                                                                                                                                          24/35
  Verifying  : perl-Encode-2.51-7.el7.x86_64                                                                                                                                             25/35
  Verifying  : perl-Pod-Perldoc-3.20-4.el7.noarch                                                                                                                                        26/35
  Verifying  : perl-podlators-2.5.1-3.el7.noarch                                                                                                                                         27/35
  Verifying  : numactl-libs-2.0.12-5.el7.x86_64                                                                                                                                          28/35
  Verifying  : perl-threads-1.87-4.el7.x86_64                                                                                                                                            29/35
  Verifying  : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                                                                                                                                     30/35
  Verifying  : perl-Filter-1.49-3.el7.x86_64                                                                                                                                             31/35
  Verifying  : perl-Getopt-Long-2.40-3.el7.noarch                                                                                                                                        32/35
  Verifying  : perl-Text-ParseWords-3.29-4.el7.noarch                                                                                                                                    33/35
  Verifying  : perl-File-Path-2.09-2.el7.noarch                                                                                                                                          34/35
  Verifying  : mysql-community-libs-8.0.20-1.el7.x86_64                                                                                                                                  35/35

Installed:
  mysql-community-server.x86_64 0:8.0.20-1.el7

Dependency Installed:
  groff-base.x86_64 0:1.22.2-8.el7              libaio.x86_64 0:0.3.109-13.el7                  mysql-community-client.x86_64 0:8.0.20-1.el7    mysql-community-common.x86_64 0:8.0.20-1.el7
  mysql-community-libs.x86_64 0:8.0.20-1.el7    net-tools.x86_64 0:2.0-0.25.20131004git.el7     numactl-libs.x86_64 0:2.0.12-5.el7              perl.x86_64 4:5.16.3-295.el7
  perl-Carp.noarch 0:1.26-244.el7               perl-Encode.x86_64 0:2.51-7.el7                 perl-Exporter.noarch 0:5.68-3.el7               perl-File-Path.noarch 0:2.09-2.el7
  perl-File-Temp.noarch 0:0.23.01-3.el7         perl-Filter.x86_64 0:1.49-3.el7                 perl-Getopt-Long.noarch 0:2.40-3.el7            perl-HTTP-Tiny.noarch 0:0.033-3.el7
  perl-PathTools.x86_64 0:3.40-5.el7            perl-Pod-Escapes.noarch 1:1.04-295.el7          perl-Pod-Perldoc.noarch 0:3.20-4.el7            perl-Pod-Simple.noarch 1:3.28-4.el7
  perl-Pod-Usage.noarch 0:1.63-3.el7            perl-Scalar-List-Utils.x86_64 0:1.27-248.el7    perl-Socket.x86_64 0:2.010-5.el7                perl-Storable.x86_64 0:2.45-3.el7
  perl-Text-ParseWords.noarch 0:3.29-4.el7      perl-Time-HiRes.x86_64 4:1.9725-3.el7           perl-Time-Local.noarch 0:1.2300-2.el7           perl-constant.noarch 0:1.27-2.el7
  perl-libs.x86_64 4:5.16.3-295.el7             perl-macros.x86_64 4:5.16.3-295.el7             perl-parent.noarch 1:0.225-244.el7              perl-podlators.noarch 0:2.5.1-3.el7
  perl-threads.x86_64 0:1.87-4.el7              perl-threads-shared.x86_64 0:1.43-6.el7

Complete!
[root@667182a79e0d mysql]# systemctl start mysqld
[root@667182a79e0d mysql]# systemctl enable mysqld
[root@667182a79e0d mysql]# cat /var/log/mysqld.log |grep password
2020-06-18T02:22:24.882710Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hMzif68I21*8
[root@667182a79e0d mysql]# mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@667182a79e0d mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.20

Copyright (c) 2000, 2020, 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.

mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER "root"@"localhost" IDENTIFIED  BY "1234";
Query OK, 0 rows affected (0.00 sec)

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> ALTER USER 'root'@'%' IDENTIFIED  with mysql_native_password by '1234';
ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'%'
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> update user set host = '%' where user = 'root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql>  select host,user from user where user='root';
+------+------+
| host | user |
+------+------+
| %    | root |
+------+------+
1 row in set (0.00 sec)

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

mysql> exit;
Bye
[root@667182a79e0d mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 8.0.20 MySQL Community Server - GPL

Copyright (c) 2000, 2020, 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.

mysql> ALTER USER 'root'@'%' IDENTIFIED  with mysql_native_password by '1234';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

主主配置

首先我们假设两个服务器分别为A和B
A服务器的IP为192.168.2.51
B服务器的IP为192.168.2.52

设置A服务器my.cnf

server-id=51
character-set-server=utf8mb4

#步进值,主节点数量
auto_increment_increment=2
#起始值,一般填写第n台主机mysql,第二台填写2
auto_increment_offset=1

max_connections=3000
max_connect_errors=100000
default_authentication_plugin=mysql_native_password


log-bin=mysql-bin
relay-log = mysql-relay-bin

#不同步的表配置
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%

设置B服务器的my.cnf

server-id=52
character-set-server=utf8mb4

#步进值,主节点数量
auto_increment_increment=2
#起始值,一般填写第n台主机mysql,第二台填写2
auto_increment_offset=2

max_connections=3000
max_connect_errors=100000
default_authentication_plugin=mysql_native_password

log-bin=mysql-bin
relay-log = mysql-relay-bin

#不同步的表配置
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%

然后重启mysql

systemctl restart mysqld
#或者
service mysqld restart

然后,分别在A,B服务器上创建用户
A服务器:

CREATE USER 'sync'@'192.168.2.52' IDENTIFIED BY '1234';
GRANT REPLICATION SLAVE ON *.* TO 'sync'@'192.168.2.52';

B服务器:

CREATE USER 'sync'@'192.168.2.51' IDENTIFIED BY '1234';
GRANT REPLICATION SLAVE ON *.* TO 'sync'@'192.168.2.51';

在B服务器上执行show master status;

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

在A服务器上执行:

mysql> change master to
    -> master_host='192.168.2.52', #B服务器的IP
    -> master_port=3306,
    -> master_user='sync',
    -> master_password='1234',
    -> master_log_file='mysql-bin.000001', #此处的file名字是我们B服务器上用show master status;查出来的
    -> master_log_pos=156; #同log_file一样
Query OK, 0 rows affected, 2 warnings (0.01 sec)

#然后启动slave
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

#查看状态
mysql> show slave status\G

在A服务器上执行show master status;

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

在B服务器上执行:

mysql> change master to
    -> master_host='192.168.2.51', #A服务器的IP
    -> master_port=3306,
    -> master_user='sync',
    -> master_password='1234',
    -> master_log_file='mysql-bin.000001',
    -> master_log_pos=156;
Query OK, 0 rows affected, 2 warnings (0.01 sec)

#然后启动slave
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

#查看状态
mysql> show slave status\G

ps:如果出现这个错误:

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 192.168.2.52
                  Master_User: sync
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 1796
               Relay_Log_File: mysql-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Connecting
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table: mysql.%,test.%,information_schema.%
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 1796
              Relay_Log_Space: 156
              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: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2061
                Last_IO_Error: error connecting to master 'sync@192.168.2.52:3306' - retry-time: 60 retries: 3 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID:
             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: 200618 11:17:03
     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 (0.00 sec)

解决方案:

mysql> select host, user, authentication_string, plugin from user;
+--------------+------------------+------------------------------------------------------------------------+-----------------------+
| host         | user             | authentication_string                                                  | plugin                |
+--------------+------------------+------------------------------------------------------------------------+-----------------------+
| %            | root             | *A4B6157319038724E3560894F7F932C8886EBFCF                              | mysql_native_password |
| 192.168.2.52 | sync             | $A$005$MsPFv)Dbi aH<M7A5wm1yqlTviOefIXiP6k5.1P//M8tPVLE5Jxwkp4VB | caching_sha2_password |
| localhost    | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost    | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost    | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+--------------+------------------+------------------------------------------------------------------------+-----------------------+
5 rows in set (0.00 sec)

mysql> ALTER USER 'sync'@'192.168.2.52' IDENTIFIED WITH mysql_native_password BY '1234';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> set global validate_password.policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password.length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'sync'@'192.168.2.52' IDENTIFIED WITH mysql_native_password BY '1234';
Query OK, 0 rows affected (0.00 sec)

mysql> select host, user, authentication_string, plugin from user;
+--------------+------------------+------------------------------------------------------------------------+-----------------------+
| host         | user             | authentication_string                                                  | plugin                |
+--------------+------------------+------------------------------------------------------------------------+-----------------------+
| %            | root             | *A4B6157319038724E3560894F7F932C8886EBFCF                              | mysql_native_password |
| 192.168.2.52 | sync             | *A4B6157319038724E3560894F7F932C8886EBFCF                              | mysql_native_password |
| localhost    | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost    | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost    | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+--------------+------------------+------------------------------------------------------------------------+-----------------------+
5 rows in set (0.00 sec)

mysql> show slave status\G

或者是这个错误

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 192.168.2.51
                  Master_User: sync
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 120
               Relay_Log_File: mysql-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Connecting
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB:
           Replicate_Do_Table:
       Replicate_Ignore_Table:
      Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table: mysql.%,test.%,information_schema.%
                   Last_Errno: 0
                   Last_Error:
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 120
              Relay_Log_Space: 120
              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: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 1045
                Last_IO_Error: error connecting to master 'sync@192.168.2.51:3306' - retry-time: 60  retries: 1
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID:
             Master_Info_File: /usr/local/mysql/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 200904 16:57:23
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set:
                Auto_Position: 0
1 row in set (0.00 sec)

解决方案:
首先在52上连接51数据库发现实际发送到51上的host为151(出现这个问题,是我们用docker启动的mysql),那就可以mysql用户权限host改为192.168.2.XXX段的所有主机都能访问。

[root@57ee178bf00b ~]# mysql -usync -h192.168.2.51 -p
Enter password:
ERROR 1045 (28000): Access denied for user 'sync'@'192.168.2.151' (using password: YES)

修改mysql用户host

mysql> update mysql.user set host = '192.168.2.%'  where user = 'sync';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

如果某个mysql中出现不能执行sql的错误时,即Slave_SQL_Running: No,可将binglog指针下移一个位置,直到不报错为止

#先停止slave
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

#将binglog指针下移一个位置
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;

#启动slave
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

keepalived虚拟IP漂移(基于docker)

1.首先在宿主机上安装keepalived(必须)

注意:docker宿主机需安装keepalived和ipvsadm,否则容器中的keepalived服务无法正常启动

2.在容器中安装keepalived(容器中已存在mysql,且设置好主主配置)

安装keepalived和ipvsadm

yum install -y keepalived ipvsadm
#根据自身需求安装keepalived所需依赖
yum -y install kernel-devel openssl-devel popt-devel
yum install -y gcc openssl-devel popt-devel

配置keepalived.cnf

[root@6baf00f105dd keepalived]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
        925718725@qq.com
    }
    notification_email_from itsection@example.com
    smtp_server mail.example.com
    smtp_connect_timeout 30
    router_id mysql-1 #keepalived标识,区分A,B容器我的B容器配置为mysql-2
}
vrrp_instance VI_1 {
   state BACKUP #指定keepalived角色,两个容器都设置为BACKUP(设置为backup会根据优先级觉得主从)
   interface eth1 #容器的虚拟网卡名
   virtual_router_id 51 #虚拟路由标识(取值在0-255之间),不同集群值必须不同,这儿两个容器都设置成51
   priority 100 #定义优先级(取值在1-255之间,在此范围外会设置成100),数字越大,优先级越高,B容器设置为90
   advert_int 1 #发VRRP包时间间隔,即多久进行一次master选举
   nopreempt #不抢占,允许priority较低的节点作为master
   authentication {
       auth_type PASS
       auth_pass 1111
   }
   virtual_ipaddress {#虚拟IP
       192.168.2.48
   }
}

virtual_server 192.168.2.48 3306 {#设置虚拟服务
   delay_loop 2 #设置运行情况检查时间,单位秒
   lb_algo rr #设置后端调度算法,(rr即轮询)
   lb_kind DR #设置LVS实现负载均衡的机制(NAT,TUN,DR可选)
   persistence_timeout 60 #会话保持时间,单位秒,
   protocol TCP #指定转发协议类型(TCP,UDP可选)
   real_server 192.168.2.51 3306 {#配置服务节点1 即真实mysql服务IP和端口,写本容器的IP,在B容器中为192.168.2.52
       weight 3 #配置服务节点权值,数字越大,权值越高
       notify_down    /etc/keepalived/restartKeepalived.sh #检测到mysql挂了以后执行的脚本
       TCP_CHECK {
            connect_timeout 3 #连接超时时间
            nb_get_retry 3 #重连次数
            delay_before_retry 3 #重连时间间隔
            connect_port 3306 #健康检查端口
       }
   }
}

在/etc/keepalived/下创建restartKeepalived.sh(keepalived.cnf中notify_down 配置的路径)

[root@6baf00f105dd keepalived]# vim /etc/keepalived/restartKeepalived.sh
#!/bin/bash
systemctl restart keepalived

赋予restartKeepalived.sh运行权限

chmod +x /etc/keepalived/restartKeepalived.sh

启动A,B容器的keepalived查看运行状态

[root@6baf00f105dd keepalived]# systemctl start keepalived
[root@6baf00f105dd keepalived]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-06-18 20:32:01 CST; 13h ago
  Process: 37492 ExecStart=/usr/sbin/keepalived $KEEPALIVED_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 37493 (keepalived)
   CGroup: /docker/6baf00f105dde6ba347d0e200876196b9670cf77e6941df29cbc1dc3728d5ccd/docker/6baf00f105dde6ba347d0e200876196b9670cf77e6941df29cbc1dc3728d5ccd/system.slice/keepalived.service
           ├─37493 /usr/sbin/keepalived -D
           ├─37494 /usr/sbin/keepalived -D
           └─37495 /usr/sbin/keepalived -D
           ‣ 37493 /usr/sbin/keepalived -D

Jun 18 20:32:01 6baf00f105dd systemd[1]: Starting LVS and VRRP High Availability Monitor...
Jun 18 20:32:01 6baf00f105dd systemd[1]: Started LVS and VRRP High Availability Monitor.

最后需要需要注意的是在运行docker容器时需要加–privileged参数

 docker run -itd  -v /etc/localtime:/etc/localtime --privileged  --network=none --name os7-52 centos:7 usr/sbin/init

扩展一下A,B容器之间建立SSH免密

#A容器中
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa 
ssh-copy-id -i  ~/.ssh/id_rsa.pub root@192.168.2.52

#B容器中
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
ssh-copy-id -i  ~/.ssh/id_rsa.pub root@192.168.2.51

出现命令未找到,安装openssh-clients解决

yum -y install openssh-clients
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值