對(duì)于大多數(shù)網(wǎng)站來說,數(shù)據(jù)是最為重要的部分。而MySQL MM(Master-Master)就是一款非常流行的數(shù)據(jù)庫(kù)架構(gòu),其最大的特點(diǎn)是可以實(shí)現(xiàn)多個(gè)MySQL服務(wù)器之間的數(shù)據(jù)同步。下面,我們就來介紹一下如何搭建MySQL MM。
1.安裝MySQL服務(wù)器
sudo apt-get install mysql-server
2.配置MySQL的主從復(fù)制
在主庫(kù)中,編輯MySQL的配置文件,添加以下內(nèi)容: server-id=1 log-bin=/var/log/mysql/mysql-bin.log expire_logs_days=10 max_binlog_size=100M binlog-do-db=mydb binlog-ignore-db=mysql binlog-ignore-db=sys 在從庫(kù)中,編輯MySQL的配置文件,添加以下內(nèi)容: server-id=2 relay-log=/var/log/mysql/mysql-relay-bin.log relay-log-index=/var/log/mysql/mysql-relay-bin.index log-slave-updates=1 read-only=1 replicate-do-db=mydb replicate-ignore-db=mysql replicate-ignore-db=sys
3.安裝和配置MySQL Proxy
sudo apt-get install mysql-proxy 編輯MySQL Proxy的配置文件,添加以下內(nèi)容: [mysql-proxy] log-file=/var/log/mysql-proxy.log daemon=true [proxy-backend-server-1] hostname=127.0.0.1 port=3306 weight=1 [proxy-backend-server-2] hostname=127.0.0.1 port=3307 weight=1 [proxy-route-1] proxy-backend-server-name=proxy-backend-server-1 proxy-read-only-backend-server=false proxy-backend-addresses=127.0.0.1:3306 [proxy-route-2] proxy-backend-server-name=proxy-backend-server-2 proxy-read-only-backend-server=false proxy-backend-addresses=127.0.0.1:3307 [admin-backend-server-1] hostname=127.0.0.1 port=4040 [admin-frontend] admin-address=127.0.0.1:4040
4.啟動(dòng)MySQL MM
sudo service mysql start mysql -uroot -p -e "GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'user'@'%' IDENTIFIED BY 'pass'; FLUSH PRIVILEGES;" mysql -uroot -p -e "CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='user', MASTER_PASSWORD='pass', MASTER_PORT=3307, MASTER_AUTO_POSITION=1; START SLAVE;" mysql-proxy --defaults-file=/etc/mysql-proxy.cnf
5.驗(yàn)證MySQL MM
在主庫(kù)中,創(chuàng)建一個(gè)數(shù)據(jù)庫(kù)和表,在從庫(kù)中查看是否同步成功: CREATE DATABASE mydb; CREATE TABLE mytable (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id), data VARCHAR(100)); INSERT INTO mytable (data) VALUES ('hello'); 在從庫(kù)中執(zhí)行: SELECT * FROM mydb.mytable; 如果能夠查詢到之前插入的數(shù)據(jù),則數(shù)據(jù)庫(kù)同步成功。
上一篇mysql mobi
下一篇mysql mof