Mariadb-Galera集群杂记
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mariadb-Galera集群杂记相关的知识,希望对你有一定的参考价值。
Galera Cluster
Galera Cluster
1、需要专门下载支持Galera-Cluster支持的mariadb分支
1.1
需要准备三个节点;
1.2 配置时间同步
[[email protected] ~]# ntpdate s2c.time.edu.cn
[[email protected] ~]# ntpdate s2c.time.edu.cn
[[email protected] ~]# ntpdate s2c.time.edu.cn
配置yum源:
[[email protected] galera_cluster]# vim /etc/yum.repos.d/galera.repo
[galera]
name=Galera Cluster from MariaDB
baseurl=http://10.201.106.1:8080/galera_cluster/
enabled=1
gpgcheck=0
[[email protected] galera_cluster]# yum list | grep Gale
MariaDB-Galera-server.x86_64 5.5.46-1.el7.centos galera
MariaDB-Galera-test.x86_64 5.5.46-1.el7.centos galera
2、清除之前的mariadb
yum remove mariadb-server
yum remove mariadb
3、安装
3.1 安装Galera
[[email protected] galera_cluster]# yum install MariaDB-Galera-server
[[email protected] galera_cluster]# yum install MariaDB-Galera-server
[[email protected] galera_cluster]# yum install MariaDB-Galera-server
3.2 查看安装生成文件
[[email protected] ~]# rpm -ql galera | grep -i smm.so
/usr/lib64/galera/libgalera_smm.so
4、配置Galera-server
4.0
[[email protected] ~]# rpm -ql galera | grep -i smm.so
/usr/lib64/galera/libgalera_smm.so
4.1 配置
[[email protected] ~]# vim /etc/my.cnf.d/server.cnf
[galera]
# Mandatory settings
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://10.201.106.131,10.201.106.132,10.201.106.133"
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0
wsrep_cluster_name=‘mycluster‘
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
4.2 复制文件到节点2,3
[[email protected] ~]# scp /etc/my.cnf.d/server.cnf master2:/etc/my.cnf.d/
server.cnf 100% 1140 1.1KB/s 00:00
[[email protected] ~]# scp /etc/my.cnf.d/server.cnf master3:/etc/my.cnf.d/
server.cnf 100% 1140 1.1KB/s 00:00
[[email protected] ~]#
5、启动
5.1 初始化启动服务
[[email protected] ~]# /etc/rc.d/init.d/mysql start --wsrep-new-cluster
Starting MySQL...... SUCCESS!
节点2,3启动
[[email protected] galera_cluster]# service mysql start
Starting MySQL.....SST in progress, setting sleep higher. SUCCESS!
[[email protected] galera_cluster]#
[[email protected] galera_cluster]# service mysql start
Starting MySQL.....SST in progress, setting sleep higher. SUCCESS!
[[email protected] galera_cluster]#
5.2 测试创建
节点1
MariaDB [(none)]> CREATE DATABASE mydb;
节点3
MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mydb |
节点2
MariaDB [mydb]> CREATE TABLE tb1(id int,name char(10));
节点1:
MariaDB [mydb]> DESC tb1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | char(10) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
6、演示同时插入数据
6.1
节点1
MariaDB [mydb]> CREATE TABLE tb2(id int UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,name CHAR(30));
MariaDB [mydb]> INSERT INTO tb2 (name) VALUES(‘hi‘),(‘hello‘);
节点2
MariaDB [mydb]> SELECT * FROM tb2;
+----+-------+
| id | name |
+----+-------+
| 1 | hi |
| 4 | hello |
MariaDB [mydb]> INSERT INTO tb2(name) VALUES (‘to‘),(‘from‘);
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
MariaDB [mydb]> SELECT * FROM tb2;
+----+-------+
| id | name |
+----+-------+
| 1 | hi |
| 4 | hello |
| 5 | to |
| 8 | from |
+----+-------+
插入ID:找一个全局惟一ID生成器,可以专门找一台服务器生成ID,不做其他事情。
以上是关于Mariadb-Galera集群杂记的主要内容,如果未能解决你的问题,请参考以下文章