注:部署双实例前,首先需要部署单实例,单实例部署详情如下:
https://www.cnblogs.com/wangqiner/p/9081002.html
1、如已经安装完成单实例,需要先停止单实例运行,接下来进行多实例部署
/etc/init.d/mysqld stopchkconfig mysqld off
2、已经制作好多实例配置文件及启动文件,以下为下载地址:
3、上传data.tar.gz到根目录,然后tar解压
[root@centos /]# tar xf data.tar.gz
[root@centos /]# tree /data
data
├── 3306
│ ├── my.cnf
│ └── mysql
└── 3307
├── my.cnf
└── mysql
4、授权所有者、所属组及文件权限并查看
chown -R mysql.mysql /data/
[root@centos /]# find /data -name mysql|xargs ls -l
-rw-r--r-- 1 root root 1345 Apr 26 2017 /home/data/3306/mysql
-rw-r--r-- 1 root root 1345 Apr 26 2017 /home/data/3307/mysql
[root@centos home]# find /home/data -name mysql|xargs chmod 700
[root@centos home]# find /home/data -name mysql|xargs ls -l
-rwx------ 1 root root 1345 Apr 26 2017 /home/data/3306/mysql
-rwx------ 1 root root 1345 Apr 26 2017 /home/data/3307/mysql
[root@centos home]#
5、进入MySQL初始化文件目录
cd /application/mysql/scripts
6、初始化3306,3307 两个实例(为了生成MySQL data下数据关联及文件)
./mysql_install_db --defaults-file=/data/3306/my.cnf --basedir=/application/mysql/ --datadir=/data/3306/data --user=mysql------------分别执行--------------./mysql_install_db --defaults-file=/data/3307/my.cnf --basedir=/application/mysql/ --datadir=/data/3307/data --user=mysql
7、环境变量设置,如已经配置,可跳过
echo ‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profilesource /etc/profile
8、启动前为保证没有错误文件的报错,提前创建错误日志文件及授权所有者及所属组
touch /data/3306/oldboy_3306.errtouch /data/3307/oldboy_3307.errchown mysql.mysql /data/3306/oldboy_3306.errchown mysql.mysql /data/3307/oldboy_3307.err
9、启动MySQL多实例
---命令---
/data/3306/mysql start/data/3307/mysql start
---展示---
[root@centos data]# /data/3306/mysql start
Starting MySQL...
[root@centos data]# /data/3307/mysql start
Starting MySQL...
10、查看MySQL端口是否正常启动
[root@centos data]# ss -lntupNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp LISTEN 0 600 :::3306 :::* users:(("mysqld",36610,11))tcp LISTEN 0 600 :::3307 :::* users:(("mysqld",37337,11))
11、分别登录进入MySQL多实例
---进入命令---
mysql -S /data/3306/mysql.sock
mysql -S /data/3307/mysql.sock
----展示-----
[root@centos data]# mysql -S /data/3306/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.36 Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec)mysql> exitBye[root@centos data]# mysql -S /data/3307/mysql.sockWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.36 Source distributionCopyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.01 sec)mysql> exitBye
完成以上操作,MySQL多实例就已经部署完成!
以下是增加一台实例思路
1、复制根目录下/data/3306 改名为 /data/3308
2、进行对比多实例MySQL实例下的my.cnf 和mysql 启动文件,
唯一的区别在于实例名称的不同(如3306,3307,3308),以及server id 的不同(任意数不相同即可)
3、使用sed -i "s#3306#3308#g" /data/3308/my* 命令进行替换,如果不太明白,可以打开复制后的3308目录中的配置文件及启动文件,一一修改为3308 即可;
4、修改完成后初始化实例3308 ,可根据上述初始化命令将其他实例名称改为3308即可;
5、创建错误日志文件到实例3308下;
6、授权实例3308 ,更改所有者、所属组及权限;
7、启动多实例3308 /data/3308/mysql start;
8、查看端口是否启动。