1. 程式人生 > >MariaDB Galera Cluster 部署(如何快速部署 MariaDB 叢集)

MariaDB Galera Cluster 部署(如何快速部署 MariaDB 叢集)

MariaDB 作為 Mysql 的一個分支,在開源專案中已經廣泛使用,例如大熱的 openstack,所以,為了保證服務的高可用性,同時提高系統的負載能力,叢集部署是必不可少的。

MariaDB Galera Cluster 介紹

MariaDB 叢集是 MariaDB 同步多主機叢集。它僅支援 XtraDB/ InnoDB 儲存引擎(雖然有對 MyISAM 實驗支援 - 看 wsrep_replicate_myisam 系統變數)。

主要功能:

  • 同步複製
  • 真正的 multi-master,即所有節點可以同時讀寫資料庫
  • 自動的節點成員控制,失效節點自動被清除
  • 新節點加入資料自動複製
  • 真正的並行複製,行級
  • 使用者可以直接連線叢集,使用感受上與MySQL完全一致

優勢:

  • 因為是多主,所以不存在Slavelag(延遲)
  • 不存在丟失事務的情況
  • 同時具有讀和寫的擴充套件能力
  • 更小的客戶端延遲
  • 節點間資料是同步的,而 Master/Slave 模式是非同步的,不同 slave 上的 binlog 可能是不同的

技術:

Galera 叢集的複製功能基於 Galeralibrary 實現,為了讓 MySQL 與 Galera library 通訊,特別針對 MySQL 開發了 wsrep API。

Galera 外掛保證叢集同步資料,保持資料的一致性,靠的就是可認證的複製,工作原理如下圖:

當客戶端發出一個 commit 的指令,在事務被提交之前,所有對資料庫的更改都會被write-set收集起來,並且將 write-set 紀錄的內容傳送給其他節點。

write-set 將在每個節點進行認證測試,測試結果決定著節點是否應用write-set更改資料。

如果認證測試失敗,節點將丟棄 write-set ;如果認證測試成功,則事務提交。

1.安裝環境準備

安裝 MariaDB 叢集至少需要 3 臺伺服器(如果只有兩臺的話需要特殊配置,請參照官方文件)

在這裡,我列出試驗機器的配置:

作業系統版本:centos7

node4:10.128.20.16 node5:10.128.20.17 node6:10.128.20.18

以第一行為例,node4 為 hostname ,10.128.20.16為 ip ,在三臺機器修改 /etc/hosts檔案,我的檔案如下:

10.128.20.16 node4
10.128.20.17 node5
10.128.20.18 node6

為了保證節點間相互通訊,需要禁用防火牆設定(如果需要防火牆,則參照官方網站增加防火牆資訊設定)

在三個節點分別執行命令:

systemctl stop firewalld

然後將/etc/sysconfig/selinux 的 selinux 設定成 disabled ,這樣初始化環境就完成了。

2.安裝 MariaDB Galera Cluster

[[email protected] ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync
[[email protected] ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync
[[email protected] ~]# yum install -y mariadb mariadb-galera-server mariadb-galera-common galera rsync

3.配置 MariaDB Galera Cluster

初始化資料庫服務,只在一個節點進行

[[email protected] mariadb]# systemctl start mariadb
[[email protected] mariadb]# 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]
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] n
 ... skipping.

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] y
 ... Success!

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] n
 ... skipping.

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!

關閉資料庫,修改 /etc/my.cnf.d/galera.cnf

[[email protected] mariadb]# systemctl stop mariadb
[[email protected] ~]# vim /etc/my.cnf.d/galera.cnf

修改以下內容:

[mysqld]
......
wsrep_provider = /usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address = "gcomm://node4,node5,node6"
wsrep_node_name = node4
wsrep_node_address=10.128.20.16
#wsrep_provider_options="socket.ssl_key=/etc/pki/galera/galera.key; socket.ssl_cert=/etc/pki/galera/galera.crt;"

提示:如果不用 ssl 的方式認證的話,請把wsrep_provider_options 註釋掉。

將此檔案複製到node5、node6,注意要把 wsrep_node_name和 wsrep_node_address改成相應節點的 hostnameip

4.啟動 MariaDB Galera Cluster 服務

[[email protected] ~]# /usr/libexec/mysqld --wsrep-new-cluster --user=root &

觀察日誌:

[[email protected] ~]# tail -f /var/log/mariadb/mariadb.log

150701 19:54:17 [Note] WSREP: wsrep_load(): loading provider library 'none'
150701 19:54:17 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.40-MariaDB-wsrep'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server, wsrep_25.11.r4026

出現 ready for connections ,證明我們啟動成功,繼續啟動其他節點:

[[email protected] ~]# systemctl start mariadb
[[email protected] ~]# systemctl start mariadb

可以檢視/var/log/mariadb/mariadb.log,在日誌可以看到節點均加入了叢集中。

警告⚠:--wsrep-new-cluster 這個引數只能在初始化叢集使用,且只能在一個節點使用。

5.檢視叢集狀態

我們可以關注幾個關鍵的引數:

wsrep_connected = on 連結已開啟

wsrep_local_index = 1在叢集中的索引值

wsrep_cluster_size =3叢集中節點的數量

wsrep_incoming_addresses = 10.128.20.17:3306,10.128.20.16:3306,10.128.20.18:3306 叢集中節點的訪問地址

6.驗證資料同步

我們在node4上新建資料庫 galera_test ,然後在node5 和node6 上查詢,如果可以查詢到 galera_test 這個庫,說明資料同步成功,叢集執行正常。

[[email protected] ~]# mysql  -uroot  -proot  -e  "create database galera_test"
[[email protected] ~]# mysql  -uroot  -proot  -e  "show databases"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| galera_test        |
| mysql              |
| performance_schema |
+--------------------+
[[email protected] ~]# mysql  -uroot  -proot  -e  "show databases"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| galera_test        |
| mysql              |
| performance_schema |
+--------------------+

至此,我們的 MariaDB Galera Cluster 已經成功部署。

本文系OneAPM工程師陳亮原創文章。想閱讀更多技術文章,請訪問OneAPM官方技術部落格

相關推薦

CentOS7.5 Qihoo360/wayne部署web管理K8S叢集

# 安裝依賴包 yum install -y yum-utils device-mapper-persistent-data lvm2 # 新增Docker軟體包源 yum-config-manager \ --add-repo \ https://download.docker.com/linux/cen

MariaDB Galera Cluster 部署如何快速部署 MariaDB 叢集

MariaDB 作為 Mysql 的一個分支,在開源專案中已經廣泛使用,例如大熱的 openstack,所以,為了保證服務的高可用性,同時提高系統的負載能力,叢集部署是必不可少的。 MariaDB Galera Cluster 介紹 MariaDB 叢集是 MariaDB

Mariadb Galera Cluster 部署

數據庫不同於標準的MySQL服務器和MySQL集群,MySQL / MariaDB Galera集群在啟動方式上有一些細小的區別。Galera需要在集群啟動一個節點作為參考點,剩余的節點才能加入形成集群。這個過程被稱為集群引導。引導是一個初始步驟,引導數據庫節點作為主節點,其它節點將主節點作為參考點同步數據。

CentOS 7.2部署MariaDB Galera Cluster(10.1.21-MariaDB) 3主叢集環境

MariaDB Galera Cluster 介紹Galera Cluster是由第三方公司Codership所研發的一套免費開源的叢集高可用方案,實現了資料零丟失,官網地址為http://galeracluster.com/。其在MySQLInnoDB儲存引擎基礎上打了wr

在CentOS7上配置MariaDB-Galera-Cluster過程全記錄

base table inf replicat connect 全局 lec sig 5.5 在CentOS7上配置MariaDB-Galera-Cluster過程全記錄 MySQL or MariaDB Replication之Galera Cluster Galera

實戰Mariadb galera Cluster集群架構

mariadb mysql centos galera Mariadb galera Cluster安裝:操作系統:Centos7.4版本集群數量:3個節點主機信息: 192.168.153.142 node1 selinux=disabled firewalld關閉192.168.1

初識MariaDB之10——MariaDB Galera Cluster

mysql mariadb PXC Galera 一、背景介紹無論是采用binlog或者GTID的方式,其本質都是通過I/O_thread和sql_thread的形式進行的同步,因為無法避免復制延遲而飽受詬病,基於上述MariaDB引入了Galera Cluster來解決此問題。二、Galer

mysql database 高可用架構:MariaDB Galera Cluster

