2018年11月27日 星期二

電腦-Linux-MariaDB/MySQL 安裝 Galera Cluster

電腦-Linux-MariaDB/MySQL 安裝 Galera Cluster

1.主機環境:
CentOS 7.x 最小安裝

/etc/hosts
db01:192.168.11.101
db02:192.168.11.102

firewalld開啟相關服務 tcp:3306、4444、4567、4568
firewall-cmd --add-service=mysql
firewall-cmd --add-port=4444/tcp
firewall-cmd --add-port=4567/tcp
firewall-cmd --add-port=4568/tcp
firewall-cmd --permanent --add-service=mysql
firewall-cmd --permanent --add-port=4444/tcp
firewall-cmd --permanent --add-port=4567/tcp
firewall-cmd --permanent --add-port=4568/tcp


關閉selinux
sed -i 's,^SELINUX=enforcing,SELINUX=disabled,g' /etc/selinux/config

安裝epel-release
yum install epel-release

2.MariaDB 安裝 (MariaDB 10.2)
vim /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

yum install MariaDB-server MariaDB-client percona-xtrabackup

rpm -qa|grep MariaDB
MariaDB-compat-10.2.19-1.el6.x86_64
MariaDB-common-10.2.19-1.el6.x86_64
MariaDB-client-10.2.19-1.el6.x86_64
MariaDB-server-10.2.19-1.el6.x86_64



3.Galera Cluster設定
3-1.db1設定
啟動MariaDB
systemctl start mariadb.service

設定Galera Cluster 同步帳號
mysql -uroot -e "grant all privileges on *.* to 'wsrep'@'localhost' identified by 'wsrep';"
mysql -uroot -e "grant all privileges on *.* to 'wsrep'@'192.168.11.%' identified by 'wsrep';"

進行安全初始化及重設root
mysql_secure_installation
systemctl stop mariadb.service

開啟Galera Cluster 功能
vim /etc/my.cnf.d/server.cnf

[mysqld]
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
character-set-server = utf8
log-error = /var/log/mariadb/mariadb.log
log-bin = mysql-bin
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2

[galera]
wsrep_on=ON
wsrep_cluster_name="wsrep_cluster"
wsrep_cluster_address="gcomm://"
wsrep_node_name=db01
wsrep_node_address=192.168.11.101
wsrep_sst_auth=wsrep:wsrep
wsrep_sst_method=rsync

第一次啟動Galera Cluster
galera_new_cluster

檢查Cluster狀態
mysql -uroot -p -e "show status like 'wsrep_connected';"
wsrep_connected         ON
mysql -uroot -p -e "show status like 'wsrep_cluster_size';"
wsrep_cluster_size       1 

3-2.db2設定
啟動MariaDB
systemctl start mariadb.service

進行安全初始化及重設root
mysql_secure_installation
systemctl stop mariadb.service

vim /etc/my.cnf.d/server.cnf

[mysqld]
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
character-set-server = utf8
log-error = /var/log/mariadb/mariadb.log
log-bin = mysql-bin
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2

[galera]
wsrep_on=ON
wsrep_cluster_name="wsrep_cluster"
wsrep_cluster_address="gcomm://192.168.11.101"
wsrep_node_name=db02
wsrep_node_address=192.168.11.102
wsrep_sst_auth=wsrep:wsrep
wsrep_sst_method=rsync

重新啟動
systemctl restart mariadb.service

db1檢查Cluster狀態
mysql -uroot -p -e "show status like 'wsrep_cluster_size';"
wsrep_cluster_size       2



4.使用xtrabackup同步
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
yum install percona-xtrabackup
rpm -qa|grep percona

vim /etc/my.cnf.d/server.cnf
[galera]
wsrep_sst_method=xtrabackup-v2

systemctl restart mariadb.service

參考資料:
MARIADB GALERA CLUSTER- SOURCE INSTALLATION
Getting Started with MariaDB Galera and MariaDB MaxScale on CentOS
Galera Cluster for MySQL Multi-master Replication
CentOS 7 安裝 Percona XtraDB Cluster
CentOS7使用官方YUM源安裝Mariadb Galera集羣

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。