CentOS7.7下二进制部署MySQL多版本多实例实战
涂鸦少年 人气:1第一章 需求说明
- 部署
MySQL
5.7的三个多实例环境(端口分别为3307,3308,3309) - 部署
MySQL
5.6和8.0版本数据库实例((端口分别为3316和3326)
第二章 环境准备
1.虚拟机环境
$ hostname -I
10.0.1.51
$ hostname
db01
$ cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
2.虚拟机优化
# 关闭Selinux
$ setenforce 0
$ sed -i s#SELINUX=enforcing#SELINUX=disabled#g /etc/selinux/config
# 关闭防火墙
$ systemctl stop firewalld
$ systemctl disable firewalld
$ iptables-save
# 更改yum源
$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.ori
$ wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
$ sed -i '/aliyuncshttps://img.qb5200.com/download-x/d' /etc/yum.repos.d/CentOS-Base.repo
# 添加epel源
$ wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 更新yum缓存
$ yum clean all
$ yum makecache fast
# 停止NetworkManager
$ systemctl stop NetworkManager
$ systemctl disable NetworkManager
# 加大文件描述符
$ echo '* - nofile 65535' >>/etc/security/limits.conf
3.清理环境
①卸载已安装的mysql
$ rpm -qa | grep mysql
# 结果如下
mysql-community-common-8.0.18-1.el7.x86_64
mysql-community-client-8.0.18-1.el7.x86_64
mysql-community-libs-8.0.18-1.el7.x86_64
# 使用以下命令依次删除上面的程序
$ yum remove mysql-xxx-xxx-
②删除mysql的配置文件
$ find / -name mysql|xargs rm -fr
③删除MariaDB的文件
$ rpm -qa | grep mariadb
$ rpm -e mariadb-xxx --nodeps
④删除my.cnf
$ rm -fr /etc/my.cnf
⑤检查端口是否被占用
$ which mysql
$ pkill mysqld
$ netstat -lntup|egrep '3307|3308|3309|3316|3326'
4.准备软件包
MySQL官方下载地址
下载二进制包略。
5.准备目录
$ rm -rf https://img.qb5200.com/download-x/data/*
# MySQL安装目录
$ mkdir -p https://img.qb5200.com/download-x/data/app
# MySQL数据目录
$ mkdir -p https://img.qb5200.com/download-x/data/330{7,8,9}https://img.qb5200.com/download-x/data
$ mkdir -p https://img.qb5200.com/download-x/data/33{16,26}https://img.qb5200.com/download-x/data
# Scoket目录
$ mkdir -p https://img.qb5200.com/download-x/data/socket
第三章 部署MySQL5.7多实例
1.解压软件包并制作软连接
$ tar xf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
$ mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql-5.7.28
$ ln -s https://img.qb5200.com/download-x/data/app/mysql-5.7.28 https://img.qb5200.com/download-x/data/app/mysql5728
2.创建MySQL
多实例配置
# 3307实例配置
$ cat > https://img.qb5200.com/download-x/data/3307/my.cnf <<EOF
[mysqld]
user=mysql
basedir=https://img.qb5200.com/download-x/data/app/mysql5728
datadir=https://img.qb5200.com/download-x/data/3307https://img.qb5200.com/download-x/data
socket=https://img.qb5200.com/download-x/data/socket/mysql3307.sock
port=3307
server_id=7
EOF
# 3308实例配置
$ cat > https://img.qb5200.com/download-x/data/3308/my.cnf <<EOF
[mysqld]
user=mysql
basedir=https://img.qb5200.com/download-x/data/app/mysql5728
datadir=https://img.qb5200.com/download-x/data/3308https://img.qb5200.com/download-x/data
socket=https://img.qb5200.com/download-x/data/socket/mysql3308.sock
port=3308
server_id=8
EOF
# 3309实例配置
$ cat > https://img.qb5200.com/download-x/data/3309/my.cnf <<EOF
[mysqld]
user=mysql
basedir=https://img.qb5200.com/download-x/data/app/mysql5728
datadir=https://img.qb5200.com/download-x/data/3309https://img.qb5200.com/download-x/data
socket=https://img.qb5200.com/download-x/data/socket/mysql3309.sock
port=3309
server_id=9
EOF
3.创建MySQL
傀儡用户并授权
$ useradd -s /sbin/nologin -M mysql
$ id mysql
$ chown -R mysql.mysql https://img.qb5200.com/download-x/data
4.初始化
$ https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysqld --initialize-insecure --user=mysql --basedir=https://img.qb5200.com/download-x/data/app/mysql5728 --datadir=https://img.qb5200.com/download-x/data/3307https://img.qb5200.com/download-x/data
$ echo $?
$ https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysqld --initialize-insecure --user=mysql --basedir=https://img.qb5200.com/download-x/data/app/mysql5728 --datadir=https://img.qb5200.com/download-x/data/3308https://img.qb5200.com/download-x/data
$ echo $?
$ https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysqld --initialize-insecure --user=mysql --basedir=https://img.qb5200.com/download-x/data/app/mysql5728 --datadir=https://img.qb5200.com/download-x/data/3309https://img.qb5200.com/download-x/data
$ echo $?
5.编写systemd启动脚本
# 3307实例启动的服务脚本
$ cat > /etc/systemd/system/mysqld3307.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http:/https://img.qb5200.com/download-x/dev.mysql.comhttps://img.qb5200.com/download-x/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysqld --defaults-file=https://img.qb5200.com/download-x/data/3307/my.cnf
LimitNOFILE = 5000
EOF
# 3308实例启动的服务脚本
$ cat > /etc/systemd/system/mysqld3308.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http:/https://img.qb5200.com/download-x/dev.mysql.comhttps://img.qb5200.com/download-x/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysqld --defaults-file=https://img.qb5200.com/download-x/data/3308/my.cnf
LimitNOFILE = 5000
EOF
# 3309实例启动的服务脚本
$ cat > /etc/systemd/system/mysqld3309.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http:/https://img.qb5200.com/download-x/dev.mysql.comhttps://img.qb5200.com/download-x/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysqld --defaults-file=https://img.qb5200.com/download-x/data/3309/my.cnf
LimitNOFILE = 5000
EOF
6.启动多实例
$ systemctl start mysqld3307
$ systemctl start mysqld3308
$ systemctl start mysqld3309
$ netstat -lntup|grep mysqld
tcp6 0 0 :::3307 :::* LISTEN 2093/mysqld
tcp6 0 0 :::3308 :::* LISTEN 2127/mysqld
tcp6 0 0 :::3309 :::* LISTEN 2161/mysqld
7.绝对路径登录MySQL
多实例
$ https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysql -S https://img.qb5200.com/download-x/data/socket/mysql3307.sock
$ https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysql -S https://img.qb5200.com/download-x/data/socket/mysql3308.sock
$ https://img.qb5200.com/download-x/data/app/mysql5728/bin/mysql -S https://img.qb5200.com/download-x/data/socket/mysql3309.sock
第四章 部署MySQL5.6单实例
1.解压软件包并制作软连接
$ tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
$ mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql-5.6.46
$ ln -s ln -s mysql-5.6.46 mysql5646
2.创建MySQL
实例配置
cat > https://img.qb5200.com/download-x/data/3316/my.cnf <<EOF
[mysqld]
user=mysql
basedir=https://img.qb5200.com/download-x/data/app/mysql5646
datadir=https://img.qb5200.com/download-x/data/3316https://img.qb5200.com/download-x/data
socket=https://img.qb5200.com/download-x/data/socket/mysql3316.sock
port=3316
server_id=16
EOF
3.创建mysql傀儡用户并授权
$ chown -R mysql.mysql https://img.qb5200.com/download-x/data
4.初始化
$ https://img.qb5200.com/download-x/data/app/mysql5646/scripts/mysql_install_db --user=mysql --basedir=https://img.qb5200.com/download-x/data/app/mysql5646 --datadir=https://img.qb5200.com/download-x/data/3316https://img.qb5200.com/download-x/data
$ echo $?
5.编写systemd启动脚本
cat > /etc/systemd/system/mysqld3316.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http:/https://img.qb5200.com/download-x/dev.mysql.comhttps://img.qb5200.com/download-x/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=https://img.qb5200.com/download-x/data/app/mysql5646/bin/mysqld --defaults-file=https://img.qb5200.com/download-x/data/3316/my.cnf
LimitNOFILE = 5000
EOF
6.启动实例
$ systemctl daemon-reload
$ systemctl start mysqld3316.service
$ netstat -lntup|grep mysqld
tcp6 0 0 :::3316 :::* LISTEN 2516/mysqld
7.绝对路径登录MySQL
实例
$ https://img.qb5200.com/download-x/data/app/mysql5646/bin/mysql -S https://img.qb5200.com/download-x/data/socket/mysql3316.sock
第五章 部署MySQL8.0单实例
1.解压软件包并制作软连接
$ tar xf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz
$ mv mysql-8.0.18-linux-glibc2.12-x86_64 mysql-8.0.18
$ ln -s mysql-8.0.18 mysql8018
2.创建MySQL
实例配置
cat > https://img.qb5200.com/download-x/data/3326/my.cnf <<EOF
[mysqld]
user=mysql
basedir=https://img.qb5200.com/download-x/data/app/mysql8018
datadir=https://img.qb5200.com/download-x/data/3326https://img.qb5200.com/download-x/data
socket=https://img.qb5200.com/download-x/data/socket/mysql3326.sock
port=3326
server_id=26
EOF
3.创建mysql傀儡用户并授权
$ chown -R mysql.mysql https://img.qb5200.com/download-x/data
4.安装依赖并初始化
$ yum install -y perl-DBD-MySQL perl-Config-Tiny epel-release perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes
$ https://img.qb5200.com/download-x/data/app/mysql8018/bin/mysqld --initialize-insecure --user=mysql --basedir=https://img.qb5200.com/download-x/data/app/mysql8018 --datadir=https://img.qb5200.com/download-x/data/3326https://img.qb5200.com/download-x/data
$ echo $?
5.编写systemd启动脚本
cat > /etc/systemd/system/mysqld3326.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http:/https://img.qb5200.com/download-x/dev.mysql.comhttps://img.qb5200.com/download-x/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=https://img.qb5200.com/download-x/data/app/mysql8018/bin/mysqld --defaults-file=https://img.qb5200.com/download-x/data/3326/my.cnf
LimitNOFILE = 5000
EOF
6.启动实例
$ systemctl start mysqld3326.service
$ netstat -lntup|grep mysqld
tcp6 0 0 :::3326 :::* LISTEN 2686/mysqld
7.绝对路径登录MySQL
实例
$ https://img.qb5200.com/download-x/data/app/mysql8018/bin/mysql -S https://img.qb5200.com/download-x/data/socket/mysql3326.sock
至此,在同一台服务器上部署多版本MySQL多实例完成,可是使用一下命令验证:
[root@db01 ~]# netstat -lntup|grep mysqld
tcp6 0 0 :::3326 :::* LISTEN 2686/mysqld
tcp6 0 0 :::33060 :::* LISTEN 2686/mysqld
tcp6 0 0 :::3307 :::* LISTEN 2093/mysqld
tcp6 0 0 :::3308 :::* LISTEN 2127/mysqld
tcp6 0 0 :::3309 :::* LISTEN 2161/mysqld
tcp6 0 0 :::3316 :::* LISTEN 2516/mysqld
我的博客:https://www.pingface.com/2020/04/23/mysqlmulti.html
加载全部内容