MAH架构图
一、上传MySQL软件
1、同步MySQL软件
[root@mysql01 ~]# ls -lrt
total 626112
-rw-r--r--. 1 root root 641127384 Jan 30 15:13 mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
-rw-------. 1 root root 1697 Feb 3 12:09 anaconda-ks.cfg
-rw-r--r--. 1 root root 1907 Feb 3 12:12 initial-setup-ks.cfg
[root@mysql01 ~]#
[root@mysql01 ~]#
[root@mysql01 ~]# rsync -avl mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz root@mysql02
sending incremental file list
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
sent 641,284,023 bytes received 35 bytes 116,597,101.45 bytes/sec
total size is 641,127,384 speedup is 1.00
[root@mysql01 ~]#
[root@mysql01 ~]#
[root@mysql01 ~]# rsync -avl mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz root@mysql03
sending incremental file list
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
sent 641,284,023 bytes received 35 bytes 142,507,568.44 bytes/sec
total size is 641,127,384 speedup is 1.00
[root@mysql01 ~]#
2、解压mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
[root@mysql03 ~]# tar -xvzf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
[root@mysql03 ~]# mv mysql-5.7.20-linux-glibc2.12-x86_64 mysql
[root@mysql03 ~]# mv mysql /usr/local/mysql/
二、一主二从数据库搭建
1、准备MySQL配置化文件,最对应主机执行
主库db01:
cat > /etc/my.cnf <<EOF
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=1
port=3306
secure-file-priv=/tmp
autocommit=0
log_bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
[mysql]
prompt=db01 [\\d]>
EOF
slave1(db02):
cat > /etc/my.cnf <<EOF
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=2
port=3306
secure-file-priv=/tmp
autocommit=0
log_bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
[mysql]
prompt=db02 [\\d]>
EOF
slave2(db03):
cat > /etc/my.cnf <<EOF
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/data
socket=/tmp/mysql.sock
server_id=3
port=3306
secure-file-priv=/tmp
autocommit=0
log_bin=/data/binlog/mysql-bin
binlog_format=row
gtid-mode=on
enforce-gtid-consistency=true
log-slave-updates=1
[mysql]
prompt=db03 [\\d]>
EOF
2、初始化数据库--ALL
cd /usr/local/mysql/bin
[root@mysql03 ~]# mysqld --initialize-insecure --user=mysql --basedir=/data/mysql --datadir=/data/mysql/data