MySQL--------多版本多实例混合部署

本文涉及的产品
RDS MySQL DuckDB 分析主实例,集群系列 4核8GB
RDS AI 助手,专业版
简介:

1. 背景

  * MySQL数据库的集中化运维,可以通过在一台服务器上,部署运行多个MySQL服务进程,通过不同的socket监听不同的服务端口来提供各自的服务。各个实例之间是相互独立的,每个实例的datadir, port, socket, pid都是不同的。

  * 网上多实例一般通过实例版本相同实现,此次以不同版本来实现多实例部署(5.5、5.6、5.7)。


2. 多实例特点

  * 有效利用服务器资源,当单个服务器资源有剩余时,可以充分利用剩余的资源提供更多的服务。

  * 资源互相抢占问题,当某个服务实例服务并发很高时或者开启慢查询时,会消耗更多的内存、CPU、磁盘IO资源,导致服务器上的其他实例提供服务的质量下降。

wKioL1lPymPxK5ulAADAhFfCdKg045.jpg


3. 环境 [ 关闭SeLinux ]

1
2
3
4
5
6
7
8
[root@MySQL ~] # cat /etc/redhat-release 
CentOS release 6.9 (Final)
 
[root@MySQL ~] # uname -r
2.6.32-504.el6.x86_64
 
[root@MySQL ~] # getenforce 
Disabled


4. MySQL 二进制包准备

  * 下载官方5.5二进制安装包

1
[root@MySQL ~] # wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.57-linux-glibc2.12-x86_64.tar.gz

  * 下载官方5.6二进制安装包

1
[root@MySQL ~] # wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz

  * 下载官方5.7二进制安装包

1
[root@MySQL ~] # wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar


5. mysql 版本初始化并统一修改密码

  * 创建 MySQL 用户

1
[root@MySQL ~] # useradd -r -s /sbin/nologin mysql


  * 创建MySQL数据目录

1
2
3
4
5
[root@MySQL ~] # mkdir -vp /data/mysql_data_{5..7}
mkdir : created directory ` /data '
mkdir : created directory ` /data/mysql_data_5 '
mkdir : created directory ` /data/mysql_data_6 '
mkdir : created directory ` /data/mysql_data_7 '


  * 修改MySQL 数据目录所属用户与所属组

1
[root@MySQL ~] # chown mysql.mysql -R /data/mysql_data_*


  * 解压MySQL 各版本至 /usr/local 目录

1
2
3
[root@MySQL ~] # tar zxf mysql-5.5.57-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@MySQL ~] # tar zxf mysql-5.6.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@MySQL ~] # tar xf mysql-5.7.19-linux-glibc2.12-x86_64.tar -C /usr/local/


  * MySQL 5.5 初始化

1
2
[root@MySQL ~] # chown mysql.mysql -R /usr/local/mysql-5.5.57-linux-glibc2.12-x86_64
[root@MySQL ~] # /usr/local/mysql-5.5.57-linux-glibc2.12-x86_64/scripts/mysql_install_db --user=mysql --datadir=/data/mysql_data_5 --basedir=/usr/local/mysql-5.5.57-linux-glibc2.12-x86_64

  * MySQL 5.5 修改密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@MySQL ~] # /usr/local/mysql-5.5.57-linux-glibc2.12-x86_64/bin/mysqld_safe --datadir=/data/mysql_data_5 &
[root@MySQL ~] # /usr/local/mysql-5.5.57-linux-glibc2.12-x86_64/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 1
Server version: 5.5.57 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2017, Oracle and /or  its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and /or  its
affiliates. Other names may be trademarks of their respective
owners.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
mysql>  set  password = password( '123' );
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@MySQL ~] # killall mysqld


  * MySQL 5.6 初始化

1
2
[root@MySQL ~] # chown mysql.mysql -R /usr/local/mysql-5.6.37-linux-glibc2.12-x86_64
[root@MySQL ~] # /usr/local/mysql-5.6.37-linux-glibc2.12-x86_64/scripts/mysql_install_db --user=mysql --datadir=/data/mysql_data_6 --basedir=/usr/local/mysql-5.6.37-linux-glibc2.12-x86_64

  * MySQL 5.6修改密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
[root@MySQL ~] # /usr/local/mysql-5.6.37-linux-glibc2.12-x86_64/bin/mysqld_safe --datadir=/data/mysql_data_6 &
[root@MySQL ~] # /usr/local/mysql-5.6.37-linux-glibc2.12-x86_64/bin/mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 1
Server version: 5.6.37 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2017, Oracle and /or  its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and /or  its
affiliates. Other names may be trademarks of their respective
owners.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
mysql>  set  password = password( '123' );
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit
Bye
[root@MySQL ~] # killall mysqld


  * MySQL 5.7 初始化 [ 注意初始化提示的随机密码 ]

1
2
3
4
[root@MySQL ~] # mkdir /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64/mysql-files
[root@MySQL ~] # chown root.mysql -R /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64
[root@MySQL ~] # chown mysql.mysql -R /data/mysql_data_7 /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64/mysql-files
[root@MySQL ~] # /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64/bin/mysqld --initialize --user=mysql --datadir=/data/mysql_data_7 --basedir=/usr/local/mysql-5.7.19-linux-glibc2.12-x86_64


  * MySQL 5.7修改密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@MySQL ~] # /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64/bin/mysqld_safe --datadir=/data/mysql_data_7 &
[root@MySQL ~] # /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64/bin/mysql -p'INoGk(hoj9>/'
mysql: [Warning] Using a password on the  command  line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 4
Server version: 5.7.18
 
Copyright (c) 2000, 2017, Oracle and /or  its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and /or  its
affiliates. Other names may be trademarks of their respective
owners.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
mysql>  set  password =  '123' ;
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit
Bye
[root@MySQL ~] # killall mysqld


6. 多版本部署

  * 编辑/etc/my.cnf 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
[client]
# 设置登陆用户
user = root
# 设置登陆用户密码
password = 123
 
[mysqld]
# mysql 运行用户
user = mysql
# 设置 mysql 监听 IP 地址
bind_address = 0.0.0.0
# 关闭 DNS 反解析
skip-name-resolve = 0
# 关闭监听
performance_schema = off
# 设置buffer pool 大小
innodb_buffer_pool_size = 32M
# 设置错误日志文件名
log_error = error.log
 
[mysqld_multi]
# 设置multi 日志
log =  /tmp/mysql_multi .log
 
[mysqld5]
# 设置实例所在目录
basedir =  /usr/local/mysql-5 .5.57-linux-glibc2.12-x86_64
# 设置mysql 运行程序所在路径
mysqld =  /usr/local/mysql-5 .5.57-linux-glibc2.12-x86_64 /bin/mysqld
# 设置mysql 管理运行程序所在路径
mysqladmin =  /usr/local/mysql-5 .5.57-linux-glibc2.12-x86_64 /bin/mysqladmin
# 设置实例数据目录 -- 多实例中一定要不同
datadir =  /data/mysql_data_5
# 设置socket 文件路径 -- 多实例中一定要不同
socket =  /tmp/mysql .sock5
# 设置实例监听端口 -- 多实例中一定要不同
port = 3305
 
[mysqld6]
basedir =  /usr/local/mysql-5 .6.37-linux-glibc2.12-x86_64
mysqld =  /usr/local/mysql-5 .6.37-linux-glibc2.12-x86_64 /bin/mysqld
mysqladmin =  /usr/local/mysql-5 .6.37-linux-glibc2.12-x86_64 /bin/mysqladmin
datadir =  /data/mysql_data_6
socket =  /tmp/mysql .sock6
port = 3306
 
[mysqld7]
basedir =  /usr/local/mysql-5 .7.19-linux-glibc2.12-x86_64
datadir =  /data/mysql_data_7
socket =  /tmp/mysql .sock7
port = 3307


  * 从随意版本二进制包中support-files目录下复制mysqld_multi.server启动脚本至 /etc/init.d/

1
2
[root@MySQL ~] # cp /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64/support-files/mysqld_multi.server /etc/init.d/mysqld_multi
[root@MySQL ~] # chmod +x /etc/init.d/mysqld_multi


  * 随意版本创始软链接,并设置环境变量

1
2
[root@MySQL ~] # ln -s /usr/local/mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql
[root@MySQL ~] # export PATH=/usr/local/mysql/bin:$PATH

7. 测试

   * 查看多实例状态

1
2
3
4
5
[root@MySQL ~] # /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld5 is not running
MySQL server from group: mysqld6 is not running
MySQL server from group: mysqld7 is not running


  * 启动多实例 [ 需等候几秒 ]

1
2
3
4
5
6
7
8
9
10
[root@MySQL ~] # /etc/init.d/mysqld_multi start 
[root@MySQL ~] # /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld5 is running
MySQL server from group: mysqld6 is running
MySQL server from group: mysqld7 is running
[root@MySQL ~] # netstat -lntp | grep mysqld
tcp        0      0 0.0.0.0:3305                0.0.0.0:*                   LISTEN      43750 /mysqld        
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      43753 /mysqld        
tcp        0      0 0.0.0.0:3307                0.0.0.0:*                   LISTEN      43756 /mysqld


  * 分别连接实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[root@MySQL ~] # mysql -S /tmp/mysql.sock5
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 4
Server version: 5.7.18 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2017, Oracle and /or  its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and /or  its
affiliates. Other names may be trademarks of their respective
owners.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
mysql> quit
Bye
 
[root@MySQL ~] # mysql -S /tmp/mysql.sock6
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 4
Server version: 5.7.18 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2017, Oracle and /or  its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and /or  its
affiliates. Other names may be trademarks of their respective
owners.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
mysql> quit
Bye
 
[root@MySQL ~] # mysql -S /tmp/mysql.sock7
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection  id  is 4
Server version: 5.7.18 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2017, Oracle and /or  its affiliates. All rights reserved.
 
Oracle is a registered trademark of Oracle Corporation and /or  its
affiliates. Other names may be trademarks of their respective
owners.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
mysql> quit
Bye


  * 停止多实例

1
2
3
4
5
6
[root@MySQL ~] # /etc/init.d/mysqld_multi stop
[root@MySQL ~] # /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld5 is not running
MySQL server from group: mysqld6 is not running
MySQL server from group: mysqld7 is not running


8. 总结


以需求驱动技术,技术本身没有优略之分,只有业务之分。





      本文转自asd1123509133 51CTO博客,原文链接:http://blog.51cto.com/lisea/1948537,如需转载请自行联系原作者




相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。   相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情: https://www.aliyun.com/product/rds/mysql 
相关文章
|
4月前
|
关系型数据库 MySQL 数据库
自建数据库如何迁移至RDS MySQL实例
数据库迁移是一项复杂且耗时的工程,需考虑数据安全、完整性及业务中断影响。使用阿里云数据传输服务DTS,可快速、平滑完成迁移任务,将应用停机时间降至分钟级。您还可通过全量备份自建数据库并恢复至RDS MySQL实例,实现间接迁移上云。
|
3月前
|
存储 关系型数据库 MySQL
MySQL Docker 容器化部署全指南
MySQL是一款开源关系型数据库,广泛用于Web及企业应用。Docker容器化部署可解决环境不一致、依赖冲突问题,实现高效、隔离、轻量的MySQL服务运行,支持数据持久化与快速迁移,适用于开发、测试及生产环境。
690 4
|
4月前
|
存储 弹性计算 关系型数据库
如何通过控制台创建RDS MySQL实例
本文介绍了通过控制台创建RDS MySQL实例的详细步骤,包括准备工作、选择计费方式、地域、实例规格、存储空间等关键配置,并指导用户完成下单与实例查看。
|
5月前
|
存储 关系型数据库 MySQL
【赵渝强老师】MySQL数据库的多实例环境
MySQL多实例是指在一台服务器上运行多个MySQL服务,通过不同端口提供独立的数据服务。各实例共享安装程序,但使用各自的配置文件和数据文件,实现资源高效利用。本文详细介绍了如何通过“mysqld_multi”工具配置和启动多个MySQL实例,并演示了目录创建、初始化、配置文件修改及实例启动等操作步骤。
264 1
|
5月前
|
关系型数据库 MySQL 数据库
为什么 MySQL 不推荐用 Docker 部署?
本文探讨了MySQL是否适合容器化的问题,分析了Docker容器在数据安全、性能瓶颈、状态管理及资源隔离等方面的挑战,并指出目前主流分布式数据库如TDSQL和OceanBase仍倾向于部署在物理机或KVM上。
316 0
|
8月前
|
Java 关系型数据库 MySQL
在Linux平台上进行JDK、Tomcat、MySQL的安装并部署后端项目
现在,你可以通过访问http://Your_IP:Tomcat_Port/Your_Project访问你的项目了。如果一切顺利,你将看到那绚烂的胜利之光照耀在你的项目之上!
452 41
|
8月前
|
开发框架 Java 关系型数据库
在Linux系统中安装JDK、Tomcat、MySQL以及部署J2EE后端接口
校验时,浏览器输入:http://[your_server_IP]:8080/myapp。如果你看到你的应用的欢迎页面,恭喜你,一切都已就绪。
574 17
|
8月前
|
Java 关系型数据库 MySQL
在Linux操作系统上设置JDK、Tomcat、MySQL以及J2EE后端接口的部署步骤
让我们总结一下,给你的Linux操作系统装备上最强的军队,需要先后装备好JDK的弓箭,布置好Tomcat的阵地,再把MySQL的物资原料准备好,最后部署好J2EE攻城车,那就准备好进军吧,你的Linux军团,无人可挡!
191 18
|
8月前
|
开发框架 关系型数据库 Java
Linux操作系统中JDK、Tomcat、MySQL的完整安装流程以及J2EE后端接口的部署
然后Tomcat会自动将其解压成一个名为ROOT的文件夹。重启Tomcat,让新“植物”适应新环境。访问http://localhost:8080/yourproject看到你的项目页面,说明“植物”种植成功。
269 10
|
4月前
|
缓存 关系型数据库 BI
使用MYSQL Report分析数据库性能(下)
使用MYSQL Report分析数据库性能
417 158

推荐镜像

更多