注:最新版本的cacti对于LAMP的要求更高,特别是mysql数据库的要求,多方尝试发现用10版本以上的mariadb是最简单的。

1.安装LAMP架构

由于系统自带的是MariaDB5.5需要卸载 [root@localhost ~]# rpm -qa mariadb-libs-5.5.60

[root@localhost ~]# yum remove mariadb-libs-5.5.60 -y

添加MariaDB、yum源

vim /etc/yum.repos.d/Mariadb.repo

[MariaDB]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.3/centos7-amd64/
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

[root@localhost yum.repos.d]# yum clean all && yum makecache

[root@localhost yum.repos.d]#

yum install httpd MariaDB-client MariaDB-server MariaDB-devel php-snmp php-ldap php-pdo php-mysql php-devel php-pear php-common php-gd php-mbstring php-xml php-process net-snmp net-snmp-utils net-snmp-libs net-snmp-agent-libs net-snmp-devel rrdtool rrdtool-php rrdtool-perl rrdtool-devel gcc openssl-devel dos2unix autoconf automake binutils libtool cpp postfix glibc-headers kernel-headers glibc-devel gd gd-devel help2man ntpdate wget patch

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf ServerName 127.0.0.1:80 #去掉注释 DocumentRoot "/var/www/html" [root@localhost ~]# vim /etc/httpd/conf.d/cacti.conf

Alias /cacti /var/www/html/ <Directory /var/www/html/> DirectoryIndex index.php Options -Indexes AllowOverride all order deny,allow allow from all AddType application/x-httpd-php .php php_flag magic_quotes_gpc on php_flag track_vars on </Directory>

[root@localhost ~]# vim /etc/httpd/conf.d/php.conf LoadModule php5_module modules/libphp5.so

[root@localhost~]# vim /etc/php.ini safe_mode = off //在[PHP]下加 date.timezone = PRC //查找修改

[root@localhost~]# systemctl stop firewalld.service [root@localhost~]# systemctl disable firewalld.service [root@localhost~]# setenforce 0 [root@localhost~]# systemctl start httpd.service [root@localhost~]# systemctl start mariadb.service

[root@localhost~]# mysql_secure_installation //按照提示初始设置mariadb,设置密码,移除匿名用户、开放root远程登录、刷新权限

[root@localhost ~]# vim /etc/my.cnf.d/server.cnf

character_set_server = utf8mb4 collation_server = utf8mb4_unicode_ci character_set_client = utf8mb4 max_connections = 100 max_heap_table_size = 256M max_allowed_packet = 16777216 join_buffer_size = 64M tmp_table_size = 64M innodb_file_per_table = ON innodb_buffer_pool_size = 1024M innodb_doublewrite = OFF innodb_lock_wait_timeout = 50 innodb_flush_log_at_timeout = 3 innodb_read_io_threads = 32 innodb_write_io_threads = 16

[root@localhost~]# mysql -uroot –p //登录数据库为测试账号cacti授权 MariaDB [(none)]> CREATE DATABASE cacti character set utf8 collate utf8_bin; MariaDB [(none)]> GRANT all ON cacti.* TO 'cacti'@'localhost' IDENTIFIED BY 'admin123'; MariaDB [(none)]> flush privileges;

---------下面可以开始安装cacti-------------- 官网网站:https://www.cacti.net

[root@localhost ~]# wget https://www.cacti.net/downloads/cacti-1.1.26.tar.gz
[root@localhost ~]# wget https://www.cacti.net/downloads/spine/cacti-spine-1.1.26.tar.gz [root@localhost~]# tar xf cacti-1.1.26.tar.gz [root@localhost~]# mv cacti-1.1.26 /var/www/html/cacti [root@localhost html]# chown -R root.root cacti/ [root@localhost~]# mysql -uroot -p cacti < /var/www/html/cacti/cacti.sql Enter password: //密码为admin123,将cacti的数据库导入 [root@localhost~]# mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot mysql -p Enter password: //密码为admin123,1.1.26版本的cacti需要导入时间数据库 [root@localhost~]# mysql -uroot –p //为cacti用户赋予时间数据库的权限 MariaDB [(none)]> grant select on mysql.time_zone_name to 'cacti'@'localhost' IDENTIFIED BY 'admin123'; MariaDB [(none)]> flush privileges; [root@localhost~]# vim /var/www/html/cacti/include/config.php $database_type = 'mysql'; $database_default = 'cacti'; $database_hostname = 'localhost'; $database_username = 'cacti'; $database_password = 'admin123'; $database_port = '3306'; $database_ssl = false; [root@localhost~]# vim /etc/snmp/snmpd.conf com2sec notConfigUser localhost public //改成环回口地址 41 access notConfigGroup "" any noauth exact all none none //把systemview改成all 62 view all included .1 80 // 去掉#号 85 [root@localhost~]# systemctl restart snmpd.service [root@localhost~]# systemctl enable snmpd.service [root@localhost~]#chown -R apache.apache /var/www/html/cacti/rra/ [root@localhost~]#chown -R apache.apache /var/www/html/cacti/log/ [root@localhost~]#chown -R apache.apache /var/www/html/cacti/resource/ [root@localhost~]#chown -R apache.apache /var/www/html/cacti/cache [root@localhost~]#chown -R apache.apache /var/www/html/cacti/scripts

-----------安装cacti-spine优化数据轮询速度----- 新版的cacti可以不使用php脚本去采集数据,新集成了一个插件spine用于采集数据 [root@localhost ~]# ln -s /usr/lib64/libmysqlclient.so.18.0.0 /usr/lib64/libmysqlclient.so [root@localhost ~]# tar xf cacti-spine-1.1.26.tar.gz [root@localhost ~]# cd cacti-spine-1.1.26 [root@localhost cacti-spine-1.1.26]# ./configure [root@localhost cacti-spine-1.1.26]# make -j 2 && make install [root@localhost ~]# cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf [root@localhost ~]# vim /usr/local/spine/etc/spine.conf //修改相关参数 DB_Host localhost DB_Database cacti DB_User cacti DB_Pass admin123 DB_Port 3306

RDB_Host localhost RDB_Database cacti RDB_User cacti RDB_Pass admin123 RDB_Port 3306

[root@localhost cacti]# crontab –e */5 * * * * /usr/bin/php /var/www/html/cacti/poller.php >> /tmp/cacti_rrdtool.log