RHEL 实例上的初始 MySQL 5.7 安装无法启动

RHEL 实例上的初始 MySQL 5.7 安装无法启动

我在 AWS 上的 AMI 上使用 Chef 进行了标准 MySQL 安装。方法如下:

mysql_service 'default' do
  bind_address '0.0.0.0'
  port '3306'
  version '5.7'
  initial_root_password 'hunter2'
  action [:create, :start]
end

mysql_config 'default' do
  source 'mysite.cnf.erb'
  notifies :restart, 'mysql_service[default]'
  action :create
end

在纠正了一些自己造成的问题(安装前没有更新 Yum)后,配方现在运行正常,但有些地方不行。在最后一步,也就是应该启动 MySQL 的地方,它失败了。这似乎是 Chef 的错误,因为我在 Chef 之外执行以下操作:

 sudo /usr/bin/mysqld_safe    

输出结果如下sudo systemctl status mysql-default.service -l

[ec2-user@ip-250-250-250-250 ~]$ sudo systemctl status mysql-default.service -l
mysql-default.service - mysql_service[mysql-default]
   Loaded: loaded (/usr/lib/systemd/system/mysql-default.service; enabled)
   Active: failed (Result: exit-code) since Sun 2014-12-21 17:36:01 EST; 21min ago
  Process: 26423 ExecStartPost=/usr/libexec/mysql-default-wait-ready $MAINPID (code=exited, status=1/FAILURE)
  Process: 26422 ExecStart=/usr/bin/mysqld_safe --defaults-file=/etc/mysql-default/my.cnf --basedir=/usr (code=exited, status=0/SUCCESS)
 Main PID: 26422 (code=exited, status=0/SUCCESS)

Dec 21 17:36:00 ip-250-250-250-250.us-west-2.compute.internal mysqld_safe[26422]: /usr/bin/mysqld_safe: line 542: /var/lib/mysql-default/mysqld_safe.pid: Permission denied
Dec 21 17:36:00 ip-250-250-250-250.us-west-2.compute.internal mysqld_safe[26422]: awk: (FILENAME=- FNR=2) warning: error writing standard output (Broken pipe)
Dec 21 17:36:00 ip-250-250-250-250.us-west-2.compute.internal mysqld_safe[26422]: 141221 17:36:00 mysqld_safe Logging to '/var/log/mysql-default/error.log'.
Dec 21 17:36:00 ip-250-250-250-250.us-west-2.compute.internal mysqld_safe[26422]: 141221 17:36:00 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql-default
Dec 21 17:36:00 ip-250-250-250-250.us-west-2.compute.internal mysqld_safe[26422]: 141221 17:36:00 mysqld_safe mysqld from pid file /var/run/mysql-default/mysqld.pid ended
Dec 21 17:36:01 ip-250-250-250-250.us-west-2.compute.internal systemd[1]: mysql-default.service: control process exited, code=exited status=1
Dec 21 17:36:01 ip-250-250-250-250.us-west-2.compute.internal systemd[1]: Failed to start mysql_service[mysql-default].
Dec 21 17:36:01 ip-250-250-250-250.us-west-2.compute.internal systemd[1]: Unit mysql-default.service entered failed state.

似乎很明显这是 /var/lib/mysql-default 上的某种权限问题,但我正在运行它,所以sudo我不确定问题是什么。以下是目录输出:

[...]
drwxr-xr-x.  2 mysql   mysql      6 Sep 18 10:07 mysql
drwxr-x---.  4 mysql   mysql   4096 Dec 21 17:36 mysql-default
[...]

是。中的相关行$DATADIR是:/var/lib/mysql-default/usr/bin/mysql_safe

safe_pid="$DATADIR/mysqld_safe.pid"

[ ... bunch of error checking ...]

# Insert pid properly into the pid file.
ps -e | grep  [m]ysqld_safe | awk '{print $1}' | sed -n 1p > $safe_pid

有什么想法吗?

答案1

/usr/bin/mysqld_safe:第 542 行:/var/lib/mysql-default/mysqld_safe.pid:权限被拒绝

你是对的,该进程失败是因为它无法写入 pid 文件。

尽管你使用 运行启动脚本sudo,但服务器进程很可能由用户 启动mysql。在默认配置中, 中应该有一行这样的代码mysqld_safe

用户='mysql'

使用以下命令检查所有者和权限/var/lib/mysql-default

ls -ld /var/lib/mysql-default

正常情况下,它应该由与配置文件中的同一用户拥有,并具有权限 755。

相关内容