[[email protected] ~]# rpm -ivh epel-release-6-8.noarch.rpm  [[email protected] ~]# yum install -y

如何在CentOS上設定MariaDB Galera Cluster 10.0

   原作者:Jijo 轉載:https://www.unixmen.com/setup-mariadb-galera-cluster-10-0-centos/   如何在CentOS上設定MariaDB Galera Cluster 10.0 &nbs

MariaDB Galera Cluster簡介及雙主HA實踐

MariaDB GaleraCluster簡介及雙主HA實踐 http://blog.sina.com.cn/s/blog_6de3aa8a0102w00d.html 概述       MariaDB Galera Cluster由於其優異的特性,被廣泛用於各類分散式系統中

MariaDB-Galera-cluster實現mariadb高可用的詳細步驟

大小寫 .cn 服務器 修改配置文件 art 註意 name mys install MariaDB的Galera-cluster實現高可用的詳細步驟 ? A. 實驗環境說明 ? a) 至少3臺centos7主機 ? b) 角色: a、 master1:1

spark2.10安裝部署集成hadoop2.7+

use star temp 保存 local export per home hadoop 這裏默認你的hadoop是已經安裝好的,master是node1,slaver是node2-3,hdfs啟動在node1,yarn啟動在node2,如果沒安裝好hadoop可以看我前

Linux系統配置及服務管理_第01章系統部署 第二小節初識shell

*** 簡介 例子 特點 基本特性 上進 用戶編寫 ffffff shell編程 ***大家好,我是霸王卸甲,又到了今天更新文章的時間了,今天給大家帶來的是第一章中的第二小節 shell語言!!*** GNU bash簡介:Shell是系統的用戶界面,提供了用戶與內核進

使用IDEA 中 實現springboot 熱部署 spring boot devtools版

apple convert lang start class tool 但是 原理 tty 第一步:添加springboot的配置文件 首先我先貼出我的配置 添加依賴包 <!-- spring boot devtools 依賴包. --> &

Disconf 學習系列之全網最詳細的最新穩定Disconf 搭建部署基於Windows7 / 8 / 10圖文詳解

分享 study str www windows 最新 1.8 環境 text   不多說,直接上幹貨! 工作環境以及安裝依賴軟件 Zookeeper-3.4.8 Disconf 2.6.36 Nginx 1.9.9(見如下博文的phpstu

Eclipse中使用JRebel實現項目熱部署Maven插件版

圖片 pom 參數 項目 設置 tof 並保存 central 打印 JRebel實現項目熱部署(Maven插件版) 熱部署,就是在應用運行過程中不進行重啟,可直接進行軟件升級。 在開發過程中,熱部署就是在項目運行過程中變更代碼,無需重啟服務器即可使代碼生效。 tomc

超詳解百萬PV網站架構案例部署內附安裝包

事先 接下來 ecc vim 兩臺 keepaliv lis chm back 網站架構概述 網站架構是根據客戶需求分析的結果,準確定位網站目標群體,設定網站的整體架構,規劃、設計網站欄目及其內容,制定網站開發流程的順序,最大限度地進行高效資源分配與管理的設計。 網站架

jenkins 整合maven,svn配置鉤子程式實現提交程式碼自動構建,tomcat實現熱部署windows+linux分別實現

1 準備工作: (1)執行jenkins的tomcat (2)執行我們專案的tomcat (3)SVN伺服器 jenkins就是一個war包,相信大家都非常熟悉,扔在tomcat  webapp下就能跑,具體操作步驟上網去搜一搜一大把,我們主要是來記錄一下如何實現鉤子程式,實現程式碼的動態部

CentOS 7部署Hadoop叢集HA高可用叢集

目錄 測試環境 Hadoop 組織框架 HDFS架構 YARN架構 HA叢集部署規劃 自動故障轉移 關於叢集主機時間 Linux環境搭建 配置Java環境 安裝單機版Hadoop Zookeeper叢集安裝 配置環境變數 關閉防火牆 修

Hadoop2.5.2集群部署完全分布式

tex 免密碼登錄 文件復制 job src 時間 配置環境 8.0 上進 環境介紹 硬件環境 CPU 4 MEM 4G 磁盤 60G 軟件環境 OS:centos6.5版本 64位 Hadoop:hadoop2.5.2 64位 JDK: JDK 1.8.0_91 主機