首先,先安裝LNMP服務php
安裝一:html
若是以爲安裝起來麻煩,能夠到以下網站進行安裝;mysql
https://lnmp.org/install.htmlsql
安裝二:數據庫
採用yum或者安裝包的方式進行安裝,具體操做請參照百度。vim
開始配置Cacti網絡
1:安裝net-snmp簡單網絡管理協議ide
yum install -y net-snmp net-snmp-libs net-snmp-utils net-snmp-devel net-snmp-perl
2:安裝RRDTool 繪圖工具工具
yum install -y rrdtool rrdtool-devel rrdtool-php rrdtool-perl perl-devel perl-CPAN perl-YAML
3:配置SNMP
修改snmp配置文件,找到以下內容修改
vim /etc/snmp/snmpd.conf
//修改default爲本機ip,修改public爲本身的團體名(能夠不改),41行
com2sec notConfigUser default public
//把systemview改爲all ,供全部snmp 訪問權限 62行
access notConfigGroup "" any noauth exact all none none
//去掉此行註釋
view all included .1 80 // 去掉#號 85行
重啓snmp服務網站
systemctl restart snmpd.service && systemctl enable snmpd.service
4:修改PHP時區
vim /usr/local/php/etc/php.ini
[PHP]
safe_mode = Off
……
date.timezone = Asia/Shanghai
5:修改Mysql配置文件
vim /etc/my.cnf
在文件最末尾新建[server]區域,複製進去如下內容
[server]
# this is only for the mysqld standalone daemon
character_set_server = utf8mb4
collation-server = utf8mb4_unicode_ci
max_heap_table_size = 256M
max_allowed_packet = 16777216
tmp_table_size = 64M
join_buffer_size = 64M
innodb_file_per_table = ON
innodb_buffer_pool_size = 1024M
innodb_doublewrite = OFF
#innodb_additional_mem_pool_size = 96M
innodb_flush_log_at_timeout = 3
innodb_read_io_threads = 32
innodb_write_io_threads =16
註釋掉[mysqld]區域下的
#max_allowed_packet = 1M
/etc/init.d/mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
6:下載cacti安裝包
wget https://www.cacti.net/downloads/cacti-1.1.38.tar.gz
tar zxvf cacti-1.1.38.tar.gz
cp -R cacti-1.1.38 /home/wwwroot/default/cacti
7:建立cacti數據庫
[root@localhost /]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.18-log Source distribution
Copyright (c) 2000, 2017, 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;
Query OK, 1 row affected (0.00 sec)
mysql> grant all on cacti.* to cactiuser@localhost identified by "cactiuser";
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> GRANT SELECT ON mysql.time_zone_name TO 'cactiuser'@'localhost' IDENTIFIED BY 'cactiuser';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
注意:這裏的數據庫用戶名密碼所有爲cactiuser,能夠自定義。
8:導入cacti數據文件
mysql> use cacti;
Database changed
mysql> source /home/wwwroot/default/cacti/cacti.sql
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)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
9:配置數據庫時區
cd /usr/local/mysql/bin/
./mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql -u root -p mysql
Enter password:
Warning: Unable to load '/usr/share/zoneinfo//iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo//zone.tab' as time zone. Skipping it.
10:cacti配置文件config.php
主要修改數據庫用戶名密碼,和cacti路徑,這裏所有默認,根據我的配置進行修改
vim /home/wwwroot/default/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;
11:建立 cacti 系統用戶,設置目錄權限
useradd -r -M cacti
chown -R cacti /home/wwwroot/default/cacti/{rra,log}/
chown -R www:www /home/wwwroot/default/cacti/{resource,cache,scripts}
chmod -R 777 /home/wwwroot/default/cacti/
12:添加定時任務
[root@localhost bin]# crontab -e
*/5 * * * * cactiuser php /home/wwwroot/default/cacti/poller.php > /dev/null 2>&1
no crontab for root - using an empty one
crontab: installing new crontab
13:從新啓動相關服務
systemctl restart crond && systemctl restart snmpd
14:安裝spine
cacti默認使用cmd.php來輪詢數據,速度會很慢,所以咱們採用Spine來輪詢數據。cacti-spine是一個由C語言開發的,用於替代cmd.php的快速獲取速度的引擎。(也能夠不裝)
安裝spine高速數據採集插件
15:訪問ip
查看是否完成配置,按照提示操做進行一步步安裝。