galera搭建高可用

2018-01-14  本文已影响67人  Sihanouk

1.galera

快速搭建

使用软件版本3-25.3.22-2.el7.x86_64
galera软件http://releases.galeracluster.com/galera-3/centos/7/x86_64/galera-3-25.3.22-2.el7.x86_64.rpm
mysql依赖包http://releases.galeracluster.com/mysql-wsrep-5.7/centos/7/x86_64/

#安装过程中可能出现各种依赖问题,根据拋错把需要依赖的软件装上即可
#如果有安装过mysql-libs包或mariadb会出错,需要先卸载yum remove mysql-libs -y
rpm -ivh galera-3-25.3.22-2.el7.x86_64.rpm
rpm -ivh mysql-wsrep-common-5.7-5.7.20-25.13.el7.x86_64.rpm
rpm -ivh mysql-wsrep-libs-5.7-5.7.20-25.13.el7.x86_64.rpm
rpm -ivh mysql-wsrep-libs-compat-5.7-5.7.20-25.13.el7.x86_64.rpm
rpm -ivh mysql-wsrep-devel-5.7-5.7.20-25.13.el7.x86_64.rpm
rpm -ivh mysql-wsrep-client-5.7-5.7.20-25.13.el7.x86_64.rpm
rpm -ivh mysql-wsrep-server-5.7-5.7.20-25.13.el7.x86_64.rpm
rpm -ivh mysql-wsrep-5.7-5.7.20-25.13.el7.x86_64.rpm
rpm -ivh mysql-wsrep-test-5.7-5.7.20-25.13.el7.x86_64.rpm

安装xtrabackup

rpm -Uvh https://www.percona.com/redir/downloads/percona-release/redhat/percona-release-0.1-4.noarch.rpm
yum install percona-xtrabackup -y

galera支持三种同步方式,下图是官网对三种同步方式对比:

Method Speed Blocks Donor Available on Live Node Type DB Root Access
mysqldump Slow Blocks Available Logical Donor and Joiner
rsync Fastest Blocks Unavailable Physical None
xtrabackup Fast Briefly Unavailable Physical Donor only

来源:http://galeracluster.com/documentation-webpages/sst.html

创建mysql实例

# 确保mysqld服务停止,此处自己指定实例(提示:CentOS7中使用systemctl管理mysql多实例)
mysqld --initialize-insecure --user=mysql --datadir=/var/lib/mysqld@3306
# 启动服务,修改初始密码
set password='admin123';
# 创建用于同步的账户
GRANT ALL PRIVILEGES on *.* to sst@'%' IDENTIFIED BY 'admin123';
flush privileges;

# my.cnf配置文件
[mysqld@3306]
datadir = /var/lib/mysqld@3306
socket = /var/lib/mysqld@3306/mysqld@3306.sock
port = 3306
pid-file = /var/run/mysqld@3306/mysqld@3306.pid
log-error = /var/log/mysqld.log
binlog_format=ROW
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
skip-name-resolve = 1
log-bin = mysql-bin
log-slave-updates = 0
relay_log_recovery = 1
relay-log = mysqld@3320-relay-bin
user = mysql
language = /usr/share/mysql/english
default-storage-engine = InnoDB
character-set-server = UTF8
server-id = 1

wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_sst_method=xtrabackup
wsrep_sst_auth=root:admin123
wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
# 如果是启动第一台的,该行为wsrep_cluster_address=gcomm:// ,且按照systemctl正常方式启动mysql实例即可
wsrep_cluster_address=gcomm://
wsrep_cluster_name='galera_cluster'
wsrep_node_address='192.168.184.50'
wsrep_node_name='db1'
# 设置好my.cnf后,重启mysqld@3306
注意:mysqld.log日志中如果出现错误Failed to read 'ready <addr>' from: wsrep_sst_xtrabackup --role 'joiner
查看配置的同步账户是否有远程执行 相关 命令的权限

# 第二个节点
wsrep_provider=/usr/lib64/galera-3/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=300M"
wsrep_cluster_address=gcomm://192.168.184.50
wsrep_cluster_name='galera_cluster'
wsrep_node_address='192.168.184.52'
wsrep_node_name='db2'

确认galera启动成功 mysql>show status like 'wsrep_cluster_size';
或者 mysql -usst -padmin123 -P3306 -h192.168.184.50 -e "SHOW STATUS LIKE 'wsrep_cluster_size'"
查看galera状态 mysql> show status like 'wsrep%';

方案分析

# 开启一个数据库防火墙panic-on模式,模拟双节点网络不通,在另一个节点上写入
mysql> create database test_error;
ERROR 1047 (08S01): WSREP has not yet prepared node for application use
# 重置galera集群状态,再写入。当关闭panic-on模式后,两个节点能同步数据到一直状态
mysql> set global wsrep_provider_options='pc.bootstrap=YES';
Query OK, 0 rows affected (0.00 sec)
mysql> create database test_error;
Query OK, 1 row affected (0.05 sec)
# 如果在开启panic-on模式后,两个节点都写入了数据,关闭panic-on模式后不能同步数据
上一篇下一篇

猜你喜欢

热点阅读