免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3019 | 回复: 1
打印 上一主题 下一主题

[其他] cacti安装后可以连接127.0.0.1的mysql但不能连接localhost的mysql问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-08-11 12:40 |只看该作者 |倒序浏览
小弟初学cacti,在yum方式搭建的lamp平台上安装并进行配置后,访问cacti首页准备进行安装时发现cacti的全局配置文件中定义mysql的hostname
是localhost时连接mysql失败,把hostname改成127.0.0.1就可以
个人认为mysql授权、本机hosts记录和cacti的config.php配置均没有问题,望大虾门指点,拜谢!

问题详情:
1、mysql授权 针对cacti.*赋予cacti@localhost全部权限
mysql> show grants for cacti@'localhost';
+--------------------------------------------------------------------------------------------------------------+
| Grants for cacti@localhost                                                                                   |
+--------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'cacti'@'localhost' IDENTIFIED BY PASSWORD '*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9' |
| GRANT ALL PRIVILEGES ON `cacti`.* TO 'cacti'@'localhost'                                                     |
+--------------------------------------------------------------------------------------------------------------+
2 rows in set (0.01 sec)

2、cacti的config.php设置 访问localhost的cacti库,口令信息与mysql授权记录保持一致
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "123456";
$database_port = "3306";
$database_ssl = false;

3、本地hosts记录和解析
[root@maxwell ~]# cat /etc/hosts
127.0.0.1   localhost
127.0.0.1   maxwell.com
::1         localhost

[root@maxwell ~]# ping localhost
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.097 ms
^C
--- localhost ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 997ms
rtt min/avg/max/mdev = 0.097/0.097/0.097/0.000 ms

4、直接通过cacti用户bash连接mysql的成功记录
[root@maxwell ~]# mysql -h localhost -u cacti -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.63-log Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

5、报错现象信息
本机ip
[root@maxwell ~]# ifconfig
eth1      Link encap:Ethernet  HWaddr 00:0C:29:1C:0F:79  
          inet addr:192.168.58.128  Bcast:192.168.58.255  Mask:255.255.255.0

访问本机页面192.168.58.128/cacti
FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'

6、调试过程
我把cacti config.php文件中的$database_hostname改成127.0.0.1之后就可以正常打开页面提示进行下一步的安装,实在是没明白127.0.0.1与localhost的区别在哪,况且我的mysql授权也是直接针对localhost来做的。

之前查询过部分帖子说是mysql的授权有误,但我这里看不出什么问题,另外也有说mysql的socket文件有问题的,但我的socket文件在tmp下,实际配置文件也是这样指定的。原来做这个实验按照参考文档相同的方式一路走下来就没有遇到这个问题,真心搞不懂了,求大神赐教,先在此谢过!

论坛徽章:
0
2 [报告]
发表于 2015-08-11 14:29 |只看该作者
自己回复下吧,问题已经解决。

yum安装方式下mysql的socket路径在tmp下,而php配置文件中默认制定的mysql的socket路径在var lib mysql下,通过localhost连接时需要调用socekt文件,这时由于两边的socket路径不一致就导致连接失败,127情况下不调用socket文件
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP