1.架構確認
mysql router : 實踐單一路口多節點分流或讀寫分離
2.建立主機
192.168.1.60 myrouter
innodb cluster
192.168.1.61 innodb-node1
192.168.1.62 innodb-node2
192.168.1.63 innodb-node3
3.環境準備
3.1 安裝 mysql router
匯入官方的 mysql apt repository
https://dev.mysql.com/downloads/repo/apt/
wget https://dev.mysql.com/get/mysql-apt-config_0.8.22-1_all.deb && \
sudo dpkg -i ./mysql-apt-config_0.8.22-1_all.deb && \
sudo apt update && \
sudo apt install -y mysql-router
3.2 建立 router
sudo mysqlrouter --bootstrap root@innodb-node1:3306 -d myrouter --user=root --report-host myrouter
### 輸入完 Mysql 的 password 後會自動讀取 MGR 的配置然後寫入 conf 裡面
Please enter MySQL password for root:
# Bootstrapping MySQL Router instance at '/etc/mysqlrouter/myrouter'...
- Creating account(s) (only those that are needed, if any)
- Verifying account (using it to run SQL queries that would be run by Router)
- Storing account in keyring
- Adjusting permissions of generated files
- Creating configuration /etc/mysqlrouter/myrouter/mysqlrouter.conf
# MySQL Router configured for the InnoDB Cluster 'innodbcluster'
After this MySQL Router has been started with the generated configuration
$ mysqlrouter -c /etc/mysqlrouter/myrouter/mysqlrouter.conf
InnoDB Cluster 'innodbcluster' can be reached by connecting to:
## MySQL Classic protocol
- Read/Write Connections: localhost:6446
- Read/Only Connections: localhost:6447
## MySQL X protocol
- Read/Write Connections: localhost:6448
- Read/Only Connections: localhost:6449
4.啟動MySQL Router
sudo sh /etc/mysqlrouter/myrouter/start.sh