mysql 多实例部署、xtrabackup下载与安装
mysql 多实例部署
一、 二进制安装mysql
软件下载
- 下载网络源
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
- 下载mysql二级制包
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
配置用户并解压二进制程序至/usr/local下
[root@mariadb ~]# ls
mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@mariadb ~]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@mariadb ~]# cd /usr/local/
[root@mariadb local]# ls
apr bin games include lib64 mysql-5.7.34-linux-glibc2.12-x86_64 share
apr-util etc httpd lib libexec sbin src
[root@mariadb local]# ln -s /usr/local/mysql-5.7.34-linux-glibc2.12-x86_64/ /usr/local/mysql
[root@mariadb local]# ll mysql
lrwxrwxrwx 1 root root 47 8月 29 13:13 mysql -> /usr/local/mysql-5.7.34-linux-glibc2.12-x86_64/
[root@mariadb local]# useradd -r -M -s /sbin/nologin mysql
[root@mariadb local]# chown -R mysql.mysql /usr/local/mysql*
[root@mariadb local]# ll /usr/local/mysql
lrwxrwxrwx 1 mysql mysql 47 8月 29 13:13 /usr/local/mysql -> /usr/local/mysql-5.7.34-linux-glibc2.12-x86_64/
[root@mariadb local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@mariadb local]# source /etc/profile.d/mysql.sh
[root@mariadb local]# echo $PATH
/usr/local/mysql/bin:/usr/local/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
二、实例部署
创建各实例数据存放的目录
[root@mariadb ~]# mkdir -p /opt/data/{3306,3307,3308}
[root@mariadb ~]# chown -R mysql.mysql /opt/data/
[root@mariadb ~]# ll /opt/data/
总用量 110680
drwxr-xr-x 2 mysql mysql 6 8月 29 13:18 3306
drwxr-xr-x 2 mysql mysql 6 8月 29 13:18 3307
drwxr-xr-x 2 mysql mysql 6 8月 29 13:18 3308
-rw-rw---- 1 mysql mysql 16384 8月 24 15:38 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 8月 24 15:38 aria_log_control
-rw-r----- 1 mysql mysql 56 8月 10 17:03 auto.cnf
-rw------- 1 mysql mysql 1676 8月 10 17:03 ca-key.pem
-rw-r--r-- 1 mysql mysql 1112 8月 10 17:03 ca.pem
-rw-r--r-- 1 mysql mysql 1112 8月 10 17:03 client-cert.pem
-rw------- 1 mysql mysql 1680 8月 10 17:03 client-key.pem
-rw-rw---- 1 mysql mysql 1486 8月 24 15:38 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 8月 24 15:38 ibdata1
-rw-rw---- 1 mysql mysql 50331648 8月 24 15:38 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 8月 10 17:39 ib_logfile1
-rw-rw---- 1 mysql mysql 0 8月 10 17:39 multi-master.info
drwxr-x--- 2 mysql mysql 4096 8月 10 17:03 mysql
drwxr-x--- 2 mysql mysql 8192 8月 10 17:03 performance_schema
-rw------- 1 mysql mysql 1680 8月 10 17:03 private_key.pem
-rw-r--r-- 1 mysql mysql 452 8月 10 17:03 public_key.pem
-rw-r--r-- 1 mysql mysql 1112 8月 10 17:03 server-cert.pem
-rw------- 1 mysql mysql 1676 8月 10 17:03 server-key.pem
drwxr-x--- 2 mysql mysql 8192 8月 10 17:03 sys
[root@mariadb ~]# tree /opt/data/
/opt/data/
├── 3306
├── 3307
├── 3308
初始化各实例
[root@mariadb ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
2021-08-29T13:20:20.373096Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-29T13:20:20.483071Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-29T13:20:20.503876Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-29T13:20:20.557846Z 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: dc17e096-08cb-11ec-b3f4-000c29dfcde8.
2021-08-29T13:20:20.558730Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-29T13:20:21.895207Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-29T13:20:22.090131Z 1 [Note] A temporary password is generated for root@localhost: UB>A(p>5(w34
[root@mariadb ~]# echo 'UB>A(p>5(w34' > 3306_pass
其他两个端口同理
密码分别为:
Installing new database in /opt/data/33072021-08-29T13:26:01.829149Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-29T13:26:01.913933Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-29T13:26:01.933676Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-29T13:26:01.989315Z 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: a79a2f64-08cc-11ec-bf55-000c29dfcde8.
2021-08-29T13:26:01.989990Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-29T13:26:02.850369Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-29T13:26:03.167494Z 1 [Note] A temporary password is generated for root@localhost: <l!pL,0ad;%e
[root@mariadb ~]# echo '<l!pL,0ad;%e' > 3307_passInstalling new database in /opt/data/33082021-08-29T13:26:04.788409Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-08-29T13:26:04.875391Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-08-29T13:26:04.910447Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-08-29T13:26:04.965507Z 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: a96050e6-08cc-11ec-8cb9-000c29dfcde8.
2021-08-29T13:26:04.966128Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-08-29T13:26:05.870725Z 0 [Warning] CA certificate ca.pem is self signed.
2021-08-29T13:26:06.034786Z 1 [Note] A temporary password is generated for root@localhost: R(Q;:xd,w0L,
[root@mariadb ~]# echo 'R(Q;:xd,w0L,' > 3308_pass
安装perl、ncuress-compat-libs依赖包
[root@mariadb ~]# yum -y install perl ncurses-compat-libs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository AppStream is listed more than once in the configuration
上次元数据过期检查:0:22:54 前,执行于 2021年08月29日 星期日 13时00分11秒。
软件包 perl-4:5.26.3-419.el8_4.1.x86_64 已安装。
软件包 ncurses-compat-libs-6.1-7.20180224.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
配置文件/etc/my.cnf
[root@mariadb ~]# vim /etc/my.cnf
[root@mariadb ~]# 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.pid
log-error=/var/log/mysql_3306.log[mysqld3307]
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql.pid
log-error=/var/log/mysql_3307.log[mysqld3308]
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql.pid
log-error=/var/log/mysql_3308.log
启动各实例
[root@mariadb ~]# mysqld_multi start
[root@mariadb ~]# ss -anlit
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:111 0.0.0.0:* cubic cwnd:10
LISTEN 0 32 192.168.122.1:53 0.0.0.0:* cubic cwnd:10
LISTEN 0 128 0.0.0.0:22 0.0.0.0:* cubic cwnd:10
LISTEN 0 5 127.0.0.1:631 0.0.0.0:* cubic cwnd:10
LISTEN 0 80 *:3306 *:* cubic cwnd:10
LISTEN 0 80 *:3307 *:* cubic cwnd:10
LISTEN 0 80 *:3308 *:* cubic cwnd:10
LISTEN 0 128 [::]:111 [::]:* cubic cwnd:10
LISTEN 0 128 [::]:22 [::]:* cubic cwnd:10
LISTEN 0 5 [::1]:631 [::]:* cubic cwnd:10
登录
[root@mariadb ~]# mysql -uroot -p'UB>A(p>5(w34' -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.34Copyright (c) 2000, 2021, 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> exit
Bye[root@mariadb ~]# mysql -uroot -p<l!pL,0ad;%e -h127.0.0.1 -P3307
-bash: !pL,0ad: event not found
[root@mariadb ~]# mysql -uroot -p'<l!pL,0ad;%e' -h127.0.0.1 -P3307
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.34Copyright (c) 2000, 2021, 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> exit
Bye
[root@mariadb ~]# mysql -uroot -p'R(Q;:xd,w0L,' -h127.0.0.1 -P3308
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.34Copyright (c) 2000, 2021, 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> exit
Bye
三、设置开机自启
[root@mariadb ~]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi.server
[root@mariadb ~]# vim /etc/init.d/mysqld_multi.server
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
export PATH=/usr/local/mysql/bin:$PATH
[root@mariadb ~]# chkconfig mysqld_multi.server on
[root@mariadb ~]# chkconfig --list注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。 要列出 systemd 服务,请执行 'systemctl list-unit-files'。查看在具体 target 启用的服务请执行'systemctl list-dependencies [target]'。mysqld_multi.server 0:关 1:关 2:开 3:开 4:开 5:开 6:关
xtrabackup
一、xtrabackup下载与安装
[root@mariadb ~]# wget https://repo.percona.com/yum/release/8/RPMS/x86_64/percona-xtrabackup-24-2.4.23-1.el8.x86_64.rpm
--2021-08-27 20:29:02-- https://repo.percona.com/yum/release/8/RPMS/x86_64/percona-xtrabackup-24-2.4.23-1.el8.x86_64.rpm
正在解析主机 repo.percona.com (repo.percona.com)... 167.71.118.3, 157.245.119.64, 167.99.233.229
正在连接 repo.percona.com (repo.percona.com)|167.71.118.3|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:8060704 (7.7M) [application/x-redhat-package-manager]
正在保存至: “percona-xtrabackup-24-2.4.23-1.el8.x86_64.rpm”percona-xtrabackup-24- 100%[===========================>] 7.69M 32.4KB/s 用时 3m 13s 2021-08-27 20:32:18 (40.8 KB/s) - 已保存 “percona-xtrabackup-24-2.4.23-1.el8.x86_64.rpm” [8060704/8060704])[root@mariadb ~]# ls pe*
percona-xtrabackup-24-2.4.23-1.el8.x86_64.rpm
- 安装
[root@mariadb ~]# yum -y install percona-xtrabackup-24-2.4.23-1.el8.x86_64.rpm
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
……mariadb-connector-c-config-3.1.11-2.el8_3.noarch percona-xtrabackup-24-2.4.23-1.el8.x86_64 perl-DBD-MySQL-4.046-3.module_el8.1.0+203+e45423dc.x86_64 完毕!
二、备份
- 删除
- 删除配置文件中/etc/my.cnf中3307、3308
[root@mariadb ~]# vim /etc/my.cnf
[root@mariadb ~]# cat /etc/my.cnf
[3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/data/3306/mysql.pid
log-error=/var/log/mysql_3306.log//配置文件
[root@mariadb ~]# cd /usr/local/mysql/support-files
[root@mariadb support-files]# vim mysql.server
basedir=/usr/local/mysql
datadir=/opt/data/3306
[root@mariadb support-files]# ./mysql.server startSUCCESS! [root@mariadb support-files]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
- 将密码和用户写入配置文件
[root@mariadb ~]# vim ~/.my.cnf
[root@mariadb ~]# cat ~/.my.cnf
[client]
user=root
password=redhat123
- 创建一个存放备份文件的目录方便等下放置备份文件
[root@mariadb ~]# mkdir /backup
- 创建表
[root@mariadb ~]# mysql -uroot -predhat123
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 3
Server version: 5.7.34 MySQL Community Server (GPL)Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mariadb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)mysql> create table student (id int not null primary key auto_increment,name varchar(50) not null,age tinyint);
Query OK, 0 rows affected (0.01 sec)mysql> insert student (name,age) values('tom',20),('jerry',20),('wnagermazi',15),('zhangsan',19),('lisi',25);
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0mysql> select * from student;
+----+------------+------+
| id | name | age |
+----+------------+------+
| 1 | tom | 20 |
| 2 | jerry | 20 |
| 3 | wnagermazi | 15 |
| 4 | zhangsan | 19 |
| 5 | lisi | 25 |
+----+------------+------+
5 rows in set (0.00 sec)
- 备份
[root@mariadb ~]# innobackupex --defaults-file=/etc/my.cnf --user=root --password=redhat123 --host=127.0.0.1 /backup
xtrabackup: recognized server arguments:
xtrabackup: recognized client arguments:
……
210827 21:31:01 [00] Writing /backup/2021-08-27_21-30-57/xtrabackup_info
210827 21:31:01 [00] ...done
xtrabackup: Transaction log of lsn (2755296) to (2755305) was copied.
210827 21:31:01 completed OK![root@mariadb ~]# cd /backup/
[root@mariadb backup]# ls
2021-08-27_21-30-57
- 误删除数据
[root@mariadb ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.34 MySQL Community Server (GPL)Copyright (c) 2000, 2021, 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mariadb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)mysql> drop database mariadb;
Query OK, 1 row affected (0.01 sec)mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
- 恢复
[root@mariadb ~]# innobackupex --apply-log /backup/2021-08-27_21-30-57/ //检查日志
xtrabackup: recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=50331648 --innodb_fast_checksum=0 --innodb_page_size=
……
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 2755624
210827 21:37:41 completed OK!//删除
[root@mariadb ~]# rm -rf /opt/data/3306/*[root@mariadb ~]# innobackupex --defaults-file=/etc/my.cnf --copy-back -uroot -predhat123 --host=127.0.0.1 /backup1/2021-08-27_22-22-59/
xtrabackup: recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksum_algorithm=strict_crc32 --innodb_data_file_path=ibdata1:12M:autoextend --
……
InnoDB: Shutdown completed; log sequence number 2755624
210827 21:50:10 completed OK!mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mariadb |
| mysql |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql 多实例部署、xtrabackup下载与安装相关推荐
- MySQL 多实例部署 xtrabackup备份与恢复
MySQL 多实例部署 1.下载安装包 [root@localhost ~]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7. ...
- MYSQl 多实例部署
MYSQl 多实例部署和 Xtarbackup 软件下载安装 下载二进制格式的mysql软件包 [root@localhost ~]# cd /usr/src/ [root@localhost ~]# ...
- mysql数据库备份与恢复,mysql多实例部署
mysql数据库备份与恢复,mysql多实例部署 文章目录 mysql数据库备份与恢复,mysql多实例部署 1: 数据库备份 2:冷备份 3:热备份 4:mysql备份工具mysqldump 5:差 ...
- mysql 单实例部署_Mysql 数据库单机多实例部署手记
最近的研发机器需要部署多个环境,包括数据库.为了管理方便考虑将mysql数据库进行隔离,即采用单机多实例部署的方式. 找了会资料发现用的人也不是太多,一般的生产环境为了充分发挥机器性能都是单机单实例运 ...
- yum方式安装mysql多实例_centos7下使用yum安装mysql
CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 $ wget http://repo.mysql.com ...
- 【MySQL】MySQL之示例数据库Sakila下载及安装
本篇将演示如何下载及安装MySQL示例数据库Sakila. 1.下载Sakila数据库: [root@strong ~]# wget http://downloads.mysql.com/docs/s ...
- mysql 单实例部署_MySQL 5.5单实例 编译安装
1.建立MySQL账号 首先以root登录到Linux,然后执行如下命令创建MySQL组及用户[root@loveyu home]# groupadd mysql [root@loveyu home] ...
- mysql多实例部署
二进制文件下载 [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget https://downloads.mysql.com/arch ...
- 04 MySQL多实例部署
软件下载 //下载二进制格式的mysql软件包 [root@localhost ~]# cd /usr/src/ [root@localhost src]# wget https://download ...
最新文章
- 基于大数据的Uber数据实时监控(Part 4:Spark Streaming、DataFrames和HBase)
- python数字排序分组代码_python pandas 组内排序、单组排序、标号的实例
- 利用OpenCV的SimpleBlobDetector检测图像的奇异区域(斑点)
- 带排序动画的横向条形图
- 这所高校的快递被机器人承包了,别人家的学校!
- 显示mnist手写数字
- 实战:kafka实现日志收集系统
- 16节课搞懂大数据,视频教程限时免费领取
- Android开发笔记(一百六十三)高仿京东的沉浸式状态栏
- STM32F103ZET6(野火霸道v2)串口烧录(mcuisp)
- 如何获取最好权限删除顽固文件Mac系统
- Micrium 开放了µC/OS-III源代码
- curl api接口获取当前IP地址
- UVa 10603 - Fille
- 【软考】信息安全工程师教程 第五章 物理与环境安全技术
- 陷波器的离散化及仿真验证
- bioperl 自动化下载genbank 中的序列
- 百度云 x 宝宝知道 | 你的宝宝问题,这个APP都知道
- 数字货币与我们普通投资者的关系
- 台式计算机中如何安装CPU,台式电脑硬件如何安装
热门文章
- react+antd+vite配置一键换肤功能(步骤详细)
- 商业数字营销师资格考试
- abb楼宇对讲机使用说明书_ABB楼宇对讲系统介绍详解.ppt
- ATmega16和avr
- 下载docx变成jsp_IE下载docx扩展名的文件时,会自动将扩展名变为zip。
- 淘宝活动代码查询帐号情况
- python处理word_python处理word文档
- ros2与windows入门教程-windows上安装ROS2 foxy
- string类型转bool类型_Go 类型的 String() 方法和格式化描述符
- 高清视频联网监控,实现一站式远程智控和管理