mysql多实例部署

mysql多实例部署

在这里插入图片描述

选择版本 系统 内核

//配置用户和组并解压二进制程序至/usr/local下
[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# useradd -r -M -s /sbin/nologin mysql
[root@localhost ~]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv mysql-5.7.37-linux-glibc2.12-x86_64 mysql
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  share  src
//修改目录/usr/local/mysql的属主属组
[root@localhost local]# chown -R mysql.mysql mysql
[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root  root    6 622 2021 bin
drwxr-xr-x. 2 root  root    6 622 2021 etc
drwxr-xr-x. 2 root  root    6 622 2021 games
drwxr-xr-x. 2 root  root    6 622 2021 include
drwxr-xr-x. 2 root  root    6 622 2021 lib
drwxr-xr-x. 3 root  root   17 414 01:35 lib64
drwxr-xr-x. 2 root  root    6 622 2021 libexec
drwxr-xr-x. 9 mysql mysql 129 73 13:57 mysql
drwxr-xr-x. 2 root  root    6 622 2021 sbin
drwxr-xr-x. 5 root  root   49 414 01:35 share
drwxr-xr-x. 2 root  root    6 622 2021 src
//配置环境变量
[root@localhost local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysqld.sh
[root@localhost local]# source /etc/profile.d/mysqld.sh   // 重启
[root@localhost local]# ln -s /usr/local/mysql/include /usr/include/mysql
[root@localhost local]# vim /etc/man_db.conf 
[root@localhost local]# vim /etc/ld.so.conf.d/mysqld.conf
[root@localhost local]# ldconfig 


创建各实例数据存放的目录

[root@localhost ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@localhost ~]# ls /opt/data/
3306  3307  3308

初始化各实例

[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3306
2022-07-03T06:09:48.279549Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-03T06:09:48.468951Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-03T06:09:48.500856Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-03T06:09:48.561772Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: be41157e-fa96-11ec-9398-000c29752da2.
2022-07-03T06:09:48.562545Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-03T06:09:48.795169Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T06:09:48.795201Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T06:09:48.795512Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-03T06:09:48.865897Z 1 [Note] A temporary password is generated for root@localhost: y:Uw&h*Fe5?#
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3307
2022-07-03T06:10:54.000610Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-03T06:10:54.194319Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-03T06:10:54.230010Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-03T06:10:54.242065Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: e5671a61-fa96-11ec-bf65-000c29752da2.
2022-07-03T06:10:54.242793Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-03T06:10:54.979885Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T06:10:54.979920Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T06:10:54.980402Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-03T06:10:55.269471Z 1 [Note] A temporary password is generated for root@localhost: 7TbyNnKNbN/=
[root@localhost ~]# mysqld --initialize --user mysql --datadir /opt/data/3308
2022-07-03T06:11:22.852684Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-07-03T06:11:23.029570Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-07-03T06:11:23.063439Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-07-03T06:11:23.125999Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: f69e70df-fa96-11ec-aeac-000c29752da2.
2022-07-03T06:11:23.127182Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-07-03T06:11:23.505562Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T06:11:23.505589Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-07-03T06:11:23.505896Z 0 [Warning] CA certificate ca.pem is self signed.
2022-07-03T06:11:23.569834Z 1 [Note] A temporary password is generated for root@localhost: yUi>h3aM)fti

安装perl

[root@localhost ~]# yum -y install perl

配置配置文件/etc/my.cnf

[root@localhost ~]# cat /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin

[mysqld3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/data/3306/mysql_3306.pid
log-error=/var/log/3306.log

[mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql_3307.pid
log-error=/var/log/3307.log

[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql_3308.pid
log-error=/var/log/3308.log
[root@localhost ~]# 

启动各实例

[root@localhost ~]# mysqld_multi start 3306
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@localhost ~]# mysqld_multi start 3307
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@localhost ~]# mysqld_multi start 3308
Wide character in print at /usr/local/mysql/bin/mysqld_multi line 678.
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128                0.0.0.0:22              0.0.0.0:*                
LISTEN   0        80                       *:3307                  *:*                
LISTEN   0        80                       *:3308                  *:*                
LISTEN   0        128                   [::]:22                 [::]:*                
LISTEN   0        80                       *:3306                  *:*                

初始化密码

[root@localhost ~]# mysql -uroot -p'y:Uw&h*Fe5?#' -S /tmp/mysql3306.sock 
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
[root@localhost ~]# yum provides libncurses.so.5  
上次元数据过期检查:0:05:19 前,执行于 20220703日 星期日 143636秒。
ncurses-compat-libs-6.1-9.20180224.el8.i686 : Ncurses compatibility libraries
仓库        :base
匹配来源:
提供    : libncurses.so.5

[root@localhost ~]# yum -y install ncurses-compat-libs // 安装ncurses-compat-libs
[root@localhost ~]# mysql -uroot -p'y:Uw&h*Fe5?#' -S /tmp/mysql3306.sock 
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 2
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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, 1 warning (0.00 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -p'7TbyNnKNbN/=' -S /tmp/mysql3307.sock 
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 2
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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, 1 warning (0.01 sec)

mysql> quit
Bye
[root@localhost ~]# mysql -uroot -p'yUi>h3aM)fti' -S /tmp/mysql3308.sock 
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 2
Server version: 5.7.37

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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, 1 warning (0.00 sec)

mysql> quit
Bye

设置开机自启

[root@localhost ~]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/my3306.service

[root@localhost ~]# cat /usr/lib/systemd/system/my3306.service
[Unit]
Description=3306 server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/usr/local/mysql/bin/mysqld_multi start 3306
ExecStop=ps -ef|grep 3306|grep -v grep|awk '{print $2}' | xargs kill -9
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@localhost ~]# systemctl daemon-reload  //重启服务
[root@localhost ~]# ln -s /usr/local/mysql/bin/my_print_defaults /usr/bin/  做软连接
[root@localhost ~]# systemctl status my3306  
● my3306.service - 3306 server daemon  // 查看状态
   Loaded: loaded (/usr/lib/systemd/system/my3306.service; disabled; vendor preset: d>
   Active: active (running) since Sun 2022-07-03 15:18:54 CST; 45s ago
  Process: 226473 ExecStart=/usr/local/mysql/bin/mysqld_multi start 3306 (code=exited>
 Main PID: 226491 (mysqld_safe)
    Tasks: 28 (limit: 11175)
   Memory: 197.3M
   CGroup: /system.slice/my3306.service
           ├─226491 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data/3306>
           └─226630 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=>

703 15:18:54 localhost.localdomain systemd[1]: Starting 3306 server daemon...
703 15:18:54 localhost.localdomain mysqld_multi[226473]: Wide character in print a>
703 15:18:54 localhost.localdomain systemd[1]: Started 3306 server daemon.

[root@localhost ~]# systemctl enable my3306.service //设置开机自启
Created symlink /etc/systemd/system/multi-user.target.wants/my3306.service → /usr/lib/
systemd/system/my3306.service.
[root@localhost ~]# systemctl status my3306
● my3306.service - 3306 server daemon
   Loaded: loaded (/usr/lib/systemd/system/my3306.service; enabled; vendor preset: di>
   Active: active (running) since Sun 2022-07-03 15:18:54 CST; 1min 36s ago
 Main PID: 226491 (mysqld_safe)
    Tasks: 28 (limit: 11175)
   Memory: 197.3M
   CGroup: /system.slice/my3306.service
           ├─226491 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data/3306>
           └─226630 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=>

703 15:18:54 localhost.localdomain systemd[1]: Starting 3306 server daemon...
703 15:18:54 localhost.localdomain mysqld_multi[226473]: Wide character in print a>
703 15:18:54 localhost.localdomain systemd[1]: Started 3306 server daemon.
// 重启测试
[root@localhost ~]# reboot 

连接断开
连接成功
Activate the web console with: systemctl enable --now cockpit.socket

Last login: Sun Jul  3 13:55:22 2022 from 192.168.183.1
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q       Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128                0.0.0.0:22              0.0.0.0:*                
LISTEN   0        80                       *:3306                  *:*                
LISTEN   0        128                   [::]:22                 [::]:*                
[root@localhost ~]# systemctl status my3306
● my3306.service - 3306 server daemon
   Loaded: loaded (/usr/lib/systemd/system/my3306.service; enabled; vendor preset: di>
   Active: active (running) since Sun 2022-07-03 15:22:58 CST; 23s ago
  Process: 1044 ExecStart=/usr/local/mysql/bin/mysqld_multi start 3306 (code=exited, >
 Main PID: 1064 (mysqld_safe)
    Tasks: 28 (limit: 11175)
   Memory: 221.8M
   CGroup: /system.slice/my3306.service
           ├─1064 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data/3306 ->
           └─1333 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/o>

703 15:22:58 localhost.localdomain systemd[1]: Starting 3306 server daemon...
703 15:22:58 localhost.localdomain mysqld_multi[1044]: Wide character in print at >
703 15:22:58 localhost.localdomain systemd[1]: Started 3306 server daemon.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值