企业私有云之mariadb集群高可用

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
简介:

上篇文章介绍了openstack组件rabbitmq高可用,现在介绍其另一个重要组件mysql高可用。

我是本次选择mysql的版本是mariadb,集群方法是galera cluster多主集群。

其实也有很多其他方案,如pxc、mha等等,选择galera的原因是安装方便,使用与维护也方便,多主模式任何一个节点挂了都可以在另外节点查看数据,同时openstack各组件也支持配置集群方式的配置。

简介

1
MariaDB Galera Cluster 是一套在mysql innodb存储引擎上面实现multi-master及数据实时同步的系统架构,业务层面无需做读写分离工作,数据库读写压力都能按照既定的规则分发到 各个节点上去。在数据方面完全兼容 MariaDB 和 MySQL。

特性

1
2
3
4
5
6
7
8
9
(1).同步复制 Synchronous replication
(2).Active-active multi-master 拓扑逻辑
(3).可对集群中任一节点进行数据读写
(4).自动成员控制,故障节点自动从集群中移除
(5).自动节点加入
(6).真正并行的复制,基于行级
(7).直接客户端连接,原生的 MySQL 接口
(8).每个节点都包含完整的数据副本
(9).多台数据库中数据同步由 wsrep 接口实现

不过局限性也有很多,比如复制仅支持innode,节点必须是3个等等,具体看官网介绍。

下面是安装

环境

系统centos 7.1

/etc/hosts是

1
2
3
node1 192.168.1.18
node2 192.168.1.20
node3 192.168.1.19

一、安装基础库(所有节点运行)

1
yum -y  install  make  cmake  bc  gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel  bzip2  bzip2 -devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel nss_ldap openldap openldap-devel  openldap-clients openldap-servers libxslt-devel libevent-devel ntp  libtool-ltdl bison libtool vim-enhanced  tar  wget readline-devel libyaml-devel  patch telnet lrzsz sysstat  screen  parted  rsync  libselinux-python dmidecode ntpdate sar openssh-clients  man

二、配置mariadb源(所有节点运行)

1
2
3
4
5
6
7
8
9
cat  > /etc/yum .repos.d /mariadb .repo <<EOF
# MariaDB 10.1 CentOS repository list - created 2016-05-24 07:59 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http: //yum .mariadb.org /10 .1 /centos7-amd64 
gpgkey=https: //yum .mariadb.org /RPM-GPG-KEY-MariaDB 
gpgcheck=1
EOF

三、安装(所有节点运行)

1
yum  install  MariaDB-server MariaDB-client -y

四、配置

1、在node1里运行

主要是修改bind-address、wsrep_cluster_name、wsrep_node_address、wsrep_node_name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@mysql-cluster-1 my.cnf.d] # cat /etc/my.cnf.d/server.cnf |grep -v '^#'|sed '/^$/d'
[server]
[mysqld]
collation-server = utf8_general_ci
init-connect =  'SET NAMES utf8'
character- set -server = utf8
skip-name-resolve
skip-host-cache
open_files_limit = 65535
max_connections = 5000
bind-address=192.168.1.18
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_file_per_table
character- set -server = utf8
[galera]
wsrep_on=ON
wsrep_provider= /usr/lib64/galera/libgalera_smm .so
wsrep_provider_options= "pc.recovery=TRUE;gcache.size=300M"
wsrep_cluster_address= 'gcomm://'
 
wsrep_cluster_name= 'ck-galera'
wsrep_node_address= '192.168.1.18'
wsrep_node_name= 'm-1'
wsrep_sst_method= rsync
[embedded]
[mariadb]
[mariadb-10.1]

启动

1
2
systemctl  enable  mariadb
systemctl start mariadb

初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
[root@mysql-cluster-1 log] # mysql_secure_installation
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MariaDB to secure it, we'll need the current
password  for  the root user.  If you've just installed MariaDB, and
you haven't  set  the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password  for  root (enter  for  none):
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
 
Set root password? [Y /n ] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
  ... Success!
 
 
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created  for
them.  This is intended only  for  testing, and to  make  the installation
go a bit smoother.  You should remove them before moving into a
production environment.
 
Remove anonymous  users ? [Y /n ] y
  ... Success!
 
Normally, root should only be allowed to connect from  'localhost' .  This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y /n ] n
  ... skipping.
 
By default, MariaDB comes with a database named  'test'  that anyone can
access.  This is also intended only  for  testing, and should be removed
before moving into a production environment.
 
Remove  test  database and access to it? [Y /n ] y
  - Dropping  test  database...
  ... Success!
  - Removing privileges on  test  database...
  ... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
 
Reload privilege tables now? [Y /n ] y
  ... Success!
 
Cleaning up...
 
All  done !  If you've completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks  for  using MariaDB!

查询集群数量

1
2
3
4
5
6
7
[root@mysql-cluster-1 log] # mysql -uroot -p -e "show status where Variable_name like 'wsrep_cluster_size'"
Enter password:
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 1     |
+--------------------+-------+

可以看到只有一个

查看当前集群ip

1
2
3
4
5
6
7
[root@mysql-cluster-1 log] # mysql -uroot -p -e "show status where Variable_name like 'wsrep_incoming_addresses'"
Enter password:
+--------------------------+-------------------+
| Variable_name            | Value             |
+--------------------------+-------------------+
| wsrep_incoming_addresses | 192.168.1.18:3306 |
+--------------------------+-------------------+

2、在node里配置

