设为首页 收藏本站
查看: 1497|回复: 1

[经验分享] linux环境中cacti安装:

  [复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-5-9 10:51:14 | 显示全部楼层 |阅读模式
这是一个学习过程中笔记,如果有大部分雷同,则说明你和我肯定是同学,只是不认识吧了!
cacti概述

    cacti使用php语言来实现的一款软件,主要功能是用snmp服务获取相关数据,然后用rrdtool存储和更新数据在有需要时用rrdtool生成图标供用户查看相关数据,因此,snmp和rrdtool是cacti的关键。snmp关系着数据的收集,rrtdool关系着数据的存储和图表的生成。

    mysql搭配php程序用来存储一些变量数据并对变量数据进行调用,如主机名,主机ip,snmp团体名,端口号,模版信息等变量。而snmp抓取到数据后不是存储在mysql中,而是存储在rrtdool生成的RRD文件中(在Cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对RRD文件的处理。RRD文件是大小固定的档案文件(Round Robin Archive),能够存储的数据量在创建时已经定义。
    下图是cacti的架构:

wKioL1ct8RLz7OF0AABszGTO_wI529.jpg
    下图是cacti的工作模式:

wKioL1ct8TCSfab5AAB6BQ6sYtw536.jpg
cacti的部署:

   因为cacti依赖于lnmp环境,因此在部署cacti之前首先需要搭建lnmp环境。

首先我们借助yum安装的方式安装mysql,apache,php及相关插件:
1
yum install -y  httpd php php-mysql mysql mysql-server mysql-devel php-gd  libjpeg libjpeg-devel libpng libpng-devel



    启动http,如下:
1
2
3
4
5
6
7
8
9
10
11
[iyunv@lvs ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 211.98.71.195 for ServerName
                                                           [  OK  ]
/启动http的时候会出现如上问题,解决办法如下:                                             
[iyunv@lvs ~]# vim /etc/httpd/conf/httpd.conf   
  /打开这个文件,把其中的#ServerName  修改为 ServerName localhost:80

然后在重启一下:
  [iyunv@lvs ~]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]



    启动mysql:如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
[iyunv@lvs ~]# /etc/init.d/mysqld start
Initializing MySQL database:  Installing MySQL system tables...
160508  3:37:29 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
160508  3:37:29 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h lvs password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]



    安装cacti及其所需要的插件:(我们在这里部署的是主监控机,暂时并没有客户端)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
[iyunv@lvs ~]#  yum install -y cacti  net-snmp  net-snmp-utils  rrdtool net-snmp-devel net-snmp-libs lm-sensors php-xml zlib libpng freetype cairo-devel pango-devel gd

[iyunv@lvs ~]# /etc/init.d/snmpd start           /启动snmp服务
Starting snmpd:                                            [  OK  ]

[iyunv@lvs ~]# mysql -u root                /mysql数据库
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73-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> create database cacti;                  /创建cacti数据库!
mysql> grant all on cacti.* to 'cactiuser'@'localhost' identified by 'cactiuser';  /创建用户,并且给用户授权。
Query OK, 0 rows affected (0.00 sec)
mysql> use cacti;                    /选择cacti数据库
Database changed
mysql> source /usr/share/doc/cacti-0.8.8b/cacti.sql;    /导入sql文件
Query OK, 0 rows affected (0.01 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 0 rows affected (0.04 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.01 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

Query OK, 1 row affected (0.00 sec)

·········
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye



   编辑cacti配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@lvs ~]# vim /usr/share/cacti/include/config.php
·····
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";      /在数据库中授权时的名字及密码
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;
·····
[iyunv@lvs ~]# vim /etc/httpd/conf.d/cacti.conf
Deny from all 修改为 Allow from all
[iyunv@lvs ~]# /etc/init.d/httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]



然后就是web访问,在浏览器中输入http://ip/cacti!在浏览器访问的时候,总会出现如下问题
1
FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php'



当初一直觉得是数据库授权的问题,然后各种检测也没有错误,后来一条命令解决了如下:
1
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock



正常之后,在浏览器输入http://ip/cacti会出现如下界面:
wKioL1ct-grBAGSJAAA_sFH8dro593.jpg
这一步直接next,然后会出现如下界面:
wKioL1ct-irypAmaAAAZuSVowHs625.jpg
因为我们是第一次安装,所以选择新安装,然后next:出现如下界面:
wKioL1ct-paRQxb8AAF0xj-M20U189.jpg
这一步我们看见各种文件的位置,若是全部显示Found,则可以直接点击finish,若不是可以自己找到合适的位置,一般都是默认即可!下一步:
wKiom1ct-hHzsnX4AABlW87YbDc330.jpg
输入帐号和密码,都为admin,默认的,然后下一步会强制修改密码:
wKiom1ct-myAYh_1AABm1cmJWQ8730.jpg
点击save,然后进入下一步: wKioL1ct-2TR2F3OAACME7HeBH0969.jpg
点击左边的settings----path打开控制台,如下图:

wKioL1ct-9_wOWM2AADuerba49s316.jpg 点击graps进入监控系统界面,发现并没有图形如下图:
wKioL1ct_CqiPdqxAACrdVlFmk8321.jpg 这时候我们运行如下命令生成图形:
1
2
3
4
5
6
7
8
[iyunv@lvs ~]# /usr/bin/php /usr/share/cacti/poller.php
PHP Warning:  strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/share/cacti/include/global_constants.php on line 165
PHP Warning:  date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/share/cacti/include/global_constants.php on line 165
tifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/share/cacti/include/global_constants.php on line 166

·······/过程很长,结束时我们可以查看一下命令返回值!
[iyunv@lvs ~]# echo $?
0                          /返回数字“0”说明,命令运行结果正确



这时候在查看一下监控图像会发现如下图:
wKiom1ct_CDTbjzhAAFe8jPFsBg750.jpg
会发现已经出现了坐标,但是没有图像;我们刚才运行的命令,写入计划任务:
1
2
3
4
5
[iyunv@lvs ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[iyunv@lvs ~]# crontab -l
*/5 * * * * /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1



过一段时间之后会发现已经出现图形如下:因为自己的模拟机负载不是很高,这一段时间会挺长的!
wKiom1ct_NbTpY8SAAFvXxVD7Ag574.jpg         
至此我们也就搭建完成了cacti的监控!对于cacti的应用及cacti怎么添加监控客户端,会在后续的博文中继续更新的!


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-214680-1-1.html 上篇帖子: cacti安装配置 下篇帖子: snmp error linux
累计签到:67 天
连续签到:1 天
发表于 2016-5-23 17:43:25 | 显示全部楼层
本帖最后由 jxcia 于 2016-5-23 17:46 编辑

楼主有个小错误 是LAMP。。。
另外请教楼主几个问题;
增加客户端后,cpu  、MEMORY 等都可以正常出现图片,只有负载不出现,求指教?
已经尝试添加多台监控,问题依旧。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表