mysql集群Galera Cluster配置

本文详细介绍在Ubuntu系统上配置Galera集群的过程,包括数据源配置、依赖安装、添加GPG密钥、配置Galera源、下载安装MySQL、MySQL授权、配置节点、服务启停步骤及集群状态检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

打开数据源配置文件

vim /etc/apt/sources.list

修改更新源 

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ 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 http://releases.galeracluster.com/mysql-wsrep-5.7/ubuntu xenial main
deb http://releases.galeracluster.com/galera-3/ubuntu xenial main

cd /etc/apt/preferences.d
touch  galera.pref
在galera.pref 文件中添加如下配置

Package: *  
Pin: origin releases.galeracluster.com  
Pin-Priority: 1001

更新源

apt-get update

下载mysql

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://192.168.60.130"
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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值