在开始操作之前,先简单介绍几个概念
*SNMP :简单网络管理协议
它主要是根据用户的需求获取远程被监控主机的一些信息而已,
*RRDTOOL : 是一个强大的绘图工具
它主要是根据用户的需求将从SNMP协议(当然也可以是其他的方式,比如说sheel脚本等,)获取到信息,绘制成图像,
是一个基于PHP开发的强大的检测分析工具而已,cacti主要是通过SNMP或sheel脚本等方式获取到被监控主机的数据, 然后通过rrdtool存储更新数据,当用户需要查看数据的时候,使用rrdtool生成图表通过cacai展示给用户,
****************************************************************************************
下面将在一台默认安装有rhel5.8的系统上安装配置cacti
****************************************************************************************
上面说过cacit是一个php语言开发的网页工具,那么我们需要安装LAMP平台,还要生成图像展示给用户,需要安装rrdtool,如果要使用snmp协议监控其他主机或本机,需要安装snmp
****************************************************************************************
准备以下软件包,存放至/usr/src目录下
****************************************************************************************
apr-1.4.6.tar.bz2apr-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 "DirectoryIndex index.php index.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 <<EOF #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi HTTPD_LANG=${HTTPD_LANG-"C"} INITLOG_ARGS="" apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else killproc -p ${pidfile} $httpd -HUP RETVAL=$? fi echo } case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL EOF chmod a+x /etc/init.d/httpd chkconfig --add httpd chkconfog httpd on fi ######################################################## ln -s $mysql_path/lib/* /lib/ ln -s $mysql_path/include/ /usr/include/mysql ln -s $mysql_path/bin/* /sbin/ chown -R mysql:mysql $mysql_path cp /usr/src/`echo $mysql | awk -F.tar '{print $1}'`/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf cp /usr/src/`echo $mysql | awk -F.tar '{print $1}'`/support-files/my-innodb-heavy-4G.cnf /etc/my.cnf cp /usr/src/`echo $mysql | awk -F.tar '{print $1}'`/support-files/mysql.server /etc/init.d/mysqld chmod a+x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on $mysql_path/scripts/mysql_install_db --user=mysql --basedir=$mysql_path --datadir=$mysql_path/data/ &>/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 <<EOF <VirtualHost *:80> ServerAdmin admin@andy.com DocumentRoot $host1 ServerName cacti.andy.com ErrorLog logs/cacti.err CustomLog logs/cacti.access" common <Directory "$host1"> Options Indexes FollowSymLinks AllowOverride None <RequireAll> Require all granted </RequireAll> </Directory> </VirtualHost> EOF } start_service() { service httpd restart && echo "httpd is up." || echo "httpd error." service mysqld restart && echo "mysqld is up." || echo "mysqld error." } check_all init_install install_httpd install_mysql install_php config_lamp vhost1 start_service
执行此脚本即可, 如果不想使用脚本安装的话,可以参考 不过需要注意的是在编译安装php的时候需要加 --enable-sockets 参数,