gitee如何搭建mysql_MySQL高可用架构集群环境搭建手册.md

本文档详细介绍了如何在Gitee上搭建MySQL高可用架构集群,包括环境准备、安装Mysql、主从配置、MHA集群半同步配置及问题记录。通过此教程,您可以了解如何设置多台服务器实现主从复制,以及使用MHA Manager进行故障转移和监控。
摘要由CSDN通过智能技术生成

# MySQL高可用架构集群环境搭建手册

## 环境准备

### 机器规划

| 节点 | IP | 配置 | 角色 |

| -------- | -------------- | ---- | ---------------- |

| master-1 | 192.168.73.129 | 1c2g | master、HMA node |

| slave-1 | 192.168.73.130 | 1c1g | salve、HMA node |

| slave-2 | 192.168.73.131 | 1c1g | salve、HMA node |

| slave-3 | 192.168.73.132 | 1c1g | HMA manager |

### 安装包

mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar

拷贝到master和salve节点的/opt/software/mysql/目录下并解压

```shell

tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar

```

### 安装Mysql

在192.168.73.129、192.168.73.130、192.168.73.131分别按如下步骤命令安装Mysql。

1)卸载自带的mariadb

```shell

rpm -qa|grep mariadb

rpm -e mariadb-libs-5.5.64-1.el7.x86_64 --nodeps

```

2)安装Mysql

```shell

rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm

rpm -ivh mysql-community-devel-5.7.28-1.el7.x86_64.rpm

```

3)初始化mysql

```shell

mysqld --initialize --user=mysql

```

4)查看临时密码

```shell

[root@localhost mysql]# cat /var/log/mysqld.log

2020-07-27T11:35:17.156086Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

2020-07-27T11:35:17.291065Z 0 [Warning] InnoDB: New log files created, LSN=45790

2020-07-27T11:35:17.321303Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.

2020-07-27T11:35:17.389391Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 3eb43224-cffd-11ea-b6e3-000c2998582e.

2020-07-27T11:35:17.390659Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.

2020-07-27T11:35:17.797306Z 0 [Warning] CA certificate ca.pem is self signed.

2020-07-27T11:35:17.916216Z 1 [Note] A temporary password is generated for root@localhost: =L=9m4yg29kA

```

5)启动mysql,并设置开机启动

```shell

[root@localhost mysql]# systemctl start mysqld.service

[root@localhost mysql]# systemctl status mysqld.service

● mysqld.service - MySQL Server

Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

Active: active (running) since 一 2020-07-27 19:37:41 CST; 5s ago

Docs: man:mysqld(8)

http://dev.mysql.com/doc/refman/en/using-systemd.html

Process: 2328 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)

Process: 2311 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)

Main PID: 2331 (mysqld)

CGroup: /system.slice/mysqld.service

└─2331 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

7月 27 19:37:41 localhost.localdomain systemd[1]: Starting MySQL Server...

7月 27 19:37:41 localhost.localdomain systemd[1]: Started MySQL Server.

```

6)登录mysql,修改密码

```shell

[root@localhost mysql]# mysql -u root -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.28

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password=password('root');

Query OK, 0 rows affected, 1 warning (0.00 sec)

```

7)关闭防火墙

```shell

[root@localhost mysql]# systemctl status firewalld

● firewalld.service - firewalld - dynamic firewall daemon

Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)

Active: active (running) since 日 2020-07-26 23:36:30 CST; 20h ago

Docs

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值