# mysql-community-ha **Repository Path**: oneslideicywater/mysql-community-ha ## Basic Information - **Project Name**: mysql-community-ha - **Description**: mysql社区版高可用自动化部署 - **Primary Language**: Shell - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-08-29 - **Last Updated**: 2021-02-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # mysql-community-ha #### Description mysql社区版高可用希望在主从环境下实现自动化部署,并对mysql-community-ui项目的参数调节面板,性能监控,压力测试,日志分析等功能提供底层支持。 提供底层支持的项目包括: 1. [mysql-community-ui ](https://gitee.com/oneslideicywater/mysql-community-ui.git) > CentOS上yum的Mysql版本过老,所以需要安装mysql repo来安装最新版。你需要安装最新版git下载repo包,然后安装mysql。 ### Prerequisites 1. 一个干净的,可联网Centos 7虚拟机 #### Software Architecture mysql-comunnity-ha希望只在master节点上执行脚本来搭建MySQL的主从环境,只要求主从可以联网,可以互相ping通,不对slave节点做任何要求。 #### Instructions ##### 快速搭建mysql单机环境 ``` bash install.sh ``` 密码会打印出来。 ```bash RNING: Using a password on the command line interface can be insecure. I change your password to One.00000 ``` ##### 自动搭建主从结构 > 以下所有操作均在主节点运行 1. 复制项目根目录的`git-build-fromsource.sh`,运行 (这个操作会在机器上安装git) ```shell wget https://gitee.com/oneslideicywater/mysql-community-ha/raw/master/git-build-fromsource.sh bash git-build-fromsource.sh ``` 2. 运行 ` git clone https://gitee.com/oneslideicywater/mysql-community-ha.git` 3. 本项目依赖于Ansible实现主从集群管理 ```shell cd mysql-community-ha yum -y install ansible ``` 4. 编辑 `/etc/ansible/hosts`文件,我们选取master和slaves组: ```ini [master] 192.168.xx.xx [slaves] 192.168.xx.xx 192.168.xx.xx ``` 5. 建立互信 这个操作会读取`/etc/ansible/hosts` 文件中master和slaves信息,并全部配置master到所有slave节点的双向互信和自信, 但是slave节点到slave节点间互信不包括在内 ```bash #你应该设定master和附属slave节点使用同一个密码 bash ssh/mutual-trust.sh <你的root密码> ``` 6.运行 setup.sh 这个脚本会在所有机器上安装mysql,并进行时间同步 ```shell bash setup.sh ``` 7. 搭建主从环境 - 二进制日志方式 ```bash # connect to mysql using mysql user 'root' with password 'One.00000' on Master node with ip 'master_ip(you should # substitute with you own ip)' and set master 'server-id=1' bash ha/ha.sh -u root -p One.00000 -h -n 1 ``` - GTID方式 ```bash # 你得在主从上都得下载项目,而二进制方式不用 cd mysql-community-ha/ha #在主节点运行 bash gtid-master-script -p One.00000 #在从节点运行 bash gtid-slave-script.sh -p One.00000 -h 192.168.0.142 -r One.00000 ``` #### Gitee Feature 1. 高可用版正在开发中..... ### MHA Reference List 1. https://www.percona.com/blog/2016/09/02/mha-quickstart-guide/ 2. https://severalnines.com/database-blog/mysql-replication-failover-maxscale-vs-mha-part-one 3. https://github.com/yoshinorim/mha4mysql-manager/wiki/Overview