參考自 無廢話 apache+mysql+php+snmp+rrdtool+cacti 配置
原貼位置:http://bbs.chinaunix.net/viewthread....ilter%3Ddigest
我在原貼基礎上進行了修改,因為适合我自己的情況,和原貼已經有很大不同,隻是給遇到相似問題的朋友一點提示,不見得具有普遍性
向原作者表示感謝
我的環境描述:
RHEL 4.0 / gcc 3.2.3 /
安裝的軟體包:
X Window System
GNOME Desktop Environment
Editors
Graphical Internet
Text-based Internet
Server Configuration Tools
Development Tools
Administration Tools
System Tools
本機IP 10.3.7.7
---安裝 mysql
直接使用RHEL4自身攜帶的 mysql 程序,即可滿足條件
可能需要額外安裝mysql服務端,安裝包:
mysql-server-4.1.7-4.RHEL4.1.i386.rpm
mysql-bench-4.1.7-4.RHEL4.1.i386.rpm
執行:
[[email protected] usr]# groupadd mysql
[[email protected] usr]# useradd -g mysql mysql
[[email protected] mysql]# /usr/bin/mysql_install_db --user=mysql
[[email protected] mysql]# ./bin/mysqld --user=mysql
[[email protected] mysql]# /usr/bin/mysqladmin -u root password mysql
[[email protected] mysql]# cd /etc/rc3.d/
[[email protected] rc3.d]# ln -s /etc/init.d/mysqld S85mysql
[[email protected] rc3.d]# ln -s /etc/init.d/mysqld K85mysql
Mysql 安裝結束
---安裝apache
apache 本身系統是自帶的,隻是為了擷取最新版本外加試驗,我也按照文章重新安裝了
[[email protected] usr]# tar -zxvf httpd-2.0.55.tar.gz
[[email protected] usr]# cd httpd-2.0.55
[[email protected] httpd-2.0.54]# ./configure --prefix=/www --enable-so
[[email protected] httpd-2.0.54]# make && make install
[[email protected] httpd-2.0.54]# cp /www/bin/apachectl /etc/init.d/httpd
[[email protected] httpd-2.0.54]# cd /etc/rc3.d
[[email protected] rc3.d]# ln -s /etc/init.d/httpd S85httpd
[[email protected] rc3.d]# ln -s /etc/init.d/httpd K85httpd
[[email protected] rc3.d]# /www/bin/apachectl start
[/code]
Apache 安裝完畢
---安裝PHP
同樣,PHP也可以使用系統自帶的,處于使用最新php版本的原因,進行了新的安裝
[code]
[[email protected] usr]# tar -zxvf php-4.3.10.tar.gz
[[email protected] usr]# cd php-4.3.10
[[email protected] php-4.3.10]# ./configure --prefix=/www/php /
> --with-apxs2=/www/bin/apxs /
> --with-config-file-path=/www/php /
> --enable-sockets /
> --with-mysql=/usr/local/mysql /
> --with-zlib /
> --with-libxml /
> --with-gd
[[email protected] php-4.3.10]# make && make install
# 沒有使用 [[email protected] php-4.3.10]# cp php.ini-dist /www/php/php.ini
[[email protected] php-4.3.10]# vi /www/conf/httpd.conf
加入内容:
AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType image/x-icon .ico
DirectoryIndex屬性調整為:
DirectoryIndex index.php index.html index.html.var
儲存退出 :wq
[[email protected] php-4.3.10]# /www/bin/apachectl restart
[/code]
---補充:由于with-gd選項可能需要圖形支援,如果出現編譯錯誤,則需要安裝如下rpm包:
libjpeg-devel-6b-33.i386.rpm
libart_lgpl-devel-2.3.16-3.i386.rpm
libattr-devel-2.4.16-3.i386.rpm
libpng10-1.0.16-1.i386.rpm
libpng10-devel-1.0.16-1.i386.rpm
libpng-devel-1.2.7-1.i386.rpm
Php安裝完畢
---設定mysql,建立cacti資料庫和資料庫帳戶
[code]
[[email protected] php-4.3.10]# /usr/local/mysql/bin/mysql -u root -pmysql
mysql> create database cactidb;
mysql> grant all on cactidb.* to root;
mysql> grant all on cactidb.* to [email protected];
mysql> grant all on cactidb.* to cactiuser;
mysql> grant all on cactidb.* to [email protected];
mysql> set password for [email protected]=password('cactipw');
注:以上語句輸出 Query OK, 0 rows affected (0.01 sec) 表示成功
mysql> exit
Mysql設定完畢
---檢測apache + php + mysql
[root @tsai usr]# cd /www/htdocs
[root @tsai htdocs]# touch test.php
[root @tsai htdocs]# vi test.php
<?
phpinfo( );
?>
儲存退出 :wq
[root @tsai htdocs]# touch mydqltest.html
[root @tsai htdocs]# vi mysqltest.html
<html>
<body>
<?
$link=mysql_connect('localhost','root');
mysql_select_db('mysql');
$str="select * from user;";
$result=mysql_query($str,$link);
$show=mysql_num_rows($result);
mysql_close($link);
for ($i=0;$i < $show;$i++)
{
$arr[$i]=mysql_fetch_array($result);
};
?>
<table align=center border=1>
<tr align=center>
<td>Host</td>
<td>User</td>
<td>Password</td>
</tr>
<?for ($i=0;$i<$show;$i++){?>
<tr>
<td><?echo $arr[$i][Host]?></td>
<td><?echo $arr[$i][User]?></td>
<td><?echo $arr[$i][Password]?></td>
</tr>
<?};?>
</body>
</html>
儲存退出 :wq
[/code]
重新開機mysql + apache 服務
[root @Bleach htdocs]# /etc/init.d/mysqld restart
[root @Bleach htdocs]# /etc/init.d/httpd restart
進入浏覽器檢查
http://10.3.7.7/test.php 和 http://10.3.7.7/mysqltest.html
---安裝rrdtool
[code]
[[email protected] usr]# tar zxvf rrdtool.tar.gz
[[email protected] usr]# cd rrdtool-1.2.12
[[email protected] rrdtool-1.0.50]# ./configure
[[email protected] rrdtool-1.0.50]# make && make install
[/code]
補充說明:
rrdtool需要tcl開發庫的支援,否則會出現編譯錯誤,請安裝
tcl-devel-8.4.7-2.i386.rpm
tcl-html-8.4.7-2.i386.rpm
tclx-devel-8.3.5-4.i386.rpm
tclx-doc-8.3.5-4.i386.rpm
另外編譯過程中可能出現錯誤: cc1: invalid option `tune=pentium4'
修改:進入 /rrdtool-1.2.12/bindings/perl-shared,編輯Makefile
删除 OPTIMIZE = -O2 -g -pipe -m32 -march=i386 -mtune=pentium4 中的 -mtune=pentium4
---這個可能和gcc版本有關
Rrdtool安裝完畢
安裝net-snmp、snmpwalk和snmpget指令
[code]
[[email protected] usr]# rpm -qa | grep net-snmp
net-snmp-5.1.2-11
net-snmp-utils-5.1.2-11
net-snmp-libs-5.1.2-11
net-snmp-perl-5.1.2-11
net-snmp-devel-5.1.2-11
[[email protected] usr]# vi /etc/snmp/snmpd.conf
更改 1、com2sec notConfigUser default public
改為:com2sec notConfigUser 127.0.0.1 public
2、access notConfigGroup "" any noauth exact systemview none none
改為:access notConfigGroup "" any noauth exact all none none
3、#view all included .1 80
将前面的 # 注釋 去掉。
儲存退出 :wq
[[email protected] usr]# service snmpd restart
[/code]
注:如果你機器内沒有snmpwalk和snmpge指令,請安裝:
net-snmp-devel-5.1.2-11.i386.rpm
net-snmp-perl-5.1.2-11.i386.rpm
net-snmp-utils-5.1.2-11.i386.rpm
[code]
安裝/ 配置cacti
[code]
[[email protected] usr]# useradd cactiuser -g users
[[email protected] usr]# passwd cactiuser (pwd:cactipw)
[[email protected] usr]# cp cacti-0.8.6h.tar.gz /www/htdocs/
[[email protected] usr]# cd /www/htdocs/
[[email protected] htdocs]# tar zxvf cacti-0.8.6h.tar.gz
[[email protected] htdocs]# mv cacti-0.8.6h cacti
[[email protected] htdocs]# cd cacti
[[email protected] cacti]# /usr/local/mysql/bin/mysql -u root -pmysql cactidb < cacti.sql
[[email protected] cacti]# chown -R cactiuser rra/
[[email protected] cacti]# chown -R cactiuser log/
[[email protected] cacti]# cd scripts
[[email protected] scripts]# chown cactiuser:users *
[[email protected] scripts]# vi /www/htdocs/cacti/include/config.php
$database_type = “mysql”;
$database_default = “cactidb”;
$database_hostname = “localhost”;
$database_username = “cactiuser”;
$database_password = “cactipw”;
更改使用者、密碼 等項 與上面給出的對應 儲存退出
[[email protected] scripts]# crontab -u cactiuser -e
加入
*/5 * * * * /www/php/bin/php /www/htdocs/cacti/poller.php > /dev/null 2>&1
儲存退出:wq
[/code]
全部設定完畢。
打開浏覽器 http://10.3.7.7/cacti 進入cacti的初始設定頁面
第一次預設登陸賬号:admin 密碼 admin
登陸後在新改個密碼就OK
需要說明的還有路徑
[code]
snmpwalk Binary Path : /usr/bin/snmpwalk
snmpget Binary Path: /usr/bin/snmpget
snmpbulkwalk Binary Path: /usr/bin/snmpbulkwalk
snmpgetnext Binary Path: /usr/bin/snmpgetnext
RRDTool Binary Path: /usr/local/rrdtool-1.2.12/bin/rrdtool
PHP Binary Path: /www/php/bin/php
Cacti Log File Path: /www/htdocs/cacti/log/cacti.log
Cactid Poller File Path: /www/htdocs/cacti/poller.php
如果你是按上述步驟做的 那上面的路徑不會錯。
[/code]
注:此時graphs還不能顯示圖形,需要将服務重新啟動一下
[code]
[[email protected] scripts]# /etc/init.d/snmpd restart
[[email protected] scripts]# /etc/init.d/mysqld restart
[[email protected] scripts]# /etc/init.d/httpd restart
[/code]
現在打開或重新整理 http://10.3.7.7/cacti 選 graphs 選項應該能出圖形
如還沒有顯示圖形,則檢查 cacti/rra cacti/log 的權限是否符合,檢視rra/目錄下是否有生成的資料檔案
可以嘗試使用 php poller.php 執行檢視是否rra目錄下有生成的檔案
如果依然沒有産生圖形,則進入web,選擇【Console】-》【Graph Management】任意選擇右側項目,在頁面又上角選擇【Turn On Graph Debug Mode.】
可以檢視列印資訊進行問題定位。
完