MYSQL8集群是在MYSQL的基礎上實現了高可用性、負載均衡以及數據的備份與恢復的一種方法。下面是MYSQL8集群搭建過程:
1. 安裝MA安裝包
wget http://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm rpm -ivh mysql80-community-release-el7-3.noarch.rpm yum install mysql-connector-java mysql-shell mysql-router -y
2. 安裝mysql-server
yum install mysql-server -y systemctl start mysqld systemctl enable mysqld
3. 創建mysql用戶和密碼
mysql -uroot -p CREATE USER 'mysql'@'%' IDENTIFIED BY 'mysql'; GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'%'; FLUSH PRIVILEGES; quit
4. 安裝ndb包
wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.6/mysql-cluster-gpl-7.6.9-linux-glibc2.12-x86_64.tar.gz tar zxvf mysql-cluster-gpl-7.6.9-linux-glibc2.12-x86_64.tar.gz
5. 創建MYSQL Cluster配置文件
[ndbd default] noofreplicas=2 datadir=/usr/local/mysql/data [ndb_mgmd] hostname=192.168.1.1 datadir=/usr/local/mysql/data id=1 [ndbd] hostname=192.168.1.2 datadir=/usr/local/mysql/data id=2 [ndbd] hostname=192.168.1.3 datadir=/usr/local/mysql/data id=3 [mysqld] hostname=192.168.1.4
6. 開始安裝MYSQL Cluster
cd mysql-cluster-gpl-7.6.9-linux-glibc2.12-x86_64 ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data ./bin/ndb_mgmd -f /usr/local/mysql-cluster/config.ini --initial --configdir=/usr/local/mysql-cluster ./bin/ndbd --initial --my-node-id=2 --config-dir=/usr/local/mysql-cluster ./bin/ndbd --initial --my-node-id=3 --config-dir=/usr/local/mysql-cluster ./bin/mysql -uroot -p CREATE DATABASE mysqlcluster; USE mysqlcluster; CREATE TABLE test_mysql_cluster ( id INT NOT NULL PRIMARY KEY, name VARCHAR(50)); quit
7. 啟動MYSQL Cluster
./bin/mysqld --defaults-file=/usr/local/mysql/mysql-cluster/config.ini --ndbcluster --ndb-connectstring=192.168.1.1:1186
至此,MYSQL8集群搭建完成。以上是簡單的搭建過程,搭建過程中遇到問題,可以到官網進行查找解決方案。