apache+mysql+php+snmp+rrdtool+cacti配置
OS CentOS3.5
本机IP 192.168.1.99
机器名请用类似 Bleach.com 格式
安装 mysql
所有安装程序 在 /usr 下
CODE:
[Copy to clipboard]
[root@Bleach usr]#groupadd mysql
[root@Bleach usr]#useradd -g mysql mysql
[root@Bleach usr]#cd /usr/local
[root@Bleach local]#gunzip < /usr/mysql-standard-4.0.23-pc-linux-i686.tar.gz | tar xvf -
[root@Bleach local]#ln -s /usr/local/mysql-standard-4.0.23-pc-linux-i686 mysql
[root@Bleach mysql]#cd mysql
[root@Bleach mysql]#scripts/mysql_install-db -user=mysql
[root@Bleach mysql]#chown -R root .
[root@Bleach mysql]# chown -R mysql data
[root@Bleach mysql]#chgrp -R mysql .
[root@Bleach mysql]#./bin/mysqld-safe -user=mysql &
[root@Bleach mysql]#./bin/mysqladmin -u root password mysql
[root@Bleach mysql]#cp ./support-file/mysql.server /etc/init.d/mysql
[root@Bleach mysql]#cd /etc/rc3.d/
[root@Bleach rc3.d]#ln -s /etc/init.d/mysql S85mysql
[root@Bleach rc3.d]#ln -s /etc/init.d/mysql K85mysql
Mysql 安装结束
安装apache
CODE:
[Copy to clipboard]
[root@Bleach usr]#tar -zxvf httpd-2.0.54.tar.gz
[root@Bleach usr]#cd httpd-2.0.54
[root@Bleach httpd-2.0.54]# ./configure --prefix=/www --enable-so
[root@Bleach httpd-2.0.54]# make && make install
[root@Bleach httpd-2.0.54]# cp /www/bin/apachectl /etc/init.d/httpd
[root@Bleach httpd-2.0.54]#cd /etc/rc3.d
[root@Bleach rc3.d]#ln -s ../init.d/httpd S85httpd
[root@Bleach rc3.d]#ln -s ../init.d/httpd K85httpd
[root@Bleach rc3.d]#/www/bin/apachectl start
Apache 安装完毕
安装PHP
CODE:
[Copy to clipboard]
[root@Bleach usr]# tar -zxvf php-4.3.10.tar.gz
[root@Bleach usr]#cd php-4.3.10
[root@Bleach 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-dir=/usr/include
>--with-gd
[root@Bleach php-4.3.10]#make && make install
[root@Bleach php-4.3.10]#cp php.ini-dist /usr/local/lib/php.ini
[root@Bleach php-4.3.10]#vi /www/conf/httpd.conf
按 I 键 添加 AddType application/x-tar .tgz
AddType application/x-httpd-php .php
AddType p_w_picpath/x-icon .ico
DirectoryIndex index.php index.html index.html.var
保存退出 :wq
[root@Bleach php-4.3.10]#/www/bin/apachectl restart
Php安装完毕
设置mysql
CODE:
[Copy to clipboard]
[root@Bleach 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 root@localhost;
mysql> grant all on cactidb.* to cactiuser;
mysql> grant all on cactidb.* to cactiuser@localhost;
mysql> set password for cactiuser@localhost=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
$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);
};
?>
保存退出 :wq
重启mysql + apache 服务
[root @Bleach htdocs]#service mydql restart
[root @Bleach htdocs]#service httpd restart
进入浏览器检查
http://192.168.1.99/test/php 和 http://192.168.1.99/mysqltest.html
安装rrdtool
CODE:
[Copy to clipboard]
[root@Bleach usr]# tar zxvf rrdtool-1.0.50.tar.gz
[root@Bleach usr]# cd rrdtool-1.0.50
[root@Bleach rrdtool-1.0.50]# ./configure
[root@Bleach rrdtool-1.0.50]#make && make install
Rrdtool安装完毕
安装net-snmp、snmpwalk和snmpget命令
CODE:
[Copy to clipboard]
[root@Bleach usr]#rpm -qa | grep net-snmp
net-snmp-5.0.9-2.30E.15
net-snmp-devel-5.0.9-2.30E.15
net-snmp-libs-5.0.9-2.30E.15
net-snmp-utils-5.0.9-2.30E.15
[root@Bleach 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
[root@Bleach usr]#service snmpd restart
注:如果你机器内没有snmpwalk和snmpge命令,请到安装盘里查找 net-snmp-utils 包,rpm -ivh net-snmp-utils-*.rpm 只后这两个命令就在系统里了。其他包也都在安装盘里 确保安装这四个包就OK
CODE:
[Copy to clipboard]
安装/ 配置cacti
[code]
[root@Bleach usr]# useradd cactiuser -g users
[root@Bleach usr]#passwd cactiuser (pwd:cactipw)
[root@Bleach usr]# cp cacti-0.8.6g.tar.gz /www/htdocs/
[root@Bleach htdocs]# tar zxvf cacti-0.8.6g.tar.gz
[root@Bleach htdocs]# mv cacti-0.8.6g cacri
[root@Bleach htdocs]# cd cacti
[root@Bleach cacti]# /usr/local/mysql/bin/mysql -u root -pmysql cactidb < cacti.sql
[root@Bleach cacti]# chown -R cactiuser rra/ log/
[root@Bleach cacti]#cd scripts
[root@Bleach scripts]#chown cactiuser:users *
[root@Bleach scripts]#vi /www/htdocs/cacti/include/config.php
$database_type = “mysql”;
$database_default = “cactidb”;
$database_hostname = “localhost”;
$database_username = “cactiuser”;
$database_password = “cactipw”;
更改用户、密码 等项 与上面给出的对应 保存退出
[root@Bleach scripts]# crontab -u cactiuser -e
加入 */5 * * * * /www/php/bin/php /www/htdocs/cacti/poller.php > /dev/null 2>&1
保存退出:wq
全部设置完毕。
打开浏览器 http://192.168.1.99/cacti 进入cacti的初始设置页面
第一次默认登陆账号:admin 密码 admin
登陆后在新改个密码就OK
需要说明的还有路径
CODE:
[Copy to clipboard]
snmpwalk Binary Path :/usr/bin/snmpwalk
snmpget Binary Path:/usr/bin/snmpget
RRDTool Binary Path:/usr/rrdtool-1.0.50/src/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
如果你是按我的步骤做的 那上面的路径一定不会错。
完