- 论坛徽章:
- 0
|
小弟初学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下,实际配置文件也是这样指定的。原来做这个实验按照参考文档相同的方式一路走下来就没有遇到这个问题,真心搞不懂了,求大神赐教,先在此谢过! |
|