公司私有云

公司私有云,第1张

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

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

不过我这次选择的mysql版本是mariadb,集群方式是galeracluster多主集群。

其实还有很多其他的方案,比如pxc,mha等。之所以选择galera,是因为它安装简单,使用维护也方便。在多主模式下,任何一个节点都可以查看另一个节点的数据,openstack的所有组件也都支持集群模式的配置。

简介

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

特点

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

但是也有很多限制,比如复制只支持innode,节点数必须为3等。详见官网介绍。

这里是安装。

环境

系统centos7.1

/etc/hosts是

node1 192.168.1.18 node2 192.168.1.20 node3 192.168.1.19

首先,安装基本库(所有节点都运行)

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源(所有节点运行)

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

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

yum install MariaDB-server MariaDB-client -y

四。配置

1.在节点1中运行

主要修改bind-address,wsrep_cluster_name,wsrep_node_address,wsrep_node_name。

[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]

开始

systemctl enable mariadb systemctl start mariadb

初始化

[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!

查询次数

[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

[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.在节点中配置

修改绑定地址、wsrep_cluster_name、wsrep_node_address和wsrep_node_name。

[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]

开始

systemctl enable mariadb systemctl start mariadb

查看集群的数量

[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     | +--------------------+-------+

您可以看到已经有两个节点

检查群集ip

[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.在节点3中配置

就像修改节点1和节点2一样

[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]

开始

systemctl enable mariadb systemctl start mariadb

检查群集的数量

[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

[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 | +--------------------------+-------------------------------------------------------+

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

下一步如果要测试,可以在任意节点创建数据库和表,插入数据,检查其他节点是否有对应的信息,这里就不一一列举了。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/zz/778197.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-03
下一篇 2022-05-03

发表评论

登录后才能评论

评论列表(0条)

保存