FAQ: mysqld_safe mysqld from pid file xxx.pid ended

处理一个兼职人员部署的服务器故障

1.php故障

Warning: require_once(ROOTPATHconfig/bluebee.inc.php): failed to open stream: No such file or directory in /web/code/mygym/mygym_pc/include/head.php on line 23

Fatal error: require_once(): Failed opening required 'ROOTPATHconfig/bluebee.inc.php' (include_path='.:/usr/local/php54/lib/php') in /web/code/mygym/mygym_pc/include/head.php on line 23

boss反馈,一个兼职人员开发部署的项目,出现了这个问题,根据经验初步判断,是文件不存在了,或者目录没有权限,登录之后发现,这个phper根本没有linux基础,以及不懂php-fpm运行机制,文件用户和组是 nginx 然后给了777权限

解决方法

service php-fpm status 显示 php-fpm 是www 用户跑的,但是当前服务器没有该用户

执行如下命令,创建www用户并加入www用户组

命令参考

groupadd www
useradd -g www -M -s /sbin/nologin www

更改代码目录权限

//更改用户组
chown -R www.www /web/code
//更改目录权限
chmod -R 755 /web/code
文件权限根据情况可以给644

2.php报错提示mysql连接失败

service mysqld status 显示启动失败,查看/var/log/mysqld.log 日志 报错如下

mysqld_safe mysqld from pid file /var/lib/mysql/mysqld.pid ended

/etc/my.cnf配置如下

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html

[mysqld]
skip-grant-tables
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

发现是使用rpm包使用的社区版安装的。

尝试了各种发,都没有用,最后参考如下问答解决

https://stackoverflow.com/questions/33984848/mysqld-safe-mysqld-from-pid-file-var-run-mysqld-mysqld-pid-prevent-from-server

restorecon -r /var/lib/mysql
service mysqld start

原因分析

可能是 /var/lib/mysql 目录,用户组 不是 mysql,

移动复制或修改文件时导致了 SELinux文件属性 丢失

首先保证 mysql 数据目录/var/lib/mysql 用户组 必须是 mysql

然后使用 restorecon 恢复文件的安全上下文

restorecon指令参考