MariaDB Galera集群部署


准備三台服務器

操作系統版本: centos7

數據庫版本:5.5.56-MariaDB

主節點:192.168.224.131

節點1:192.168.224.132

節點2:192.168.224.133

一、各節點之間添加解析

vi /etc/hosts

192.168.224.131 k8s-master
192.168.224.132 k8s-node1
192.168.224.133 k8s-node2

二、配置mariadb的yum源

1.查看是否有安裝mariadb
rpm -qa | grep MariaDB 
rpm -qa | grep mariadb
2.卸載
rpm -e --nodeps MariaDB-*
yum remove mysql mysql-server mysql-libs compat-mysql51

3.添加源
vim /etc/yum.repos.d/MariaDB.repo


[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

三、每個節點安裝mariadb和galera

yum install -y MariaDB-server MariaDB-client galera -y

四、初始化數據庫

systemctl restart mariadb
mysql_secure_installation 
回車
y
設置root密碼
y
n
y
y

五、關閉數據庫,修改/etc/my.cnf.d/server.cnf

[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.224.131,192.168.224.132,192.168,224.133"  #節點IP地址
wsrep_node_name= k8s-mastr-1        #節點主機名
wsrep_node_address=192.168.224.131   #節點IP
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_slave_threads=1
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=120M
wsrep_sst_method=rsync
wsrep_causal_reads=ON

將此文件復制到mariadb-2、mariadb-3,注意要把 wsrep_node_name 和 wsrep_node_address 改成相應節點的 hostname 和 ip。

六、啟動集群

主節點啟動192.168.224.131啟動命令如下
galera_new_cluster 
 
 其他節點啟動:
  systemctl restart mariadb
  
  集群服務監聽了4567和3306端口(每個節點都監聽了4567和3306端口)   
  
  ss -tnl

連接mariadb,查看是否啟用galera插件

##顯示on表示開啟
show status like "wsrep_ready";
##查看集群集群數
 show status like "wsrep_cluster_size";
 ##查看集群集群狀態
 MariaDB [(none)]> show status like "wsrep%";
+------------------------------+-------------------------------------------------------+
| Variable_name                | Value                                                 |
+------------------------------+-------------------------------------------------------+
| wsrep_apply_oooe             | 0.000000                                              |
| wsrep_apply_oool             | 0.000000                                              |
| wsrep_apply_window           | 0.000000                                              |
| wsrep_causal_reads           | 2                                                     |
| wsrep_cert_deps_distance     | 0.000000                                              |
| wsrep_cert_index_size        | 0                                                     |
| wsrep_cert_interval          | 0.000000                                              |
| wsrep_cluster_conf_id        | 14                                                    |
| wsrep_cluster_size           | 3                                                     |
| wsrep_cluster_state_uuid     | 541248ce-56d0-11e9-b41b-3a9775d73ca7                  |
| wsrep_cluster_status         | Primary         #主服務器                                      |
| wsrep_commit_oooe            | 0.000000                                              |
| wsrep_commit_oool            | 0.000000                                              |
| wsrep_commit_window          | 0.000000                                              |
| wsrep_connected              | ON         #當前是否連接中                                            |
| wsrep_desync_count           | 0                                                     |
| wsrep_evs_delayed            |                                                       |
| wsrep_evs_evict_list         |                                                       |
| wsrep_evs_repl_latency       | 0/0/0/0/0                                             |
| wsrep_evs_state              | OPERATIONAL                                           |
| wsrep_flow_control_paused    | 0.000000                                              |
| wsrep_flow_control_paused_ns | 0                                                     |
| wsrep_flow_control_recv      | 0                                                     |
| wsrep_flow_control_sent      | 0                                                     |
| wsrep_gcomm_uuid             | 540ee869-56d0-11e9-955e-9b7f30e437a6                  |
| wsrep_incoming_addresses     | 192.168.64.5:3306,192.168.64.4:3306,192.168.64.7:3306 | #連接中的數據庫
| wsrep_last_committed         | 0                                                     |
| wsrep_local_bf_aborts        | 0                                                     |
| wsrep_local_cached_downto    | 18446744073709551615                                  |
| wsrep_local_cert_failures    | 0                                                     |
| wsrep_local_commits          | 0                                                     |
| wsrep_local_index            | 1                                                     |
| wsrep_local_recv_queue       | 0                                                     |
| wsrep_local_recv_queue_avg   | 0.100000                                              |
| wsrep_local_recv_queue_max   | 2                                                     |
| wsrep_local_recv_queue_min   | 0                                                     |
| wsrep_local_replays          | 0                                                     |
| wsrep_local_send_queue       | 0                                                     |
| wsrep_local_send_queue_avg   | 0.000000                                              |
| wsrep_local_send_queue_max   | 1                                                     |
| wsrep_local_send_queue_min   | 0                                                     |
| wsrep_local_state            | 4                                                     |
| wsrep_local_state_comment    | Synced                                                |
| wsrep_local_state_uuid       | 541248ce-56d0-11e9-b41b-3a9775d73ca7                  |
| wsrep_protocol_version       | 8                                                     |
| wsrep_provider_name          | Galera                                                |
| wsrep_provider_vendor        | Codership Oy <info@codership.com>                     |
| wsrep_provider_version       | 25.3.23(r3789)                                        |
| wsrep_ready                  | ON                                                    |
| wsrep_received               | 20                                                    |
| wsrep_received_bytes         | 3651                                                  |
| wsrep_repl_data_bytes        | 0                                                     |
| wsrep_repl_keys              | 0                                                     |
| wsrep_repl_keys_bytes        | 0                                                     |
| wsrep_repl_other_bytes       | 0                                                     |
| wsrep_replicated             | 0                                                     |
| wsrep_replicated_bytes       | 0                                                     |
| wsrep_thread_count           | 2                                                     |
+------------------------------+-------------------------------------------------------+
58 rows in set (0.002 sec)

###查看集群主機IP
 show status like "wsrep_incoming_addresses";

在其中一個節點操作創建數據庫,再另外一個節點查看是否同步


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM