尝试连接到Mysql安装mediawiki时权限被拒绝


Permission denied when trying to connect to Mysql installing mediawiki

我整个下午都有一个问题,我很难解决,所以,让我们来解释一下。

我正在运行MariaDB,它是Fedora Linux分发版的mysql的一部分。我正试图在我的本地机器上安装一个需要数据库后端的php-cms,所以我已经创建了数据库(这不是第一次了,所以我应该知道我在做什么),比方说它叫myDb好吗?然后我创建了用户,比方说myDbUser@localhost好啊然后将数据库上的权限授予用户(GRANT ALL是特定的)。然后,我从数据库的命令行测试了用户和授予的权限,一切都很好,我可以登录,我可以看到数据库。

然后我运行cms的安装脚本,好吗?

Database type:  MySQL (or compatible)
Database host: localhost
Database name: myDb
Database username: myDbUser
Database password: passowrd

与在命令行中工作的数据相同。但结果是:

DB connection error: Permission denied (localhost).
Check the host, username and password and try again. 

假设用户名和密码在命令行中运行良好,我认为这是"主机"的问题。。

所以我花了整整一个晚上的时间试图了解它出了什么问题,我唯一想到的(我知道它不多)是这个命令的输出:

netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:2393            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN   

我尝试了所有这些IP,但没有成功。我总是犯同样的错误,所以有什么想法、暗示、线索,甚至是其中的一部分吗?谢谢

编辑:所以进一步的研究表明,这个问题不是数据库问题,而是CMS问题。这是因为我可以使用给定的用户和密码从命令行连接到数据库。

第二版:其他研究表明,这个问题可能是权限问题。我从机器的根用户登录到数据库,但Web服务器正在从其他用户访问它。我仍然不知道如何解决这个问题。

编辑3:这是apache服务器的日志文件:

/var/www/html/Wiki/includes/limit.sh: line 61: ulimit: cpu time: cannot modify limit: Permission denied
/var/www/html/Wiki/includes/limit.sh: line 90: ulimit: file size: cannot modify limit: Permission denied

有人以前遇到过类似的问题,可以帮忙吗?我有这两个链接:12但它们似乎对我没有更多帮助,因为我不明白为什么这个脚本不能运行这些命令。

如果您不熟悉MySQL权限的工作方式,只需向MediaWiki安装程序提供根密码,它就会为自己创建具有正确权限的用户。

您可以尝试使用'%'而不是localhost来授予权限,如'youUser'@'%'。这应该行得通。

事实证明,这根本不是MySql或PHP的问题。相反,这是一个安全问题,服务器没有访问mysql通道的权限。我不得不使用以下命令修复它:

              # grep httpd /var/log/audit/audit.log | audit2allow
              # semodule -i mypol.pp

我真的很难找到这个解决方案,我不得不用journalctl(一个我以前不知道的命令)寻找系统消息。所以这是一个大皮塔,但我最终发现了。

因此,如果有人会有类似的问题,至少答案是存在的。

实际上,您需要的是

setsebool -P httpd_can_network_connect_db 1

我总是,每一个!仅有一个的时间在设置新主机时遇到一个或多个selinux问题。每次我都会在谷歌上搜索这个问题,通常是几个小时,然后我就会运行sealert-a并自己处理它。

所以,你必须稍微了解如何阅读

sealert -a /var/log/audit/audit.log

它向您展示了应用的grep解决方案。你需要进一步阅读。您的输出如下所示(注意问题,第一条粘贴的线,以及他们自信的建议解决方案,您选择的解决方案相当不足):

SELinux is preventing /usr/sbin/httpd from name_connect access on the tcp_socket .
*****  Plugin catchall_boolean (47.5 confidence) suggests  *******************
If you want to allow HTTPD scripts and modules to connect to the network using TCP.
Then you must tell SELinux about this by enabling the 'httpd_can_network_connect'boolean.
Do
setsebool -P httpd_can_network_connect 1
*****  Plugin catchall_boolean (47.5 confidence) suggests  *******************
If you want to allow HTTPD scripts and modules to connect to databases over the network.
Then you must tell SELinux about this by enabling the 'httpd_can_network_connect_db'boolean.
Do
setsebool -P httpd_can_network_connect_db 1
*****  Plugin catchall (6.38 confidence) suggests  ***************************
If you believe that httpd should be allowed name_connect access on the  tcp_socket by default.
Then you should report this as a bug.
You can generate a local policy module to allow this access.
Do
allow this access for now by executing:
# grep httpd /var/log/audit/audit.log | audit2allow -M mypol
# semodule -i mypol.pp

Additional Information:
Source Context                unconfined_u:system_r:httpd_t:s0
Target Context                system_u:object_r:mysqld_port_t:s0
Target Objects                 [ tcp_socket ]
Source                        httpd
Source Path                   /usr/sbin/httpd
Port                          3306
Host                          <Unknown>
Source RPM Packages           httpd-2.2.15-54.el6.centos.x86_64
Target RPM Packages
Policy RPM                    selinux-policy-3.7.19-292.el6.noarch
Selinux Enabled               True
Policy Type                   targeted
Enforcing Mode                Enforcing
Host Name                     publicsrv
Platform                      Linux publicsrv 2.6.32-642.el6.x86_64 #1 SMP Tue
                              May 10 17:27:01 UTC 2016 x86_64 x86_64
Alert Count                   26
First Seen                    Sat 01 Oct 2016 09:14:01 PM EEST
Last Seen                     Sat 01 Oct 2016 11:23:12 PM EEST
Local ID                      064b82b4-2e50-42ea-9a07-11468d0a62a6
Raw Audit Messages
type=AVC msg=audit(1475353392.72:578): avc:  denied  { name_connect } for  pid=5858 comm="httpd" dest=3306 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=system_u:object_r:mysqld_port_t:s0 tclass=tcp_socket

type=SYSCALL msg=audit(1475353392.72:578): arch=x86_64 syscall=connect success=no exit=EACCES a0=e a1=7f0cd22a6008 a2=10 a3=40 items=0 ppid=5852 pid=5858 auid=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=1 comm=httpd exe=/usr/sbin/httpd subj=unconfined_u:system_r:httpd_t:s0 key=(null)
Hash: httpd,httpd_t,mysqld_port_t,tcp_socket,name_connect
audit2allow
#============= httpd_t ==============
#!!!! This avc can be allowed using one of the these booleans:
#     httpd_can_network_connect, httpd_can_network_connect_db
allow httpd_t mysqld_port_t:tcp_socket name_connect;
audit2allow -R
#============= httpd_t ==============
#!!!! This avc can be allowed using one of the these booleans:
#     httpd_can_network_connect, httpd_can_network_connect_db
allow httpd_t mysqld_port_t:tcp_socket name_connect;