标签:bin using user adb 数据库 启动 mysql8 dep pos
原文:CentOS7.7下二进制部署MySQL多版本多实例实战MySQL
5.7的三个多实例环境(端口分别为3307,3308,3309)MySQL
5.6和8.0版本数据库实例((端口分别为3316和3326)$ hostname -I
10.0.1.51
$ hostname
db01
$ cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
# 关闭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 ‘/aliyuncs/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
$ 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-
$ find / -name mysql|xargs rm -fr
$ rpm -qa | grep mariadb
$ rpm -e mariadb-xxx --nodeps
$ rm -fr /etc/my.cnf
$ which mysql
$ pkill mysqld
$ netstat -lntup|egrep ‘3307|3308|3309|3316|3326‘
MySQL官方下载地址
下载二进制包略。
$ rm -rf /data/*
# MySQL安装目录
$ mkdir -p /data/app
# MySQL数据目录
$ mkdir -p /data/330{7,8,9}/data
$ mkdir -p /data/33{16,26}/data
# Scoket目录
$ mkdir -p /data/socket
$ 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 /data/app/mysql-5.7.28 /data/app/mysql5728
MySQL
多实例配置# 3307实例配置
$ cat > /data/3307/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/data/app/mysql5728
datadir=/data/3307/data
socket=/data/socket/mysql3307.sock
port=3307
server_id=7
EOF
# 3308实例配置
$ cat > /data/3308/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/data/app/mysql5728
datadir=/data/3308/data
socket=/data/socket/mysql3308.sock
port=3308
server_id=8
EOF
# 3309实例配置
$ cat > /data/3309/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/data/app/mysql5728
datadir=/data/3309/data
socket=/data/socket/mysql3309.sock
port=3309
server_id=9
EOF
MySQL
傀儡用户并授权$ useradd -s /sbin/nologin -M mysql
$ id mysql
$ chown -R mysql.mysql /data
$ /data/app/mysql5728/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql5728 --datadir=/data/3307/data
$ echo $?
$ /data/app/mysql5728/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql5728 --datadir=/data/3308/data
$ echo $?
$ /data/app/mysql5728/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql5728 --datadir=/data/3309/data
$ echo $?
# 3307实例启动的服务脚本
$ cat > /etc/systemd/system/mysqld3307.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/app/mysql5728/bin/mysqld --defaults-file=/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://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/app/mysql5728/bin/mysqld --defaults-file=/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://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/app/mysql5728/bin/mysqld --defaults-file=/data/3309/my.cnf
LimitNOFILE = 5000
EOF
$ 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
MySQL
多实例$ /data/app/mysql5728/bin/mysql -S /data/socket/mysql3307.sock
$ /data/app/mysql5728/bin/mysql -S /data/socket/mysql3308.sock
$ /data/app/mysql5728/bin/mysql -S /data/socket/mysql3309.sock
$ 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
MySQL
实例配置cat > /data/3316/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/data/app/mysql5646
datadir=/data/3316/data
socket=/data/socket/mysql3316.sock
port=3316
server_id=16
EOF
$ chown -R mysql.mysql /data
$ /data/app/mysql5646/scripts/mysql_install_db --user=mysql --basedir=/data/app/mysql5646 --datadir=/data/3316/data
$ echo $?
cat > /etc/systemd/system/mysqld3316.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/app/mysql5646/bin/mysqld --defaults-file=/data/3316/my.cnf
LimitNOFILE = 5000
EOF
$ systemctl daemon-reload
$ systemctl start mysqld3316.service
$ netstat -lntup|grep mysqld
tcp6 0 0 :::3316 :::* LISTEN 2516/mysqld
MySQL
实例$ /data/app/mysql5646/bin/mysql -S /data/socket/mysql3316.sock
$ 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
MySQL
实例配置cat > /data/3326/my.cnf <<EOF
[mysqld]
user=mysql
basedir=/data/app/mysql8018
datadir=/data/3326/data
socket=/data/socket/mysql3326.sock
port=3326
server_id=26
EOF
$ chown -R mysql.mysql /data
$ yum install -y perl-DBD-MySQL perl-Config-Tiny epel-release perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes
$ /data/app/mysql8018/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/app/mysql8018 --datadir=/data/3326/data
$ echo $?
cat > /etc/systemd/system/mysqld3326.service <<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/data/app/mysql8018/bin/mysqld --defaults-file=/data/3326/my.cnf
LimitNOFILE = 5000
EOF
$ systemctl start mysqld3326.service
$ netstat -lntup|grep mysqld
tcp6 0 0 :::3326 :::* LISTEN 2686/mysqld
MySQL
实例$ /data/app/mysql8018/bin/mysql -S /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
标签:bin using user adb 数据库 启动 mysql8 dep pos
原文地址:https://www.cnblogs.com/lonelyxmas/p/12766673.html