構建 MariaDB Galera Cluster 分佈式數據庫集羣(二)

MariaDB的安裝

構建 MariaDB Galera Cluster以前,首先安裝MariaDB,本文使用的版本是10.1node

1.環境準備

主機:mysql

  • MariaDB01(192.168.56.102)
  • MariaDB02(192.168.56.103)
  • MariaDB03(192.168.56.104)

OS: centos6.5
MariaDB版本:10.1linux

yum源設置
Here is your custom MariaDB YUM repository entry for CentOS. Copy and paste it into a file under /etc/yum.repos.d/ (we suggest naming the file MariaDB.repo or something similar). See "Installing MariaDB with yum" for detailed information.
#翻譯:這是您CentOS的自定義MariaDB YUM存儲庫條目。 將它複製並粘貼到/etc/yum.repos.d/下的文件(咱們建議命名文件MariaDB.repo或相似的東西)。 有關詳細信息,請參閱「使用yum安裝MariaDB」。nginx

vim /etc/yum.repos.d/MariaDB.repo 寫入以下內容:

# MariaDB 10.1 CentOS repository list - created 2016-09-30 08:23 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

而後執行下列命令導入證書並更新reposql

# sudo rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
# yum repolist

若是你對網絡質量充滿信心,你如今就能夠進入第二步的安裝maridb了,可是我強烈建議你用下面的這個方法,由於你可能要反覆測試重裝個幾回,畢竟每次都從官網下載不是一件高效的事兒。數據庫

就像上面說的,若是你擔憂和考慮到網絡質量不佳的狀況,可下載rpm包後自建yum源
http://downloads.mariadb.com/MariaDB/mariadb-10.1/yum/rhel/mariadb-10.1.19-rhel-6-x86_64-rpms.tar 自建yum源方法可問下度娘
或者訪問https://mariadb.com/downloads/maxscale下載最新版本的mariadb(它會自動給你選擇最新的mariadb的,因爲各版本安裝配置差別較大,本文只對mariadb10.1版本負責)
對新版感興趣的能夠測試下maxscale方法:
#install MariaDB MaxScale like this:
#https://mariadb.com/downloads/maxscale
yum install maxscale  或者
RPM-ivh https://downloads.mariadb.com/MaxScale/2.0.3/rhel/6/x86_64/maxscale-2.0.3-1.rhel.6.x86_64.rpm
或者依據官方提供的https://downloads.mariadb.com/MaxScale/x.x.x/rhel/6/x86_64/maxscale-x.x.x-.rhel.6.x86_64.rpm最新版本進行安裝bootstrap

2.安裝maridb

如下安裝過程來源於官網 https://mariadb.com/kb/en/mariadb-enterprise/mariadb-enterprise-installation-guide/
#Install MariaDB Enterprise Server or MariaDB Enterprise Cluster 10.1 like this:vim

yum install MariaDB-server MariaDB-client

官網還提供了MariaDB Enterprise Cluster 5.5的安裝方法,不是本文的重點,直接跳過。
值得注意的是,若是你要安裝5.5版本,則後面的cluster集羣的安裝配置和10.1版本下是徹底不同的,須要高度注意,避免發生混淆和錯誤。windows

3.建立執行用戶

# groupadd mariadb
# useradd -g mariadb mariadb
# passwd mariadb
# echo 'mariadb ALL=(ALL) ALL' >> /etc/sudoers
# cd /var/lib
# chown -R mariadb:mariadb mysql

4.啓動maridb服務

請根據自身系統版本,選擇適合的啓動方法啓動便可。本文安裝環境是在centos6.5下,按照4.3進行啓動centos

4.1:On RHEL and CentOS starting with version 7 using systemd, start MariaDB like this: (經過systemd啓動mariadb)
# systemctl start mariadb.service

4.2:or on RHEL and CentOS starting with version 7 using systemd, bootstrap the first node of a MariaDB Enterprise Cluster like this:
# galera_new_cluster

4.3:or on RHEL and CentOS before version 7, such as centos6.5, start MariaDB like this:(在centos6.5上仍然按照啓動mysql的方法啓動mariadb)

# service mysql start

啓動時可能會遇到下列錯誤:
Starting MySQL.161222 11:28:27 mysqld_safe Logging to '/var/lib/mysql/MariaDB03.err'.
 ERROR!
#檢查是因爲/var/lib/mysql/MariaDB03.err權限的問題,須要執行 su mariadb,在mariadb用戶下啓動服務

