一、MySQL Galera介绍
MySQL/Galera是MySQL/InnoDB的多主集群,有以下特性:
1)同步复制
2)Active-active的多主拓扑结构
3)集群任意节点可以读和写
4)自动身份控制,失败节点自动脱离集群
5)自动节点接入
6)真正的基于”行”级别和ID检查的并行复制
7)无单点故障,易扩展
2、架构图
二、Galera Cluster安装
1、安装前的准备
1)需要至少三台mysql服务器,如果只有两台做cluster的话,一旦出现数据不一致的情况,就可能发生脑裂,需要一台仲裁服务器,如果直接三台做cluster的话,就不再需要仲裁。
2)如果是对现有环境做galera集群,需要对mysql现有表做检查,包括表,表引擎,是否无主键,是否有全文索引,是否有空间索引:
SELECT DISTINCT CONCAT(t.table_schema,‘.‘,t.table_name) as tbl, t.engine, IF(ISNULL(c.constraint_name),‘NOPK‘,‘‘) AS nopk, IF(s.index_type = ‘FULLTEXT‘,‘FULLTEXT‘,‘‘) as ftidx, IF(s.index_type = ‘SPATIAL‘,‘SPATIAL‘,‘‘) as gisidx FROM information_schema.tables AS t LEFT JOIN information_schema.key_column_usage AS c ON (t.table_schema = c.constraint_schema AND t.table_name = c.table_name AND c.constraint_name = ‘PRIMARY‘) LEFT JOIN information_schema.statistics AS s ON (t.table_schema = s.table_schema AND t.table_name = s.table_name AND s.index_type IN (‘FULLTEXT‘,‘SPATIAL‘)) WHERE t.table_schema NOT IN (‘information_schema‘,‘performance_schema‘,‘mysql‘) AND t.table_type = ‘BASE TABLE‘ AND (t.engine <> ‘InnoDB‘ OR c.constraint_name IS NULL OR s.index_type IN (‘FULLTEXT‘,‘SPATIAL‘)) ORDER BY t.table_schema,t.table_name;
2、实验环境:
操作系统:Centos6.5-X64
mysql1:172.16.5.156
mysql2:172.16.5.157
mysql3:172.16.5.158
3、安装相关依赖包:
yum groupinstall -y "Development Tools" "Server Platform Development"
4、安装含wsrep patch的mysql版本
yum install -y libaio-devel wget https://launchpad.net/codership-mysql/5.6/5.6.16-25.5/+download/mysql-5.6.16_wsrep_25.5-linux-x86_64.tar.gz tar xf mysql-5.6.16_wsrep_25.5-linux-x86_64.tar.gz mv mysql-5.6.16_wsrep_25.5-linux-x86_64 /usr/local/mysql useradd -s /sbin/nologin -M mysql mkdir /data/mydata ./scripts/mysql_install_db --no-defaults --datadir=/data/mydata --user=mysql chown -R mysql.mysql /data/mydata/ chown root.mysql /usr/local/mysql cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
5、安装galera复制插件
wget https://launchpad.net/galera/3.x/25.3.5/+download/galera-25.3.5-src.tar.gz tar xf galera-25.3.5-src.tar.gz cd galera-25.3.5-src scons cp garb/garbd /usr/local/mysql/bin cp libgalera_smm.so /usr/local/mysql/lib/plugin/
6、编辑mysql配置文件my.cnf
[mysqld] basedir = /usr/local/mysql datadir = /data/mydata port = 3306 server-id=101 socket = /tmp/mysql.sock pid-file=/data/mydata/mysql.pid sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES wsrep_node_name = mysql1 wsrep_provider = /usr/local/mysql/lib/plugin/libgalera_smm.so wsrep_sst_method = rsync #wsrep_sst_auth=sst:sstpass #使用sst的用户和密码,这里如果开启,需要在mysql上创建该用户,并授予其足够的权限 default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 innodb_locks_unsafe_for_binlog=1 innodb_flush_log_at_trx_commit=1 innodb_file_per_table=1 binlog_format=ROW log-bin=mysql-bin relay-log=mysql-relay-bin log-slave-updates=1
本文出自 “从心开始” 博客,请务必保留此出处http://hao360.blog.51cto.com/5820068/1672435
LVS/DR + KeepAlived+ Galera Cluster 实现mysql群集
原文地址:http://hao360.blog.51cto.com/5820068/1672435