[2003] Can’t connect to MySQL server on ‘localhost'(13)

LOG:Jan 17 23:46:46 s1 setroubleshoot: SELinux is preventing the http daemon from connecting to network port 3306 For complete SELinux messages. run sealert -l ed55546b-97a3-4eea-9cf2-9aa2b6fce245

看得出是selinux的问题。

根据日志提示,开始解决。

[root@s1 ~]# sealert -l ed55546b-97a3-4eea-9cf2-9aa2b6fce245

摘要:

SELinux is preventing the http daemon from connecting to network port 3306

详细的描述:

SELinux has denied the http daemon from connecting to 3306. An httpd script is
trying to do a network connect to a remote port. If you did not setup httpd to
network connections, this could signal a intrusion attempt.

正在允许访问:

If you want httpd to connect to network ports you need to turn on the
httpd_can_network_network_connect boolean: “setsebool -P
httpd_can_network_connect=1”

以下命令将允许这个权限:

setsebool -P httpd_can_network_connect=1

附加的信息:

源上下文                  root:system_r:httpd_t
目标上下文               system_u:object_r:mysqld_port_t
目标对象                  None [ tcp_socket ]
Source                        httpd
Source Path                   /usr/sbin/httpd
Port                          3306
Host                          s1
Source RPM Packages           httpd-2.2.3-43.el5
Target RPM Packages
策略 RPM                    selinux-policy-2.4.6-279.el5
Selinux 激活                True
策略类型                  targeted
MLS 激活                    True
强制模式                  Enforcing
插件名称                  httpd_can_network_connect
主机名                     s1
平台                        Linux s1 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:43
                              EDT 2010 i686 i686
警告记数                  27
First Seen                    Mon Jan 17 23:41:16 2011
Last Seen                     Tue Jan 18 00:05:35 2011
Local ID                      ed55546b-97a3-4eea-9cf2-9aa2b6fce245
行数

原始 Audit 消息

host=s1 type=AVC msg=audit(1295280335.304:112): avc:  denied  { name_connect } f                                              or  pid=4718 comm=”httpd” dest=3306 scontext=root:system_r:httpd_t:s0 tcontext=s                                              ystem_u:object_r:mysqld_port_t:s0 tclass=tcp_socket

host=s1 type=SYSCALL msg=audit(1295280335.304:112): arch=40000003 syscall=102 su                                              ccess=no exit=-13 a0=3 a1=bf8c5a20 a2=3fbe6f8 a3=2 items=0 ppid=4716 pid=4718 au                                              id=0 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none)                                               ses=2 comm=”httpd” exe=”/usr/sbin/httpd” subj=root:system_r:httpd_t:s0 key=(null                                              )

[root@s1 ~]# setsebool -P httpd_can_network_connect=1

[root@s1 ~]#

再次访问,解决。

[warn] NameVirtualHost 1.1.1.2:80 has no VirtualHosts

[warn] NameVirtualHost 1.1.1.2:80 has no VirtualHosts

在阿帕奇中配置的虚拟主机,重启服务的时候报以上的错误。

配置文件如下:

NameVirtualHost 1.1.1.2:80
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#

<VirtualHost www2.dz.com:80>
Serveradmin
venuslinux@gmail.com
Servername www2.dz.com
Documentroot /wz/dz
Errorlog logs/error_log
Customlog logs/access_log common
Directoryindex index.php
</VirtualHost>

网上搜索的结果大多都是因为namevirtualhost 配置了多遍,导致的错误,但是我就配置了一次。

然后有一条解决方法还靠谱,屏蔽这一行试试,结果可以,但是郁闷中,这是为啥子呢?

随后用dig解析www2.dz.com 随后发现忘记配置dns,加上后,然后又解除namevirtualhost屏蔽后,重启OK了。原来是因为阿帕奇重启的时候会去查询虚拟主机的信息,因为是基于域名的虚拟主机嘛。