MySQL多實例安裝部署
解壓 MySQL 5.7 二進制包到指定目錄
[root@MySQL ~]# tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz -C /usr/local/
創建 MySQL 軟鏈接
[root@MySQL ~]#mv /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql
創建 MySQL 用戶
[root@MySQL ~]#groupadd -r mysql
[root@MySQL ~]# useradd -r -g mysql -s /bin/false -M mysql
在 MySQL 二進制包目錄中創建 mysql-files 目錄 [MySQL 數據導入/導出數據專放目錄]
mkdir: created directory `/usr/local/mysql/mysql-files‘
創建多實例數據目錄
[root@MySQL ~]# mkdir -vp /data/mysql_data{1..4}
mkdir: created directory /data‘ <br/>mkdir: created directory
/data/mysql_data1‘
mkdir: created directory /data/mysql_data2‘ <br/>mkdir: created directory
mkdir: created directory `/data/mysql_data4‘
修改 MySQL 二進制包目錄的所屬用戶與所屬組
1 [root@MySQL ~]# chown root.mysql -R /usr/local/mysql
修改 MySQL 多實例數據目錄與 數據導入/導出專放目錄的所屬用戶與所屬組
[root@MySQL ~]# chown mysql.mysql -R /usr/local/mysql/mysql-files /data/mysql_data{1..4}
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld
log = /tmp/mysql_multi.log
[mysqld1]
# 設置數據目錄 [多實例中一定要不同]
datadir = /data/mysql_data1
# 設置sock存放文件名 [多實例中一定要不同]
socket = /tmp/mysql.sock1
# 設置監聽開放端口 [多實例中一定要不同]
port = 3306
# 設置運行用戶
user = mysql
# 關閉監控
performance_schema = off
# 設置innodb 緩存大小
innodb_buffer_pool_size = 32M
# 設置監聽IP地址
bind_address = 0.0.0.0
# 關閉DNS 反向解析
skip-name-resolve = 0 **
[mysqld2]
datadir = /data/mysql_data2
socket = /tmp/mysql.sock2
port = 3307
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0
[mysqld3]
datadir = /data/mysql_data3
socket = /tmp/mysql.sock3
port = 3308
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0
[mysqld4]
datadir = /data/mysql_data4
socket = /tmp/mysql.sock4
port = 3309
user = mysql
performance_schema = off
innodb_buffer_pool_size = 32M
bind_address = 0.0.0.0
skip-name-resolve = 0
-
初始化各個實例 [ 初始化完成後會自帶隨機密碼在輸出日誌中 ]
[root@MySQL ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data1
[root@MySQL ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data2
[root@MySQL ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3
[root@MySQL ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data4 - 各實例開啟 SSL 連接
[root@MySQL ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data1
[root@MySQL ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data2
[root@MySQL ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data3
[root@MySQL ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql_data4
*修改環境變量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
-
復制多實例腳本到服務管理目錄下 [ /etc/init.d/ ]
[root@MySQL ~]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi -
添加腳本執行權限
[root@MySQL ~]# chmod +x /etc/init.d/mysqld_multi - 添加進service服務管理
[root@MySQL ~]# chkconfig --add mysqld_multi
- 啟動測試
- 查個多實例狀態
[root@MySQL ~]# /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running
MySQL server from group: mysqld4 is not running
- 查個多實例狀態
-
啟動多實例
[root@MySQL ~]# /etc/init.d/mysqld_multi start -
查看多實例狀態
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
MySQL server from group: mysqld4 is running - 查看實例監聽端口
[root@MySQL ~]# netstat -lntp | grep mysqld
tcp 0 0 0.0.0.0:3306 0.0.0.0: LISTEN 2673/mysqld
tcp 0 0 0.0.0.0:3307 0.0.0.0: LISTEN 2676/mysqld
tcp 0 0 0.0.0.0:3308 0.0.0.0: LISTEN 2679/mysqld
tcp 0 0 0.0.0.0:3309 0.0.0.0: LISTEN 2682/mysqld
- 連接測試
MySQL多實例安裝部署