同样修改bind-address、wsrep_cluster_name、wsrep_node_address、wsrep_node_name

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@mysql-cluster-2 log] # grep -v '^#' /etc/my.cnf.d/server.cnf |sed '/^$/d'
[server]
[mysqld]
collation-server = utf8_general_ci
init-connect =  'SET NAMES utf8'
character- set -server = utf8
skip-name-resolve
skip-host-cache
open_files_limit = 65535
max_connections = 5000
bind-address=192.168.1.20
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_file_per_table
character- set -server = utf8
[galera]
wsrep_on=ON
wsrep_provider= /usr/lib64/galera/libgalera_smm .so
wsrep_provider_options= "pc.recovery=TRUE;gcache.size=300M"
wsrep_cluster_address= 'gcomm://192.168.1.18'
wsrep_cluster_name= 'ck-galera'
wsrep_node_address= '192.168.1.20'
wsrep_node_name= 'm-2'
wsrep_sst_method= rsync
[embedded]
[mariadb]
[mariadb-10.1]

启动

1
2
systemctl  enable  mariadb
systemctl start mariadb

查看集群数量

1
2
3
4
5
6
7
[root@mysql-cluster-2 log] # mysql -uroot -p -e "show status where Variable_name like 'wsrep_cluster_size'"
Enter password:
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 2     |
+--------------------+-------+

可以看到已经有2个节点了

查看集群ip

1
2
3
4
5
6
7
[root@mysql-cluster-2 log] # mysql -uroot -p -e "show status where Variable_name like 'wsrep_incoming_addresses'"
Enter password:
+--------------------------+-------------------------------------+
| Variable_name            | Value                               |
+--------------------------+-------------------------------------+
| wsrep_incoming_addresses | 192.168.1.20:3306,192.168.1.18:3306 |
+--------------------------+-------------------------------------+

可以看到node1与node2都在里面

3、在node3里配置

修改跟node1与node2一样

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@mysql-cluster-3 ~] # grep -v '^#' /etc/my.cnf.d/server.cnf |sed '/^$/d'
[server]
[mysqld]
collation-server = utf8_general_ci
init-connect =  'SET NAMES utf8'
character- set -server = utf8
skip-name-resolve
skip-host-cache
open_files_limit = 65535
max_connections = 5000
bind-address=192.168.1.19
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_file_per_table
character- set -server = utf8
[galera]
wsrep_on=ON
wsrep_provider= /usr/lib64/galera/libgalera_smm .so
wsrep_provider_options= "pc.recovery=TRUE;gcache.size=300M"
wsrep_cluster_address= 'gcomm://192.168.1.18,192.168.1.20'
wsrep_cluster_name= 'ck-galera'
wsrep_node_address= '192.168.1.19'
wsrep_node_name= 'm-3'
wsrep_sst_method= rsync
[embedded]
[mariadb]
[mariadb-10.1]

启动

1
2
systemctl  enable  mariadb
systemctl start mariadb

查看集群数量

1
2
3
4
5
6
7
[root@mysql-cluster-3 ~] # mysql -uroot -p -e "show status where Variable_name like 'wsrep_cluster_size'"
Enter password:
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+

查看集群ip

1
2
3
4
5
6
7
[root@mysql-cluster-3 ~] # mysql -uroot -p -e "show status where Variable_name like 'wsrep_incoming_addresses'"
Enter password:
+--------------------------+-------------------------------------------------------+
| Variable_name            | Value                                                 |
+--------------------------+-------------------------------------------------------+
| wsrep_incoming_addresses | 192.168.1.19:3306,192.168.1.20:3306,192.168.1.18:3306 |
+--------------------------+-------------------------------------------------------+

可以看到3个节点都在里面了。

下一步大家如果想测试,可以在任意一个节点里创建数据库与表,插入数据后,在另外节点里查看是否有对应信息,我这里就不列举了。





 本文转自 reinxu 51CTO博客,原文链接:http://blog.51cto.com/dl528888/1865285,如需转载请自行联系原作者

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
相关文章
|
SQL 分布式计算 Hadoop
Hadoop-12-Hive 基本介绍 下载安装配置 MariaDB安装 3台云服务Hadoop集群 架构图 对比SQL HQL
Hadoop-12-Hive 基本介绍 下载安装配置 MariaDB安装 3台云服务Hadoop集群 架构图 对比SQL HQL
273 3
|
SQL 分布式计算 关系型数据库
Hadoop-12-Hive 基本介绍 下载安装配置 MariaDB安装 3台云服务Hadoop集群 架构图 对比SQL HQL
Hadoop-12-Hive 基本介绍 下载安装配置 MariaDB安装 3台云服务Hadoop集群 架构图 对比SQL HQL
189 2
|
关系型数据库 MySQL Linux
小白带你学习linux的mariadb高可用MAH
小白带你学习linux的mariadb高可用MAH
265 0
|
关系型数据库 MySQL Linux
如何在CentOS 7服务器上配置使用MariaDB的Galera集群:
如何在CentOS 7服务器上配置使用MariaDB的Galera集群:
|
关系型数据库 MySQL Linux
MySQL集群升级从5.5版本升级到10.*以上版本(CentOS7.5 MariaDB集群升级)
MySQL集群升级从5.5版本升级到10.*以上版本(CentOS7.5 MariaDB集群升级)
565 0
MySQL集群升级从5.5版本升级到10.*以上版本(CentOS7.5 MariaDB集群升级)
|
运维 安全 数据库
【运维】MariaDB_galera_cluster集群
Galera Cluster 基于多主架构
3805 0
【运维】MariaDB_galera_cluster集群
|
关系型数据库 数据安全/隐私保护
|
关系型数据库 数据库 MySQL

热门文章

最新文章

推荐镜像

更多