基础环境
CentOS Linux release 7.7 两台
IP:192.168.1.123(主01)
IP:192.168.1.187(主02)
配置/etc/hosts
[root@v123 etc]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.123 masterA v123
192.168.1.187 masterB v187
安装mysql
删除自带的数据库
rpm -qa | grep -i mariadb
rpm -e --nodeps mariadb-libs-5.5.64-1.el7.x86_64
上传 mysql-5.7.27-1.el7.x86_64.rpm-bundle.tar
wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm
rpm -ivh mysql57-community-release-el7-8.noarch.rpm
yum install perl -y
yum install net-tools -y
rpm -ivh mysql-community-common-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.27-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.27-1.el7.x86_64.rpm
修改密码
vi /etc/my.cnf
skip-grant-tables添加
数据库刷新下权限
flush privileges;
mysql> grant all on *.* to '用户名'@'登录主机' identified by '密码';
mysql> alter user '用户名'@'登录主机' identified by '密码(自定义)';
mysql> SET PASSWORD FOR '用户名'@'登录主机' = PASSWORD('密码');
flush privileges;(修改密码再次刷新权限)
配置(主01)my.cnf
[root@26 mysql]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin=mysql-bin
server-id=1
binlog-ignore-db = mysql,information_schema
binlog_cache_size = 1M
auto_increment_increment = 2
auto_increment_offset = 1
relay_log = mysql-relay-bin
主02
[root@v43 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
log-bin=mysql-bin
server-id=2
binlog-ignore-db = mysql,information_schema
binlog_cache_size = 1M
auto_increment_increment = 2
auto_increment_offset = 2
relay_log = mysql-relay-bin
创建复制账号
主msql1
mysql>GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'Abcd@666888';
mysql> flush privileges;
mysql> change master to
-> master_host='192.168.1.43',
-> master_user='repl1',
-> master_password='Abcd@666888',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=106;
mysql> start slave;
SHOW MASTER STATUS;
mysql>GRANT REPLICATION SLAVE ON *.* TO 'repl1'@'%' IDENTIFIED BY 'Abcd@666888';
mysql> flush privileges;
mysql> change master to
-> master_host='192.168.1.26',
-> master_user='repl',
-> master_password='Abcd@666888',
-> master_log_file='mysql-bin.000001',
-> master_log_pos=106;
mysql> start slave;
完成如图
图一
图二