在CentOS 7.3下通过Galera搭建Mysql 5.6集群,在此将操作记录下来,亲测通过。
在3台服务器分别执行以下命令:
# yum install gcc gcc-c++ boost-devel scons check-devel openssl-devel
# yum install rsync libaio
# yum install cmake
# yum install ncurses-devel bison
# yum -y install lsof net-tools perl socat openssl
# yum -y install autoconf
在3台服务器分别执行以下命令:
# rpm -qa |grep mariadb
# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
在3台服务器分别执行以下命令:
# tar -zxvf mysql-wsrep-5.6.30-25.15.tar.gz
# mv mysql-wsrep-5.6.30-25.15 mysql-wsrep-5.6.30
# mv mysql-wsrep-5.6.30 /usr/local
# cd /usr/local/mysql-wsrep-5.6.30
# cmake -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW=ON ./
# make
# make install
在3台服务器分别执行以下命令:
# tar -zxvf scons-2.4.1.tar.gz
# cd scons-2.4.1
# python setup.py install
在3台服务器分别执行以下命令:
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
在3台服务器分别执行以下命令:
# tar -zxvf galera-3-25.3.16.tar.gz
# mv galera-3-25.3.16 /usr/local
# cd /usr/local/galera-3-25.3.16
# scons
# cp garb/garbd /usr/local/mysql/bin/
# cp libgalera_smm.so /usr/local/mysql/lib/plugin/
在3台服务器分别执行以下命令:
# cd /usr/local.mysql
# groupadd mysql
# useradd -r -g mysql mysql
# chown -R mysql:mysql .
# chown -R root .
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql
在3台服务器分别执行以下命令:
# cd /usr/local/mysql
# ./scripts/mysql_install_db --no-defaults --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
在3台服务器分别执行以下命令:
# cd /usr/local/mysql
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# mkdir -p /var/lib/mysql
# chown -R mysql:mysql /var/lib/mysql
# mkdir -p /app/data/mysql_log
# chown -R mysql:mysql /app/data/mysql_log
# mkdir -p /app/data/mysql_binlog
# chown -R mysql:mysql /app/data/mysql_binlog
编辑配置文件,注意以下几点:
执行以下命令:
# vim /etc/my.cnf
//编辑内容如下:
[mysqld]
wsrep_node_name = node1
wsrep_provider = /usr/local/mysql/lib/plugin/libgalera_smm.so
wsrep_sst_method = rsync
# wsrep_sst_auth = root:1qaz2wsx
wsrep_cluster_address = gcomm://
port = 3306
socket = /var/lib/mysql/mysql.sock
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql
general_log = ON
general_log_file = /app/data/mysql_log/mysql.log
log-error = /app/data/mysql_log/mysql_error.log
max_binlog_size = 200M
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
innodb_locks_unsafe_for_binlog = 1
innodb_flush_log_at_trx_commit = 0
innodb_doublewrite = 0
innodb_file_per_table = 1
binlog_format = ROW
log-bin = /app/data/mysql_binlog/mysql-bin
server-id = 101
relay-log = mysql-relay-bin
log-slave-updates = 1
执行以下命令:
# vim /etc/my.cnf
//编辑内容如下:
[mysqld]
wsrep_node_name = node2
wsrep_provider = /usr/local/mysql/lib/plugin/libgalera_smm.so
wsrep_sst_method = rsync
# wsrep_sst_auth = root:1qaz2wsx
wsrep_cluster_address = gcomm://mysql01的IP:4567
port = 3306
socket = /var/lib/mysql/mysql.sock
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql
general_log = ON
general_log_file = /app/data/mysql_log/mysql.log
log-error = /app/data/mysql_log/mysql_error.log
max_binlog_size = 200M
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
innodb_locks_unsafe_for_binlog = 1
innodb_flush_log_at_trx_commit = 0
innodb_doublewrite = 0
innodb_file_per_table = 1
binlog_format = ROW
log-bin = /app/data/mysql_binlog/mysql-bin
server-id = 102
relay-log = mysql-relay-bin
log-slave-updates = 1
执行以下命令:
# vim /etc/my.cnf
//编辑内容如下:
[mysqld]
wsrep_node_name = node3
wsrep_provider = /usr/local/mysql/lib/plugin/libgalera_smm.so
wsrep_sst_method = rsync
# wsrep_sst_auth = root:1qaz2wsx
wsrep_cluster_address = gcomm://mysql01的IP:4567,mysql02的IP:4567
port = 3306
socket = /var/lib/mysql/mysql.sock
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql
general_log = ON
general_log_file = /app/data/mysql_log/mysql.log
log-error = /app/data/mysql_log/mysql_error.log
max_binlog_size = 200M
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
innodb_locks_unsafe_for_binlog = 1
innodb_flush_log_at_trx_commit = 0
innodb_doublewrite = 0
innodb_file_per_table = 1
binlog_format = ROW
log-bin = /app/data/mysql_binlog/mysql-bin
server-id = 103
relay-log = mysql-relay-bin
log-slave-updates = 1
# service mysql restart
# service mysql restart
# service mysql restart
# vim /etc/my.cnf
//编辑wsrep_cluster_address字段值,内容如下:
wsrep_cluster_address = gcomm://mysql01的IP:4567,mysql03的IP:4567
# service mysql restart
# vim /etc/my.cnf
//编辑wsrep_cluster_address字段值,内容如下:
wsrep_cluster_address = gcomm://mysql02的IP:4567,mysql03的IP:4567
# service mysql restart
mysql默认安装后的root用户,密码默认为空。
在3台服务器分别执行以下命令:
# cd /usr/local/mysql/bin
# ./mysql -h127.0.0.1 -uroot -p
//mysql默认安装后的root用户,密码默认为空,因此直接回车
在任意一个节点执行以下命令:
# cd /usr/local/mysql/bin
# ./mysqladmin -h127.0.0.1 -uroot -p password 111111
在其他节点执行以下命令:
# cd /usr/local/mysql/bin
# ./mysql -h127.0.0.1 -uroot -p111111
在任意节点执行以下命令:
# cd /usr/local/mysql/bin
# ./mysql -h127.0.0.1 -uroot -p111111
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '111111' WITH GRANT OPTION;
mysql> flush privileges;