亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

構建cacti監控平臺, LAMP使用腳本自動化編譯安裝

標簽:
MySQL


 在开始操作之前,先简单介绍几个概念

*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 "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 [email protected] 

        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 参数,

二,安装SNMP

1, 使用yum方式安装,

#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服务

#chkconfig snmpd on  

#service snmpd restart 

三, 编译安装rrdtool 

1, 编译安装rrdtool

#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, 配置cacti

#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.2 选择安装的方式

 

8.3, 设置cacti所需要依赖的一些软件及命令的位置,

 

8.4,输入cacti的用户及密码,默认的用户及密码为admin

 

8.5,第一次登录需要重置下admin的密码.

8.6,cacti的主界面,

8.7 点击左上角的graphs-->localhost, 可以看到默认监控本机的图像了,如果没有图像执行下如下命令

#/usr/local/php/bin/php /cacti/poller.php 

 

 

 

 OK,到这里已经安装配置好了,后面会再写篇博客介绍cacti的使用,

 

©著作权归作者所有:来自51CTO博客作者andy_f的原创作品,如需转载,请注明出处,否则将追究法律责任

监控cacti监控


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消