-
4. MySQL Galera Cluster全解析 Part 4 Galera Cluster 安装前准备
tutorial4
-
-
Attachments
-
Changes
-
View Source
-
View
## 前期回顾
**Galera架构**
| 主机名 |IP地址|操作系统 |MySQL版本|插件版本|
| --- | --- | --- | --- | ---|
| rac1 | 11.12.14.29| Redhat 6.10|5.7.26|25.3.27|
| rac2| 11.12.14.30| Redhat 6.10|5.7.26|25.3.27|
| rac3 | 11.12.14.39 | Redhat 6.10|5.7.26|25.3.27|
前面我们说了Galera Cluster有三种不同的分支
- MySQL Galera Cluster by Codership
- Percona XtraDB Cluster by Percona
- MariaDB Galera Cluster (5.5 and 10.0) by MariaDB
这里我们以官方的软件来做演示,即第一个
## 1. 软件组成
Galera Cluster由两部分组成
- the Galera Replication Library (galera-3)
- a version of MySQL extended with the Write Set Replication (WSREP) API
第一个即Galera 插件
第二个为集成了wsrep API的 MySQL服务器软件
以上意味着我们需要安装一个集成了Galera的MySQL数据库和一个Galera插件
## 2. 下载软件
官方提供了两种安装方式
- MySQL Binary Installation
- MySQL Source Installation
我们MySQL采用源码安装,Galera插件采用二进制安装
我们通过官方网站下载源码包
[https://galeracluster.com/downloads/](https://galeracluster.com/downloads/)
[image:748 size:orig]
[image:749 size:orig]
galera以及下面说的依赖包可以通过如下链接下载
链接: https://pan.baidu.com/s/1SOQDgCrqEbVdyyWOmS2RPw 提取码: 9h22
## 3. 依赖关系解决
通过源码安装我们首先需要解决依赖关系
SCons这里暂不安装
- **MySQL Database的依赖包 Server with wsrep API**: Git, CMake, GCC and GCC-C++, Automake, Autoconf, and Bison, as well as development releases of libaio and ncurses.
- **Galera Replication Plugin**: SCons, as well as development releases of Boost, Check and OpenSSL.
### 3.1 yum源安装
**三台服务器**
下面给出相应的命令,大家可以配置本地yum源后进行安装
```
yum install -y git
yum install -y cmake
yum install -y gcc
yum install -y gcc-c++
yum install -y automake
yum install -y autoconf
yum install -y bison
yum install -y libaio*
yum install -y ncurses*
yum install -y check*
yum install -y openssl*
yum install -y python-devel
yum install -y bzip*
yum install -y zlib*
yum install pam*
```
### 3.2 boost 安装
由于需要1.59的boost版本,这里我们单独安装
[https://www.boost.org/users/history/](https://www.boost.org/users/history/)
**三台服务器**
```
root> mkdir -p /usr/local/boost
root> cd /tmp
root> tar zxvf boost_1_59_0.tar.gz
root> cd boost_1_59_0
root> ./bootstrap.sh --with-libraries=all --with-toolset=gcc
root> ./b2 toolset=gcc
root> ./b2 install --prefix=/usr/local/boost
```
## 4. MySQL环境准备
### 4.1 目录规划
| 目录名称 | 参数名称 | 路径地址|
| --------- | --------- | ---------|
| 安装目录 | basedir|/usr/local/mysql|
| 数据文件目录 | datadir |/data/mysql/data|
| 临时文件目录 | tmpdir |/data/mysql/tmp|
| socket文件位置 |socket|/data/mysql/data/mysql.sock|
| bin日志文件目录| log_bin|/datalog/mysql/binlog|
| relay日志文件目录| relay_log |/datalog/mysql/relaylog|
### 4.2 操作系统环境准备
Galera Cluster最少需要3个节点
其可提供多种冗余架构,节点可分布正在多个交换机,网络和数据中心
**硬件需求**
最低要求
- 1 GHz single core CPU;
- 512 MB RAM; and
- 100 Mbps network connectivity
**软件需求**
- Linux or FreeBSD operating system installed;
- MySQL or MariaDB server with the wsrep API patch;
- andGalera Replication Plugin installed.
**其他要求**
- 建议关闭selinux
- 建议关闭防火墙
### 4.3 建立用户
**三台服务器**
```
root> /usr/sbin/groupadd -g 105
root> mysql/usr/sbin/useradd -u 105 -g mysql mysql
root> echo "mysql123" |passwd mysql --stdin
```
之后配置环境变量
```
vim ~/.bash_profile
export MYSQL_HOME=/usr/local/mysql
export PATH=$HOME/bin:$MYSQL_HOME/bin:$PATH
export LD_LIBRARY_PATH=$MYSQL_HOME/lib:$LD_LIBRARY_PATH
source ~/.bash_profile
```
### 4.4 建立配置文件
这里建立/etc/my.cnf
具体内容参考以前的MySQL安装文档
[http://www.zhaibibei.cn/mysql/mysql-install/linux1/](http://www.zhaibibei.cn/mysql/mysql-install/linux1/)
之后更改文件权限
```
chown mysql:mysql /etc/my.cnf
```
### 4.5 hosts文件设置
**三台服务器**
```
11.12.14.29 rac1
11.12.14.30 rac2
11.12.14.39 rac3
```
## 5. 参考资料
[https://galeracluster.com/library/documentation/install.html](https://galeracluster.com/library/documentation/install.html)
[上一章](http://www.zhaibibei.cn/mysql/galera/tutorial3)
[下一章](http://www.zhaibibei.cn/mysql/galera/tutorial5)