在開始操做以前,先簡單介紹幾個概念
*SNMP :簡單網絡管理協議
它主要是根據用戶的需求獲取遠程被監控主機的一些信息而已,
*RRDTOOL : 是一個強大的繪圖工具
它主要是根據用戶的需求將從SNMP協議(固然也能夠是其餘的方式,好比說sheel腳本等,)獲取到信息,繪製成圖像,
*cacti : cacti( http://www.cacti.net )
是一個基於PHP開發的強大的檢測分析工具而已,cacti主要是經過SNMP或sheel腳本等方式獲取到被監控主機的數據, 而後經過rrdtool存儲更新數據,當用戶須要查看數據的時候,使用rrdtool生成圖表經過cacai展現給用戶,
****************************************************************************************php
下面將在一臺默認安裝有rhel5.8的系統上安裝配置cacti html
****************************************************************************************
上面說過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平臺,腳本內容以下mysql
- #!/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
執行此腳本便可, 若是不想使用腳本安裝的話,能夠參考
http://ant595.blog.51cto.com/5074217/920996 不過須要注意的是在編譯安裝php的時候須要加 --enable-sockets 參數,
web
二,安裝SNMP
1, 使用yum方式安裝,sql
- #yum -y install net-snmp net-snmp-devel net-snmp-utils
- 說明:
- net-snmp 此包是被監控端須要安裝的包
- net-snmp-utils 此包是監控端須要安裝的包
2, 配置SNMP數據庫
- #vim /etc/snmp/snmpd.conf 編輯snmp主配置文件修改如下內容
- com2sec notConfigUser 127.0.0.1 public
- access notConfigGroup "" any noauth exact all none none
- view all included .1 80
3,啓動snmpd服務apache
- #chkconfig snmpd on
- #service snmpd restart
三, 編譯安裝rrdtool
1, 編譯安裝rrdtoolbootstrap
- #cd /usr/src
- #tar xzvf rrdtool-1.4.7.tar.gz
- #cd rrdtool-1.4.7
- #./configure --prefix=/usr/local/rrdtool
- #make
- #make install
四,安裝配置cacti
1, 配置cactivim
- #cd /usr/src
- #tar xzvf cacti-0.8.8a.tar.gz
- #mv cacti-0.8.8a/* /cacti/
- #chown -R root:root /cacti
- #chmod -R a+w /cacti/log /cacti/rra
2,導入cacti所需數據庫並創建cacti所使用的數據庫用戶瀏覽器
- #mysql -e "create database cacti;"
- #mysql cacti < /cacti/cacti.sql
- #mysql -e "grant all privileges on cacti.* to cacti@localhost identified by 'redhat';"
- #mysql -e "flush privileges;"
3,修改cacti配置文件
- #vim /cacti/include/config.php
- $database_type = "mysql";
- $database_default = "cacti";
- $database_hostname = "localhost";
- $database_username = "cacti";
- $database_password = "redhat";
- $database_port = "3306";
- $database_ssl = false;
- $url_path = "/";
4,安裝cacti-spine
- #cd /usr/src
- #tar xzvf cacti-spine-0.8.8a.tar.gz
- #cd cacti-spine-0.8.8a
- #./configure
- #make
- #make install
5,配置cacti-spine
- #vim /usr/local/spine/etc/spine.conf
- DB_Host localhost
- DB_Database cacti
- DB_User cacti
- DB_Pass redhat
- DB_Port 3306
- DB_PreG 0
6,將spine命令加入系統搜索路徑
- #ln -sv /usr/local/spine/bin/spine /sbin/
7,生成初始圖像文件
- #vim /usr/local/php/etc/php.ini 修改如下內容
- date.timezone = Asia/Shanghai 若是不修改此行配置的話,執行下面的命令會報錯,
- #/usr/local/php/bin/php /cacti/poller.php
- #crontab -e 內容以下
- */5 * * * * /usr/local/php/bin/php /cacti/poller.php &>/dev/null
8,安裝cacti, 上面說過cacti是一個php開發的web頁面,那麼虛擬主機確定是要配置的,上面的腳本中已經配置過了,域名是cacti.andy.com
8.1 在瀏覽器中輸入cacti.andy.com 將看到cacti的安裝界面, 前提是客戶端要能訪問cacti.andy.com的域名,見圖,
8.4,輸入cacti的用戶及密碼,默認的用戶及密碼爲admin
8.5,第一次登陸須要重置下admin的密碼.
8.7 點擊左上角的graphs-->localhost, 能夠看到默認監控本機的圖像了,若是沒有圖像執行下以下命令
- #/usr/local/php/bin/php /cacti/poller.php
OK,到這裏已經安裝配置好了,後面會再寫篇博客介紹cacti的使用,