關閉selinuxphp
1.搭建lamp環境html
配置apachemysql
[root@cacti-server ~]# yum -y install httpdlinux
[root@cacti-server ~]# systemctl start httpdsql
[root@cacti-server ~]# systemctl enable httpd數據庫
[root@cacti-server ~]# firewall-cmd --permanent --add-service=httpapache
successvim
[root@cacti-server ~]# firewall-cmd --reload瀏覽器
successtcp
配置mariadb
[root@cacti-server ~]# yum -y install mariadb-server mysql-devel
[root@cacti-server ~]# systemctl start mariadb
[root@cacti-server ~]# mysql_secure_installation
Set root password? [Y/n]
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
[root@cacti-server ~]# mysql -u root -p
MariaDB [(none)]> grant all privileges on *.* to test@localhost identified by 'redhat'; 建立用於測試php和mariadb連通性的用戶
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
[root@cacti-server ~]# systemctl restart mariadb
[root@cacti-server ~]# systemctl enable mariadb
[root@cacti-server ~]# firewall-cmd --permanent --add-port=3306/tcp
success
[root@cacti-server ~]# firewall-cmd --reload
success
配置php
[root@cacti-server ~]# yum -y install php php-mysql php-gd php-pear
[root@cacti-server ~]# vim /etc/php.ini
date.timezone =PRC 修改時區
[root@cacti-server ~]# vim /var/www/html/index.php 編輯測試頁面
<?php
$conn=mysql_connect('localhost','test','redhat');
if ($conn)
echo "database connect ok";
else
echo "database connect failure";
?>
<?php
phpinfo()
?>
[root@cacti-server ~]# systemctl restart httpd
測試
2.安裝配置cacti
下載軟件
[root@cacti-server ~]# cd /usr/local/src/
[root@cacti-server src]# wget http://www.cacti.net/downloads/cacti-0.8.8f.tar.gz
[root@cacti-server src]# tar zxvf cacti-0.8.8f.tar.gz
[root@cacti-server src]# mv cacti-0.8.8f /var/www/html/cacti
建立cacti數據庫和cacti用戶,賦予權限
[root@cacti-server ~]# mysql -u root -p
MariaDB [(none)]> create database cacti default character set utf8;
MariaDB [(none)]> grant all privileges on cacti.* to cacti@localhost identified by 'redhat';
MariaDB [(none)]> flush privileges;
把cacti.sql導入數據庫
[root@cacti-server cacti]# mysql -ucacti -predhat cacti < /var/www/html/cacti/cacti.sql
編輯config.php和global.php
[root@cacti-server cacti]# vim /var/www/html/cacti/include/config.php|global.php
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "redhat";
$database_port = "3306";
$database_ssl = false;
安裝rrdtool以生成圖像
[root@cacti-server src]# yum -y install rrdtool rrdtool-devel rrdtool-php rrdtool-perl
[root@cacti-server src]# yum -y install gd gd-devel php-gd ---rrdtool繪製圖像須要的圖形庫
安裝snmp服務
[root@cacti-server cacti]# yum -y install net-snmp net-snmp-utils php-snmp net-snmp-libs
編輯配置文件
[root@cacti-server ~]# vim /etc/snmp/snmpd.conf
41 com2sec notConfigUser 127.0.0.1 public
62 access notConfigGroup "" any noauth exact all none none
85 view all included .1 80
[root@cacti-server ~]# systemctl restart snmpd.service
[root@cacti-server ~]# systemctl enable snmpd.service
受權目錄權限
[root@cacti-server ~]# useradd -r -M cacti
[root@cacti-server ~]# chown -R cacti /var/www/html/cacti/rra/
[root@cacti-server ~]# chown -R cacti /var/www/html/cacti/log/
配置一個抓圖的計劃任務
[root@cacti-server ~]# crontab -e
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php >> /tmp/cacti_rrdtool.log
瀏覽器訪問cacti管理頁面進行安裝
[root@cacti-server ~]# /usr/bin/php /var/www/html/cacti/poller.php
OK u:0.00 s:0.01 r:0.80
OK u:0.00 s:0.02 r:1.21
OK u:0.00 s:0.02 r:1.39
OK u:0.00 s:0.02 r:1.50
OK u:0.00 s:0.02 r:1.87
10/21/2016 04:02:32 PM - SYSTEM STATS: Time:1.4211 Method:cmd.php Processes:1 Threads:N/A Hosts:2 HostsPerProcess:2 DataSources:5 RRDsProcessed:5