[root@MariaDB03 ~]# cat /var/lib/mysql/MariaDB03.err
161222 11:28:27 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2016-12-22 11:28:27 140570816137248 [Note] /usr/sbin/mysqld (mysqld 10.1.18-MariaDB) starting as process 3650 ...
2016-12-22 11:28:27 140570816137248 [ERROR] mysqld: File '/var/lib/mysql/aria_log_control' not found (Errcode: 13 "Permission denied")
2016-12-22 11:28:27 140570816137248 [ERROR] mysqld: Got error 'Can't open file' when trying to use aria control file '/var/lib/mysql/aria_log_control'
2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'Aria' init function returned error.
2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'Aria' registration as a STORAGE ENGINE failed.
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: The InnoDB memory heap is disabled
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using Linux native AIO
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Using SSE crc32 instructions
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-12-22 11:28:27 140570816137248 [Note] InnoDB: Completed initialization of buffer pool
2016-12-22 11:28:27 140570816137248 [ERROR] InnoDB: ./ibdata1 can't be opened in read-write mode
2016-12-22 11:28:27 140570816137248 [ERROR] InnoDB: The system tablespace must be writable!
2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'InnoDB' init function returned error.
2016-12-22 11:28:27 140570816137248 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
2016-12-22 11:28:27 140570816137248 [Note] Plugin 'FEEDBACK' is disabled.
2016-12-22 11:28:27 140570816137248 [ERROR] Could not open mysql.plugin table. Some plugins may be not loaded
2016-12-22 11:28:27 140570816137248 [ERROR] Unknown/unsupported storage engine: InnoDB
2016-12-22 11:28:27 140570816137248 [ERROR] Aborting
161222 11:28:27 mysqld_safe mysqld from pid file /var/lib/mysql/MariaDB03.pid en

# su mariadb
$ service mysql start


4.4:or on RHEL and CentOS before version 7, bootstrap the first node of a MariaDB Enterprise Cluster like this:
service mysql bootstrap

5.初始化maridb數據庫

在mariadb@MariaDB01 至 mariadb@MariaDB03上分別初始化msyql

[mariadb@MariaDB01 root]# su mariadb
$ sudo mysql_secure_installation

>根據提示進行操做
>因爲是測試,密碼推薦設置爲空,便於後面的操做,正式用的時候再修改密碼
>必定要設置不容許root遠程訪問,這是起碼的操守,不要再問爲何了,由於之後也不會再去改它了吧

5.防火牆設置

centos6,root下執行

# iptables -A INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT
# iptables -A INPUT -i eth0 -p tcp --dport 4567 -j ACCEPT

若是在centos7下,諸如這樣執行:

# firewall-cmd --add-port=3306/tcp #暫時生效,重啓後失效
# firewall-cmd --permanent --add-port=3306/tcp #永久生效

正式環境務必要配置防火牆的,尤爲對於研發的人來講,必定要重視這個問題
如測試用,可關閉防火牆,忽略此配置便可

6.mysql管理和監控工具

MySQL免費性能監控工具-MONyog 分linux和windows版
SQLyog數據庫管理 只有windows版
上面的工具說實話我沒用過,我更習慣用nginx/zabbix進行監控,用navicat進行管理

7.使用

安裝完了,簡單測試下吧

[mariadb@MariaDB01 my.cnf.d]$ mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.1.18-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

#看看集羣的狀態如何

MariaDB [(none)]> show status like 'wsrep%';
+--------------------------+----------------------+
| Variable_name            | Value                |
+--------------------------+----------------------+
| wsrep_cluster_conf_id    | 18446744073709551615 |
| wsrep_cluster_size       | 0                    |
| wsrep_cluster_state_uuid |                      |
| wsrep_cluster_status     | Disconnected         |
| wsrep_connected          | OFF                  |
| wsrep_local_bf_aborts    | 0                    |
| wsrep_local_index        | 18446744073709551615 |
| wsrep_provider_name      |                      |
| wsrep_provider_vendor    |                      |
| wsrep_provider_version   |                      |
| wsrep_ready              | OFF                  |
| wsrep_thread_count       | 0                    |
+----------------------

MariaDB [(none)]> show variables like 'wsrep_cluster_address';
+-----------------------+------------------------------------------------------+
| Variable_name         | Value                                                |
+-----------------------+------------------------------------------------------+
| wsrep_cluster_address | gcomm://192.168.56.102,192.168.56.103,192.168.56.104 |  #這個展現是已經配置過集羣的,初始安裝的這裏顯示的應該是空,不要被誤導啊!
+-----------------------+------------------------------------------------------+
1 row in set (0.00 sec)

如今還只是個MariaDB10.1的環境,要完成MariaDB Galera Cluster請繼續看下一章內容

 

-本章完-

2017-02-24

相關文章
相關標籤/搜索