mysql集群Galera Cluster配置

2021-09-08 16:51:00 字數 3496 閱讀 2170

開啟資料來源配置檔案

vim /etc/apt/sources.list
修改更新源 

# deb cdrom:[ubuntu 16.04 lts _xenial xerus_ - release amd64 (20160420.1)]/ xenial main restricted

deb-src xenial main restricted #added by software-properties

deb xenial main restricted

deb-src xenial main restricted multiverse universe #added by software-properties

deb xenial-updates main restricted

deb-src xenial-updates main restricted multiverse universe #added by software-properties

deb xenial universe

deb xenial-updates universe

deb xenial multiverse

deb xenial-updates multiverse

deb xenial-backports main restricted universe multiverse

deb-src xenial-backports main restricted universe multiverse #added by software-properties

deb xenial partner

deb-src xenial partner

deb xenial-security main restricted

deb-src xenial-security main restricted multiverse universe #added by software-properties

deb xenial-security universe

deb xenial-security multiverse

安裝依賴

apt-get install python-software-properties  

apt-get install software-properties-common

新增gunpg key

apt-key adv --keyserver keyserver.ubuntu.com --recv bc19ddba
配置ubuntu下galera源

cd /etc/apt/sources.list.d

touch galera.list

在galera.list檔案中新增url

# codership repository (galera cluster for mysql)

deb xenial main

deb xenial main

cd /etc/apt/preferences.d

touch  galera.pref

在galera.pref 檔案中新增如下配置

package: *  

pin: origin releases.galeracluster.com  

pin-priority: 1001

更新源

apt-get update
apt-get install galera-3 galera-arbitrator-3 mysql-wsrep-5.7
進入mysql授權

grant all privileges on *.* to 'root'@'192.168.60.131' identified by '123456' with grant option;

grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;

新增角色

create user 'wsrep'@'%' identified by '123456';
讓它生效

flush privileges;
配置節點

在my.cnf新增

[mysqld]

bind-address = 0.0.0.0

binlog_format=row

default-storage-engine=innodb

innodb_autoinc_lock_mode=2

innodb_flush_log_at_trx_commit=0

innodb_buffer_pool_size=122m

innodb-log-file-size = 100m

wsrep_provider=/usr/lib/libgalera_smm.so

wsrep_provider_options="gcache.size=300m; gcache.page_size=1g"

wsrep_cluster_name="galeracluster"

wsrep_cluster_address="gcomm:"

wsrep_sst_method=rsync

wsrep_sst_auth=wsrep:123456

關閉mysql服務

service mysql stop
啟動mysql服務

service mysql start --wsrep-new-cluster(主節點啟動需要加這個引數)
其他直接啟動

進入mysql檢視集群

show status like 'wsrep%';
如果主節點服務停止需要重啟的話,找到/var/lib/mysql/grastate.dat

將safe_to_bootstrap: 0 ->1

再重啟其他節點,將重新加入集群

建立表及新增資料方便檢視結果

create database clustertest;

create table clustertest.mycluster ( id int not null auto_increment, name varchar(50), ipaddress varchar(20), primary key(id));

insert into clustertest.mycluster (name, ipaddress) values ("db1", "1.1.1.1");

select * from clustertest.mycluster;

mysql 集群 自動分片 Mysql集群

特性 高可用性 主伺服器故障後可切換到備用伺服器 可伸縮性 方便增加db 負載均衡 支援將某資料切換到另外的伺服器 mysqlcluster mysql cluster 是mysql官方集群部署方案,通過自動分片支援讀寫擴充套件,通過實時備份冗餘資料,是可用性最高的方案,聲稱可做到99.999 的可...

mysql集群安裝面板 mysql集群安裝指南

環境說明 系統環境 centos 6.5 mini 64bit 軟體版本 mysql cluster advanced 7.3.7 linux glibc2.5 x86 64.tar.gz mgm 192.168.100.211 ndbd1 192.168.100.212 ndbd2 192.168...

mysql集群最小配置 mysql集群安裝配置

groupadd mysql useradd mysql g mysql mv mysql cluster gpl 7.0.8a linux i686 glibc23.tar.gz usr local cd usr local tar zxvf mysql cluster gpl 7.0.8a li...