title, date, lastmod, tags, categories
title |
date |
lastmod |
tags |
categories |
CentOS7 部署 Mariadb Galera 集群 |
2019-10-30T14:01:06+08:00 |
2019-10-30T14:01:06+08:00 |
|
|
环境
cpu |
mem |
hostname |
public ip |
cluster ip |
CentOS |
MariaDB |
双核 |
2GB |
mariadb_1 |
10.0.0.231 |
10.10.10.1 |
7.5 |
10.1.33 |
双核 |
2GB |
mariadb_2 |
10.0.0.232 |
10.10.10.2 |
7.5 |
10.1.33 |
双核 |
2GB |
mariadb_3 |
10.0.0.233 |
10.10.10.3 |
7.5 |
10.1.33 |
安装数据库
离线安装
yum 安装
-
创建 MariaDB-10.1 的 yum 源文件(就近选择一个)
#官方
cat > /etc/yum.repos.d/MariaDB.repo <<-END
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
END
#中科大
cat > /etc/yum.repos.d/MariaDB.repo <<-END
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.1/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
END
#上海大学
cat > /etc/yum.repos.d/MariaDB.repo <<-END
[mariadb]
name = MariaDB
baseurl = https://mirrors.shu.edu.cn/mariadb/yum/10.1/centos7-amd64
gpgkey=https://mirrors.shu.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
END
-
安装 MariaDB
yum install MariaDB-client MariaDB-server
# galera_4 会作为依赖自动安装
启动server
```bash
systemctl start mariadb
```
安全设置
配置Galera Cluster
- 修改/etc/my.cnf.d/server.cnf如下
[server]
innodb-flush-log-at-trx-commit=0
innodb-buffer-pool-size=1024M #一半内存
innodb-autoinc-lock-mode=2
default-storage-engine=InnoDB
#
[mysqld]
#
[galera]
wsrep-on=ON
wsrep-provider = /usr/lib64/galera/libgalera_smm.so
wsrep-provider-options="gcache.dir=/var/lib/gcache;gcache.size=1G;gcache.recover=yes;pc.recovery=TRUE"
wsrep-cluster-name="mariadb_galera_cluster"
wsrep-cluster-address = "gcomm://10.10.10.1,10.10.10.2,10.10.10.3"
wsrep-node-name = mariadb_1 #当前节点名字
wsrep-node-address = 10.10.10.1 #当前节点地址
binlog-format=ROW
wsrep-slave-threads=2
wsrep-sst-method=rsync
#wsrep-auto-increment-control=OFF #只通过一个节点做增删改时使用
#
[embedded]
#
[mariadb]
#
[mariadb-10.1]
停止 server
```bash
systemctl stop mariadb
```
启动集群
- 启动 galera cluster
mysqld --wsrep-new-cluster --user=mysql
- 查看集群状态
show status like 'wsrep_%';
- 在剩余两台服务器启动 server,向集群中添加节点
systemctl start mariadb
- 再次查看集群状态
show status like 'wsrep_%';
注意事项
- 防火墙开放 3306、4444 和 4567 端口
- 关闭 selinux
- 集群关闭时,/var/lib/mysql/grastate.dat 文件中 safe_to_bootstrap 项为 1 的节点服务器是最后关闭的数据库,数据最全,所以下次集群启动时应从这台节点服务器启动