从 AWS AMI 恢复 mysql db?

从 AWS AMI 恢复 mysql db?

我们有一个运行 mysql 数据库服务器的 EC2 实例。

由于安全事故,我们不得不删除当前的 EC2 实例,因为数据库被某种加密彻底搞乱了。

因此,我们必须从每 6 小时拍摄一次的快照/AMI 中恢复它。我们有过去 1 个月的快照和 AMI 可用于此 EC2 实例。

该 EC2 实例只有一个 SSD(持久块存储)EBS 卷,它是快照/AMI 的一部分。

我们也安装了 phpmyadmin,但由于显而易见的原因,它无法连接到 DB!

以下是操作系统和mysql服务状态的详细信息。

# 猫 /etc/发布

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

#mysqld--版本

/usr/sbin/mysqld  Ver 8.0.22-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))

#systemctl 状态 mysql.service

● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: activating (start) since Mon 2021-03-01 13:19:50 UTC; 241ms ago
    Process: 79728 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 79736 (mysqld)
     Status: "Server startup in progress"
      Tasks: 1 (limit: 1164)
     Memory: 91.3M
     CGroup: /system.slice/mysql.service
             └─79736 /usr/sbin/mysqld

Mar 01 13:19:50 ip-172-31-93-250 systemd[1]: Starting MySQL Community Server...
Mar 01 13:19:52 ip-172-31-93-250 systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
Mar 01 13:19:52 ip-172-31-93-250 systemd[1]: mysql.service: Failed with result 'exit-code'.
Mar 01 13:19:52 ip-172-31-93-250 systemd[1]: Failed to start MySQL Community Server.
Mar 01 13:19:53 ip-172-31-93-250 systemd[1]: mysql.service: Scheduled restart job, restart counter is at 328.
Mar 01 13:19:53 ip-172-31-93-250 systemd[1]: Stopped MySQL Community Server.
Mar 01 13:19:53 ip-172-31-93-250 systemd[1]: Starting MySQL Community Server...

# journalctl -xe

Mar 01 13:14:20 ip-XXX-XXX-XXX-XXX systemd[1]: mysql.service: Main process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- An ExecStart= process belonging to unit mysql.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
Mar 01 13:14:20 ip-XXX-XXX-XXX-XXX systemd[1]: mysql.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- The unit mysql.service has entered the 'failed' state with result 'exit-code'.
Mar 01 13:14:20 ip-XXX-XXX-XXX-XXX systemd[1]: Failed to start MySQL Community Server.
-- Subject: A start job for unit mysql.service has failed
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit mysql.service has finished with a failure.
--
-- The job identifier is 105083 and the job result is failed.
Mar 01 13:14:21 ip-XXX-XXX-XXX-XXX systemd[1]: mysql.service: Scheduled restart job, restart counter is at 206.
-- Subject: Automatic restarting of a unit has been scheduled
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- Automatic restarting of the unit mysql.service has been scheduled, as the result for
-- the configured Restart= setting for the unit.
Mar 01 13:14:21 ip-XXX-XXX-XXX-XXX systemd[1]: Stopped MySQL Community Server.
-- Subject: A stop job for unit mysql.service has finished
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A stop job for unit mysql.service has finished.
--
-- The job identifier is 105149 and the job result is done.
Mar 01 13:14:21 ip-XXX-XXX-XXX-XXX systemd[1]: Starting MySQL Community Server...
-- Subject: A start job for unit mysql.service has begun execution
-- Defined-By: systemd
-- Support: http://www.ubuntu.com/support
--
-- A start job for unit mysql.service has begun execution.
--
-- The job identifier is 105149.

对于额外的日志输出“# tail -500 /var/log/mysql/error.log”

你们有人能帮助我恢复带有数据/数据库的 mysql 服务吗?

我们不确定在这种情况下应遵循什么正确的程序来恢复数据库。

提前致谢!

答案1

要解决此问题,您只需执行以下操作:

只需编辑/etc/mysql/mysql.conf.d/mysqld.cnf使用您喜欢的编辑器打开文件,并使用您喜欢的编辑器更新绑定地址。下面是您需要使用正确/更新的 IP 地址进行更新的行。因为当您使用备份 AMI 映像或快照启动新的 EC2 实例时,它会获得一个新的私有 IP 地址(除非您之前已在操作系统配置中将其设为静态。)

绑定地址 = 192.168.XXX.XXX

然后使用以下命令重新启动 mysql 服务,一切都将像以前一样开始工作,包括 PHP My Admin 控制台。

systemctl 重新启动 mysql.service

相关内容