构建cacti监控平台, LAMP使用脚本自动化编译安装
在开始操作之前,先简单介绍几个概念*SNMP :简单网络管理协议
它主要是根据用户的需求获取远程被监控主机的一些信息而已,
*RRDTOOL : 是一个强大的绘图工具
它主要是根据用户的需求将从SNMP协议(当然也可以是其他的方式,比如说sheel脚本等,)获取到信息,绘制成图像,
*cacti : cacti( http://www.cacti.net )
是一个基于PHP开发的强大的检测分析工具而已,cacti主要是通过SNMP或sheel脚本等方式获取到被监控主机的数据, 然后通过rrdtool存储更新数据,当用户需要查看数据的时候,使用rrdtool生成图表通过cacai展示给用户,
****************************************************************************************
下面将在一台默认安装有rhel5.8的系统上安装配置cacti
****************************************************************************************
上面说过cacit是一个php语言开发的网页工具,那么我们需要安装LAMP平台,还要生成图像展示给用户,需要安装rrdtool,如果要使用snmp协议监控其他主机或本机,需要安装snmp
****************************************************************************************
准备以下软件包,存放至/usr/src目录下
****************************************************************************************
apr-1.4.6.tar.bz2
apr-util-1.4.1.tar.bz2
cmake-2.8.8.tar.gz 这些包主要是LAMP环境所用到的软件包
httpd-2.4.2.tar.bz2
mysql-5.5.25a.tar.gz
php-5.4.4.tar.bz2
****************************************************************************************
rrdtool-1.4.7.tar.gz
cacti-spine-0.8.8a.tar.gz
cacti-0.8.8a.tar.gz
****************************************************************************************
准备完成好,下面来安装配置了,需要注意的是软件包一定要放到/usr/src目录,而且要配置好yum源,
一, 构建LAMP环境,这里使用脚本自动化编译安装并配置,(当然也可以使用yum安装,)
1. 构建LAMP平台,脚本内容如下
[*]#!/bin/bash
[*]# andy_f
[*]# 编译安装LAMP平台
[*]local_ip=`ifconfig eth0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}'`
[*]# install path
[*]http_path=/usr/local/apache
[*]apr_path=/usr/local/apr
[*]apr_util_path=/usr/local/apr-util
[*]php_path=/usr/local/php
[*]mysql_path=/usr/local/mysql
[*]
[*]re=0
[*]
[*]# install package name
[*]apr="apr-1.4.6.tar.bz2"
[*]apr_util="apr-util-1.4.1.tar.bz2"
[*]http="httpd-2.4.2.tar.bz2"
[*]php="php-5.4.4.tar.bz2"
[*]cmake="cmake-2.8.8.tar.gz"
[*]mysql="mysql-5.5.25a.tar.gz"
[*]# Compiler parameters
[*]make_apr="--prefix=$apr_path"
[*]make_apr_util="--prefix=$apr_util_path --with-apr=$apr_path"
[*]make_http="--prefix=$http_path --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=$apr_path --with-apr-util=$apr_util_path --enable-suexec --with-suexec"
[*]make_mysql="-DCMAKE_INSTALL_PREFIX=$mysql_path -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci "
[*]make_php="--prefix=$php_path --with-mysql=$mysql_path --with-config-file-path=$php_path/etc --with-openssl --enable-sockets --with-mysqli=$mysql_path/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml -with-apxs2=$http_path/bin/apxs --with-bz2"
[*]###################################
[*]host1=/cacti
[*]##################################
[*]check_apache() {
[*][ -e $apr_path ] && echo -e "\033[31m apr installed\033[0m" && re=1
[*][ -e $apr_util_path ] && echo -e "\033[31m apr-util installed\033[0m" && re=1
[*][ -e $http_path ] && echo -e "\033[31m apache installed\033[0m" && re=1
[*]}
[*]
[*]check_php() {
[*][ -e $php_path ] && echo -e "\033[31m php installed\033[0m" && re=1
[*]}
[*]
[*]check_mysql() {
[*][ -e $mysql_path ] && echo -e "\033[31m mysql installed\033[0m" && re=1
[*]}
[*]
[*]check_all() {
[*]count=0
[*]check_apache
[*][ ! $re -eq 0 ] && count=1
[*]check_php
[*][ ! $re -eq 0 ] && count=${count+1}
[*]check_mysql
[*][ ! $re -eq 0 ] && count=${count+1}
[*][ ! $count -eq 0 ] && exit 1
[*]}
[*]
[*]init_install() {
[*]setenforce 0
[*]service iptables stop &>/dev/null
[*]yum -y groupinstall "Development Libraries" "Development Tools" "X Software Development"&>/dev/null
[*]yum -y install pcre-devel &>/dev/null
[*]####################################
[*]if [ -e /usr/src/$apr ];then
[*] cd /usr/src
[*] tar xjf $apr &>/dev/null
[*] cd /usr/src/`echo $apr | awk -F.tar '{print $1}'`
[*] ./buildconf &>/dev/null
[*] ./configure $make_apr &>/dev/null
[*] make&>/dev/null && make install &>/dev/null
[*] if [ $? -eq 0 ];then
[*] echo "$apr install ok"
[*] else
[*] echo "$apr install fail"
[*] exit 2
[*] fi
[*]else
[*] echo "/usr/src/$apr no file"
[*] exit 3
[*]fi
[*]####################################
[*] if [ -e /usr/src/$apr_util ];then
[*] cd /usr/src
[*] tar xjf $apr_util
[*] cd /usr/src/`echo $apr_util | awk -F.tar '{print $1}'`
[*] ./buildconf --with-apr=/usr/src/`echo $apr | awk -F.tar '{print $1}'`&>/dev/null
[*] ./configure $make_apr_util &>/dev/null
[*] make&>/dev/null &&make install &>/dev/null
[*] if [ $? -eq 0 ];then
[*] echo "$apr_util install ok"
[*] else
[*] echo "$apr_util install fail"
[*] exit 2
[*] fi
[*] else
[*] echo "/usr/src/$apr_util no file"
[*] exit 3
[*]fi
[*]####################################
[*]if [ -e /usr/src/$cmake ];then
[*] cd /usr/src
[*] tar xzf$cmake
[*] cd /usr/src/`echo $cmake | awk -F.tar '{print $1}'`
[*] ./bootstrap &>/dev/null
[*] make&>/dev/null && make install &>/dev/null
[*] if [ $? -eq 0 ];then
[*] echo "$cmake install ok"
[*] else
[*] echo "$cmake install fail"
[*] exit 2
[*] fi
[*]else
[*] echo "/usr/src/$cmake no file"
[*] exit 3
[*]fi
[*]####################################
[*]}
[*]
[*]install_httpd() {
[*]if [ -e /usr/src/$http ];then
[*] cd /usr/src
[*] tar xjf $http
[*] cd /usr/src/`echo $http | awk -F.tar '{print $1}'`
[*] ./configure $make_http &>/dev/null
[*] make&>/dev/null && make install &>/dev/null
[*] if [ $? -eq 0 ];then
[*] echo "$http install ok"
[*] else
[*] echo "$http install fail"
[*] exit 2
[*] fi
[*] else
[*] echo "/usr/src/$http no file"
[*] exit 3
[*] fi
[*]}
[*]
[*]install_mysql() {
[*]id mysql &>/dev/null
[*][ $? -eq 0 ] || useradd -s /sbin/nologin -M mysql
[*]if [ -e /usr/src/$mysql ];then
[*] cd /usr/src
[*] tar xzf $mysql
[*] cd /usr/src/`echo $mysql | awk -F.tar '{print $1}'`
[*] cmake . $make_mysql &>/dev/null
[*] make&>/dev/null && make install &>/dev/null
[*] if [ $? -eq 0 ];then
[*] echo "$mysql install ok"
[*] else
[*] echo "$mysql install fail"
[*] exit 2
[*] fi
[*]else
[*] echo "/usr/src/$mysql no file"
[*] exit 3
[*]fi
[*]}
[*]
[*]install_php() {
[*]if [ -e /usr/src/$php ];then
[*] cd /usr/src
[*] tar xjf $php
[*] cd /usr/src/`echo $php | awk -F.tar '{print $1}'`
[*] ./configure $make_php &>/dev/null
[*] make&>/dev/null && make install &>/dev/null
[*] if [ $? -eq 0 ];then
[*] echo "$php install ok"
[*] else
[*] echo "$php install fail"
[*] exit 2
[*] fi
[*]else
[*] echo "/usr/src/$php no file"
[*] exit 3
[*]fi
[*]}
[*]
[*]config_lamp() {
[*]########################################################
[*]echo "pidfile "/var/run/httpd.pid"" >> $http_path/conf/httpd.conf
[*]echo "AddType application/x-httpd-php.php" >> $http_path/conf/httpd.conf
[*]echo "AddType application/x-httpd-php-source.phps" >> $http_path/conf/httpd.conf
[*]echo "DirectoryIndexindex.phpindex.html" >> $http_path/conf/httpd.conf
[*]echo "Include conf/vhost/*.conf" >> $http_path/conf/httpd.conf
[*]mkdir -p $http_path/conf/vhost
[*]ln -s $http_path/bin/* /sbin/
[*]ln -s $http_path/include/ /usr/include/apache
[*]echo "$local_ip `hostname`" >> /etc/hosts
[*]if [ -e /media/Server/httpd-2.2.3-63.el5.i386.rpm ];then
[*] cp /media/Server/httpd-2.2.3-63.el5.i386.rpm /var/tmp/
[*] cd /var/tmp
[*] rpm2cpio httpd-2.2.3-63.el5.i386.rpm | cpio -id &>/dev/null
[*] cp /var/tmp/etc/rc.d/init.d/httpd /etc/init.d/
[*] sed -i '40,55d;62d' /etc/init.d/httpd
[*] sed -i s@/usr/sbin/apachectl@$http_path/bin/apachectl@g /etc/init.d/httpd
[*] sed -i s@/usr/sbin/httpd@$http_path/bin/httpd@g /etc/init.d/httpd
[*] chmod a+x /etc/init.d/httpd
[*] chkconfig --add httpd
[*] chkconfig httpd on
[*]else
[*]cat > /etc/init.d/httpd /dev/null
[*]########################################################
[*]cp /usr/src/`echo $php | awk -F.tar '{print $1}'`/php.ini-production $php_path/etc/php.ini
[*]########################################################
[*]}
[*]
[*]vhost1() {
[*][ -e $host1 ] ||mkdir -p $host1
[*]cat > $http_path/conf/vhost/cacti.conf localhost, 可以看到默认监控本机的图像了,如果没有图像执行下如下命令
[*]#/usr/local/php/bin/php /cacti/poller.php
http://blog.运维网.com/attachment/201207/201248822.png
OK,到这里已经安装配置好了,后面会再写篇博客介绍cacti的使用,
页:
[1]