This commit is contained in:
YUN-PC5\user 2024-01-30 17:28:22 +08:00
parent 322b19d33e
commit 42dc8497a2
25 changed files with 292 additions and 12 deletions

View File

@ -596,8 +596,11 @@ cd mysql_install
# 下载安装包 # 下载安装包
wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.41-1.el7.x86_64.rpm-bundle.tar wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.41-1.el7.x86_64.rpm-bundle.tar
tar -xvf mysql-5.7.41-1.el7.x86_64.rpm-bundle.tar tar -xvf mysql-5.7.41-1.el7.x86_64.rpm-bundle.tar
rpm -ivh mysql-community-common-5.7.41-1.el7.x86_64.rpm rpm -ivh mysql-community-common-5.7.41-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.41-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-5.7.41-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm rpm -ivh mysql-community-libs-compat-5.7.41-1.el7.x86_64.rpm
# 如果出现以下错误 # 如果出现以下错误
error: Failed dependencies: error: Failed dependencies:
@ -605,31 +608,40 @@ error: Failed dependencies:
libcrypto.so.10(libcrypto.so.10)(64bit) is needed by mysql-community-libs-compat-5.7.41-1.el7.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by mysql-community-libs-compat-5.7.41-1.el7.x86_64
libssl.so.10()(64bit) is needed by mysql-community-libs-compat-5.7.41-1.el7.x86_64 libssl.so.10()(64bit) is needed by mysql-community-libs-compat-5.7.41-1.el7.x86_64
libssl.so.10(libssl.so.10)(64bit) is needed by mysql-community-libs-compat-5.7.41-1.el7.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by mysql-community-libs-compat-5.7.41-1.el7.x86_64
# 执行
dnf install -y https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-4.el8_6.x86_64.rpm dnf install -y https://repo.almalinux.org/almalinux/8/AppStream/x86_64/os/Packages/compat-openssl10-1.0.2o-4.el8_6.x86_64.rpm
rpm -ivh mysql-community-devel-5.7.41-1.el7.x86_64.rpm rpm -ivh mysql-community-devel-5.7.41-1.el7.x86_64.rpm
# 如果出现以下错误 # 如果出现以下错误
error: Failed dependencies: error: Failed dependencies:
/usr/bin/pkg-config is needed by mysql-community-devel-5.7.41-1.el7.x86_64 /usr/bin/pkg-config is needed by mysql-community-devel-5.7.41-1.el7.x86_64
# 执行
dnf install openssl-devel -y dnf install openssl-devel -y
rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm
# 如果出现以下错误 # 如果出现以下错误
错误:依赖检测失败: 错误:依赖检测失败:
libncurses.so.5()(64bit) 被 mysql-community-client-5.7.41-1.el7.x86_64 需要 libncurses.so.5()(64bit) 被 mysql-community-client-5.7.41-1.el7.x86_64 需要
libtinfo.so.5()(64bit) 被 mysql-community-client-5.7.41-1.el7.x86_64 需要 libtinfo.so.5()(64bit) 被 mysql-community-client-5.7.41-1.el7.x86_64 需要
# 执行
dnf install libncurses* -y dnf install libncurses* -y
dnf install epel-release -y dnf install epel-release -y
dnf install ncurses-compat-libs -y dnf install ncurses-compat-libs -y
# 再次执行 rpm -ivh mysql-community-client-5.7.41-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm
# 如果出现以下提示 # 如果出现以下提示
/usr/lib/tmpfiles.d/mysql.conf:23: Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly. /usr/lib/tmpfiles.d/mysql.conf:23: Line references path below legacy directory /var/run/, updating /var/run/mysqld → /run/mysqld; please update the tmpfiles.d/ drop-in file accordingly.
# 执行
vim /usr/lib/tmpfiles.d/mysql.conf vim /usr/lib/tmpfiles.d/mysql.conf
# 将/var/run/mysqld 改为 /run/mysqld # 将/var/run/mysqld 改为 /run/mysqld
# 如果出现以下提示 # 如果出现以下提示
error: Failed dependencies: error: Failed dependencies:
libcrypt.so.1()(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64 libcrypt.so.1()(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
libcrypt.so.1(GLIBC_2.2.5)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64 libcrypt.so.1(GLIBC_2.2.5)(64bit) is needed by mysql-community-server-5.7.41-1.el7.x86_64
# 执行
dnf install -y libxcrypt-compat dnf install -y libxcrypt-compat
# 如果出现以下提示 # 如果出现以下提示
error: Failed dependencies: error: Failed dependencies:
/usr/bin/perl is needed by mysql-community-server-5.7.41-1.el7.x86_64 /usr/bin/perl is needed by mysql-community-server-5.7.41-1.el7.x86_64
@ -639,8 +651,9 @@ dnf install -y perl.x86_64
# 如果出现以下提示 # 如果出现以下提示
error: Failed dependencies: error: Failed dependencies:
net-tools is needed by mysql-community-server-5.7.41-1.el7.x86_64 net-tools is needed by mysql-community-server-5.7.41-1.el7.x86_64
# 执行
dnf install net-tools -y dnf install net-tools -y
# 再次执行 rpm -ivh mysql-community-server-5.7.41-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-5.7.41-1.el7.x86_64.rpm rpm -ivh mysql-community-embedded-compat-5.7.41-1.el7.x86_64.rpm
``` ```
@ -775,6 +788,108 @@ firewall-cmd --zone=public --add-port=3306/tcp --permanent
``` ```
## 查看硬盘空间
```shell
# 统计磁盘整体情况,包括磁盘大小,已使用,可用
df -lh
# 查看根目录下文件夹大小
du -sh /*
```
## 扩容
### LVM
Orale VirtualBox
![image-20240130093530200](Linux/image-20240130093530200.png)
需要选择最后一个,因为前几个是之前的备份快照
![image-20240130093629718](Linux/image-20240130093629718.png)
分配大小即可,只能增加不能缩小
查看现有分区大小
```shell
df -Th
```
![image-20240130093817210](Linux/image-20240130093817210.png)
查看扩容后磁盘大小
```shell
lsblk
```
![image-20240130093857754](Linux/image-20240130093857754.png)
创建分区
```shell
fdisk /dev/sda
```
![image-20240130093939297](Linux/image-20240130093939297.png)
![image-20240130094105250](Linux/image-20240130094105250.png)
刷新分区并创建物理卷
```shell
partprobe /dev/sda
pvcreate /dev/sda4
```
![image-20240130094218593](Linux/image-20240130094218593.png)
查看卷组名称,以及卷组使用情况
```shell
vgdisplay
```
![image-20240130094244545](Linux/image-20240130094244545.png)
将物理卷扩展到卷组
```shell
vgextend rl /dev/sda4
```
![image-20240130094253931](Linux/image-20240130094253931.png)
查看当前逻辑卷的空间状态
```shell
lvdisplay
```
![image-20240130094329028](Linux/image-20240130094329028.png)
将卷组中的空闲空间扩展到根分区逻辑卷
```shell
lvextend -l +100%FREE /dev/rl/root
```
![image-20240130094418379](Linux/image-20240130094418379.png)
刷新根分区
```shell
xfs_growfs /dev/rl/root
```
![image-20240130094442884](Linux/image-20240130094442884.png)
扩容成功
![image-20240130094540550](Linux/image-20240130094540550.png)
## 分配Swap ## 分配Swap
查看分区大小 查看分区大小
@ -1083,15 +1198,6 @@ dnf install nodejs -y
## 查看硬盘空间
```shell
# 统计磁盘整体情况,包括磁盘大小,已使用,可用
df -lh
# 查看根目录下文件夹大小
du -sh /*
```
## 安装宝塔面板 ## 安装宝塔面板
## 安装 Neofetch ## 安装 Neofetch
@ -1334,3 +1440,50 @@ type=rpm-md
dnf install --enablerepo=elasticsearch elasticsearch -y dnf install --enablerepo=elasticsearch elasticsearch -y
``` ```
## 安装 Rsync
```shell
dnf install rsync -y
```
### 配置
```shell
vim /etc/rsyncd.conf
# /etc/rsyncd: configuration file for rsync daemon mode
# See rsyncd.conf man page for more options.
# configuration example:
uid = root
gid = root
ignore errors
hosts allow = 10.0.3.0/24
secrets file = /etc/rsyncd.secrets
# use chroot = yes
# max connections = 4
# pid file = /var/run/rsyncd.pid
# exclude = lost+found/
# transfer logging = yes
# timeout = 900
# ignore nonreadable = yes
# dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
# [ftp]
# path = /home/ftp
# comment = ftp export area
# 同步模块名称
[syncwspswwwroot]
# 服务器同步的路径
path = /root/wwwroot
log file = /var/log/rsync.log
# 只读模式 不允许客户端向同步路径进行同步上传文件
read only = yes
[mysql_bakup]
path = /root/mysql_bakup
read only = yes
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@ -68,7 +68,7 @@ mysqldump -uroot -p -B test > test.sql
- MySQL 5.6、5.7以下载并安装Percona XtraBackup 2.4.9为例 - MySQL 5.6、5.7以下载并安装Percona XtraBackup 2.4.9为例
```shell ```shell
wget https://downloads.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.9/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.9-1.el9.x86_64.rpm wget https://downloads.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.29/binary/redhat/9/x86_64/percona-xtrabackup-24-2.4.29-1.el9.x86_64.rpm
rpm -ivh percona-xtrabackup-24-2.4.9-1.el7.x86_64.rpm --nodeps --force rpm -ivh percona-xtrabackup-24-2.4.9-1.el7.x86_64.rpm --nodeps --force
``` ```
@ -80,9 +80,136 @@ mysqldump -uroot -p -B test > test.sql
rpm -ivh percona-xtrabackup-80-8.0.32-26.1.el7.x86_64.rpm --nodeps --force rpm -ivh percona-xtrabackup-80-8.0.32-26.1.el7.x86_64.rpm --nodeps --force
``` ```
## 备份
#### 全量备份
```shell
innobackupex --user=root --password=123456 --host=127.0.0.1 ~/mysql_bakup/
#语法解释说明
#--user=root 指定备份用户
#--password=123456 指定备份用户密码
#--host  指定主机
#~/mysql_bakup/  指定备份目录
```
执行命令后。可看到备份时间的文件夹
![image-20240130140632864](MySQL/image-20240130140632864.png)
文件夹内容如下
![image-20240130140723465](MySQL/image-20240130140723465.png)
#### 增量备份
```shell
innobackupex --user=root --password=123456 --host=127.0.0.1 --incremental ~/mysql_bakup/ --incremental-basedir=~/mysql_bakup/2024-01-30_14-03-42/
```
![image-20240130151257100](MySQL/image-20240130151257100.png)
增量备份需要使用参数--incremental指定需要备份到哪个目录使用incremental-dir指定全备目录
查看备份数据
![image-20240130172206916](MySQL/image-20240130172206916.png)
## 恢复 ## 恢复
#### 全量备份恢复
```shell
# 停止目标服务器上的mysql
systemctl stop mysqld
```
![image-20240130142057208](MySQL/image-20240130142057208.png)
同步服务器上的备份文件至本地
```shell
# 同步服务器上的备份文件夹至本地
rsync -av root@10.0.3.3::mysql_bakup ~/mysql_bakup
```
![image-20240130142150299](MySQL/image-20240130142150299.png)
创建本地数据目录备份
```shell
cp -r /var/lib/mysql /var/lib/mysqlbakup
```
合并数据日志,使数据文件处于一致性的状态
```shell
innobackupex --apply-log ~/mysql_bakup/2024-01-30_14-03-42/
```
![image-20240130142410127](MySQL/image-20240130142410127.png)
删除数据目录
```shell
rm -rf /var/lib/mysql
```
进行数据恢复
```shell
innobackupex --copy-back 2024-01-30_14-03-42/
```
![image-20240130142551097](MySQL/image-20240130142551097.png)
赋予权限
```shell
chown mysql:mysql /var/lib/mysql -R
```
临时关闭SELinux
```she
setenforce 0
```
永久关闭SELinux
#### 增量备份恢复
```shell
# 停止目标服务器上的mysql
systemctl stop mysqld
```
![image-20240130142057208](MySQL/image-20240130142057208.png)
删除数据目录
```shell
rm -rf /var/lib/mysql
```
合并全备数据目录,确保数据的一致性
```shell
innobackupex --apply-log --redo-only ~/mysql_bakup/2024-01-30_14-03-42/
```
将增量备份数据合并到全备数据目录当中
```shell
innobackupex --apply-log --redo-only ~/mysql_bakup/2024-01-30_14-03-42/ --incremental-dir=~/mysql_bakup/2024-01-30_15-12-28/
```
恢复数据
```shell
innobackupex --copy-back ~/mysql_bakup/2024-01-30_14-03-42/
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB