三臺linux
一、配置yum源mysql
[root@localhost ~]# vim /etc/yum.repos.d/galera.repo [mysql] baseurl=https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-5.5.64/yum/centos7-amd64/ gpgcheck=0 enabled=1
二、安裝軟件linux
全部要實現galera的都須要安裝,MariaDB-Galera-server會自動把mariadb-server替換掉 [root@localhost ~]# yum -y install MariaDB-Galera-server
三、配置文件sql
[root@localhost ~]# vim /etc/my.cnf.d/server.cnf [galera] wsrep_provider=/usr/lib64/galera/libgalera_smm.so #庫文件路徑 wsrep_cluster_address="gcomm://192.168.2.6,192.168.2.16,192.168.2.16" #gcomm協議,集羣主機 binlog_format=row
四、同步配置文件數據庫
[root@localhost ~]# scp /etc/my.cnf.d/server.cnf 192.168.2.16:/etc/my.cnf.d/ [root@localhost ~]# scp /etc/my.cnf.d/server.cnf 192.168.2.26:/etc/my.cnf.d/
五、首次啓動,須要初始化集羣,在其中一個節點上執行,而後再正常啓動其餘節點vim
[root@localhost ~]# service mysql start --wsrep-new-cluster #(腳本啓動方法) Starting MariaDB.190509 23:16:39 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 190509 23:16:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql .... SUCCESS! [root@localhost ~]# service mysql start Starting MariaDB.190509 23:18:37 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 190509 23:18:37 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql ....SST in progress, setting sleep higher.. SUCCESS! root@localhost ~]# service mysql start Starting MariaDB.190509 23:19:07 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 190509 23:19:07 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql ...SST in progress, setting sleep higher. SUCCESS!
六、一臺機器執行安全腳本(會同步部分數據庫信息)centos
[root@localhost ~]# mysql_secure_installation
七、測試同步安全
主機1: MariaDB [(none)]> create database db1; 主機2: MariaDB [(none)]> show databases; 主機3: MariaDB [(none)]> show databases; 主機2: MariaDB [(none)]> create database db1; ERROR 1007 (HY000): Can't create database 'db1'; database exists 主機3: MariaDB [(none)]> create database db1; ERROR 1007 (HY000): Can't create database 'db1'; database exists 測試成功
八、查看集羣中相關係統變量和狀態變量bash
MariaDB [(none)]> show variables like 'wsrep_%'\G; MariaDB [(none)]> show status like 'wsrep_%'; MariaDB [(none)]> show status like 'wsrep_cluster_size';