資安論壇

行政院 國家資通安全會報 - 技術服務中心 - 資安論壇 http://forum.icst.org.tw/
現在的時間是 週六 7月 31, 2010 10:59 am

所有顯示的時間為 UTC + 8 小時




發表新文章 回覆主題  [ 2 篇文章 ] 
發表人 內容
 文章主題 : [教學][研究] MRTG 快速安裝程式 (CentOS 5.1)
文章發表於 : 週五 4月 18, 2008 12:16 pm 
離線

註冊時間: 週三 9月 25, 2002 10:57 am
文章: 7359
來自: R.O.C
[教學][研究] MRTG 快速安裝程式 (CentOS 5.1)

MRTG官方安裝方法
http://oss.oetiker.ch/mrtg/doc/mrtg-unix-guide.en.html

修改後的步驟重點說明

(1)安裝 gcc , perl, gd, libpng, zlib, mrtg , snmp, httpd 等套件

代碼:
yum  -y  install  gcc  perl  gd  libpng  zlib  mrtg


(2) yum 安裝的 net-snmp 似乎有問題, 只好自己去下載, 安裝, 執行

http://net-snmp.sourceforge.net/

代碼:
tar  zxvf  net-snmp-5.4.1.tar.gz
cd  net-snmp-5.4.1
./configurfe
make
make  install
/bin/cp -f  ./python/netsnmp/tests/snmpd.conf   /usr/local/etc/snmp/snmpd.conf


在 /usr/local/etc/snmp/snmpd.conf 增加兩行
數值意義請參考
http://oss.oetiker.ch/mrtg/doc/mrtg-mibhelp.en.html

代碼:
view systemview included .1.3.6.1.2.1.2.2.1.10
view systemview included .1.3.6.1.2.1.2.2.1.16


把系統中現有的 snmpd 停掉, 執行新安裝的

代碼:
killall snmpd
/usr/local/sbin/snmpd  -c   /usr/local/etc/snmp/snmpd.conf


(3) 編輯 MRTG 設定檔

編輯 /etc/mrtg/mrtg.cfg , 內容只要有下面即可

代碼:
Target[eth0]: 2:public@127.0.0.1"
MaxBytes[eth0]: 1250000"
Title[eth0]: Traffic Analysis"
PageTop[eth0]: <H1>127.0.0.1 eth0</H1>


public 前面的數字可用下面偵測, 一般 eth0 代號是 2
代碼:
ip  link


(4) 產生基本網頁

執行 3 次下面指令, 產生基本網頁
代碼:
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg


(5) 產生 MRTG 首頁

執行
代碼:
indexmaker /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html


(6) 設定排程

vi /etc/crontab 增加一行

代碼:
*/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg  > /dev/null 2>&1


(7) 啟動 MRTG 監控

代碼:
firefox http://localhost/mrtg &


最後由 lu 於 週五 4月 18, 2008 2:34 pm 編輯,總共編輯了 4 次。

回頂端
   
 
 文章主題 :
文章發表於 : 週五 4月 18, 2008 2:28 pm 
離線

註冊時間: 週三 9月 25, 2002 10:57 am
文章: 7359
來自: R.O.C
[教學][研究] MRTG 快速安裝程式 (CentOS 5.1)

MRTG為一個使用甚廣的網路流量統計軟體,它神奇的地方在於能即時地繪出網路流量的統計圖。

MRTG官方安裝方法
http://oss.oetiker.ch/mrtg/doc/mrtg-unix-guide.en.html

這是小弟寫的快速安裝程式, 基本上都使用 yum 安裝
除了 snmp 似乎有問題 (請看下篇)

[研究] snmpd dead but pid file exists
http://forum.icst.org.tw/phpBB2/viewtopic.php?t=14861

net-snmp-5.4.1.tar.gz 請自己到下面抓下
http://downloads.sourceforge.net/net-sn ... g_mirror=1

小弟本想用 wget 抓下, 結果抓完後就停住, 按下 Enter 居然跳出 Shell Script

代碼:

echo -e "\033[34m"
echo -e "############################################"
echo -e " MRTG Install Shell Script (CentOS 5.1) "
echo -e " by Lu 2008/04/18 "
echo -e "############################################"
echo -e "\033[0m"

DEBUG=n

if [ "`cat /proc/version | grep centos | grep el5`" != "" ]; then
  OS="CentOS 5.x"
  echo "Detection your OS is CentOS 5.x"
else
  echo "[ERROR] Only Support CentOS 5.x"
  exit
fi

echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Internet Connection Check "
echo -e "####################################"
echo -e "\033[0m"

echo -e "\033[32mCheck...\033[0m"
if [ "`ping  www.hinet.net  -c 1 | grep ttl `"  !=  "" ]; then
  echo "Internet Online"
else
  echo "Internet Offline"
  exit
fi 

if [ "$DEBUG" == "y" ]; then echo "Press any key to continue..." ; read ; fi

echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " ntpdate tick.stdtime.gov.tw "
echo -e "####################################"
echo -e "\033[0m"

echo -e "\033[32mKill nptd on running...\033[0m"
ProcessID="`ps aux | grep ntpd | awk '{print $2}' `"
for i in $ProcessID
do
  echo $i
  kill -9 $i
done
ntpdate tick.stdtime.gov.tw
if [ "$DEBUG" == "y" ]; then echo "Press any key to continue..." ; read ; fi

echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Configure MRTG Install Enviroment "
echo -e "####################################"
echo -e "\033[0m"

echo -e "\033[32myum -y install net-snmp mrtg gd libpng zlib sysstat gcc\033[0m"

echo -e "\033[31m'yum -y install net-snmp' has serious BUG on CentOS 5.x (net-snmp 5.3.x rpm has BUG) \033[0m"
echo -e "\033[31mservice snmpd start, ps aux | grep, you will find that snmpd does not run \033[0m"
echo -e "\033[31mI will use tar.gz to install net-snmp 5.4.x \033[0m"

echo -e "\033[32mKill yum on running...\033[0m"
ProcessID="`ps aux | grep yum | awk '{print $2}' `"
for i in $ProcessID
do
  echo $i
  kill -9 $i
done

YUMARGS=""

if [ "`rpm -q httpd | grep not`" != "" ]; then
  YUMARGS="$YUMARGS httpd"
  echo "httpd not installed"
else
  echo "httpd installed" 
fi

if [ "`rpm -q mrtg | grep not`" != "" ]; then
  YUMARGS="$YUMARGS mrtg"
  echo "mrtg not installed"
else     
  echo "mrtg installed" 
fi 

if [ "`rpm -q gd | grep not `" != "" ]; then
  YUMARGS="$YUMARGS gd"
  echo "gd not installed"
else
  echo "gd installed" 
fi

if [ "`rpm -q libpng | grep not `" != "" ]; then
  YUMARGS="$YUMARGS libpng"
  echo "libpng not installed"
else
  echo "libpng installed" 
fi

if [ "`rpm -q zlib | grep not `" != "" ]; then
  YUMARGS="$YUMARGS zlib"
  echo "zlib not installed"
else
  echo "zlib installed" 
fi

if [ "`rpm -q sysstat | grep not `" != "" ]; then
  YUMARGS="$YUMARGS sysstat"
  echo "sysstat not installed"
else
  echo "sysstat installed" 
fi

if [ "`rpm -q gcc | grep not `" != "" ]; then
  YUMARGS="$YUMARGS gcc"
  echo "gcc not installed"
else
  echo "gcc installed" 
fi

#echo $YUMARGS

if [ ! "$YUMARGS" == "" ]; then
  echo -e "\033[32mrm -fr /var/cache/yum \033[0m"
  rm -fr /var/cache/yum
  echo -e "\033[32myum -y install $YUMARGS \033[0m" 
  yum -y install $YUMARGS
fi

if [ ! -s net-snmp-5.4.1.tar.gz ]; then
  #wget http://downloads.sourceforge.net/net-snmp/net-snmp-5.4.1.tar.gz?modtime=1185535805&big_mirror=1
  # bug ? wget finish will quit shell scipt
  echo "Not found net-snmp-5.4.1.tar.gz"
  exit
fi

echo -e "\033[32mtar zxvf net-snmp-5.4.1.tar.gz \033[0m"
tar zxvf net-snmp-5.4.1.tar.gz

echo -e "\033[32mcd net-snmp-5.4.1 \033[0m"
cd net-snmp-5.4.1
pwd

echo -e "\033[32m./configure \033[0m"
./configure
echo -e "\033[32mmake \033[0m"
make
echo -e "\033[32mmake install \033[0m"
make install

mkdir /usr/local/etc/snmp
/bin/cp -f ./python/netsnmp/tests/snmpd.conf   /usr/local/etc/snmp/snmpd.conf
/bin/cp -f ./python/netsnmp/tests/snmpd.conf   /usr/local/etc/snmp/snmpd.conf.OLD

echo -e "\033[32mchkconfig httpd on \033[0m"
chkconfig httpd on
echo -e "\033[32mservice httpd restart \033[0m"
service httpd restart
echo -e "\033[32mkillall snmpd \033[0m"
killall snmpd
echo -e "\033[32m/usr/local/sbin/snmpd \033[0m"
/usr/local/sbin/snmpd

echo -e "\033[32mModify /etc/mrtg/mrtg.cfg\033[0m"
if [ ! -s  /etc/mrtg/mrtg.cfg.OLD ]; then
/bin/cp -f  /etc/mrtg/mrtg.cfg  /etc/mrtg/mrtg.cfg.OLD
fi
/bin/cp -f  /etc/mrtg/mrtg.cfg.OLD  /etc/mrtg/mrtg.cfg
#delete old setting
sed -i -e "/eth0/d" /etc/mrtg/mrtg.cfg
#add new setting
echo "Target[eth0]: 2:public@127.0.0.1" >> /etc/mrtg/mrtg.cfg
echo "MaxBytes[eth0]: 1250000" >> /etc/mrtg/mrtg.cfg
echo "Title[eth0]: Traffic Analysis" >> /etc/mrtg/mrtg.cfg
echo "PageTop[eth0]: <H1>127.0.0.1 eth0</H1>" >> /etc/mrtg/mrtg.cfg

echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Modify /etc/crontab "
echo -e "####################################"
echo -e "\033[0m"


echo -e "\033[32mModify /etc/crontab\033[0m"
#echo "Deleting old setting , Adding MRTG to /etc/crontab..."
sed -i -e "/mrtg/d"  /etc/crontab
echo "*/5 * * * * root env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg  > /dev/null 2>&1 " >> /etc/crontab
echo "" >> /etc/crontab

echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Modify snmpd.conf "
echo -e "####################################"
echo -e "\033[0m"

echo -e "\033[32mModify snmpd.conf\033[0m"

echo "view systemview included .1.3.6.1.2.1.2.2.1.10" >> /usr/local/etc/snmp/snmpd.conf
echo "view systemview included .1.3.6.1.2.1.2.2.1.16" >> /usr/local/etc/snmp/snmpd.conf
killall snmpd
/usr/local/sbin/snmpd  -c   /usr/local/etc/snmp/snmpd.conf


echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Modify /etc/httpd/conf.d/mrtg.conf "
echo -e "####################################"
echo -e "\033[0m"

echo -e "\033[32mModify /etc/httpd/conf.d/mrtg.conf\033[0m"
if [ ! -s  /etc/httpd/conf.d/mrtg.conf.OLD ]; then
/bin/cp -f  /etc/httpd/conf.d/mrtg.conf  /etc/httpd/conf.d/mrtg.conf.OLD
fi
/bin/cp -f  /etc/httpd/conf.d/mrtg.conf.OLD  /etc/httpd/conf.d/mrtg.conf
#Allow monitor from anywhere
sed -i -e "s@Deny from all@#Deny from all@" /etc/httpd/conf.d/mrtg.conf


echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Configure CPU Monitor "
echo -e "####################################"
echo -e "\033[0m"

echo -e "\033[32m********** Set CPU Monitor **********\033[0m"
#yum -y install sysstat

echo -e "\033[32mMake /etc/mrtg/cpu.sh\033[0m"
echo "#!/bin/bash" > /etc/mrtg/cpu.sh
echo "cpuusr=\`/usr/bin/sar -u 1 3 | grep Average | awk '{print \$3}'\`  " >> /etc/mrtg/cpu.sh
echo "cpusys=\`/usr/bin/sar -u 1 3 | grep Average | awk '{print \$5}'\`  " >> /etc/mrtg/cpu.sh
echo "UPtime=\`/usr/bin/uptime | awk '{print \$3\"\"\$4\"\"\$5}'\`  " >> /etc/mrtg/cpu.sh
echo "echo \$cpuusr  " >> /etc/mrtg/cpu.sh
echo "echo \$cpusys  " >> /etc/mrtg/cpu.sh
echo "echo \$UPtime  " >> /etc/mrtg/cpu.sh
echo "hostname  " >> /etc/mrtg/cpu.sh

#/bin/cp -f cpu.sh /etc/mrtg/cpu.sh
chmod 755 /etc/mrtg/cpu.sh

echo -e "\033[32mModify /etc/mrtg/mrtg.cfg\033[0m"

sed -i -e "/cpu/d" /etc/mrtg/mrtg.cfg
echo " "  >> /etc/mrtg/mrtg.cfg
echo "Target[cpu]: \`/etc/mrtg/cpu.sh\`  " >> /etc/mrtg/mrtg.cfg
echo "MaxBytes[cpu]: 100  " >> /etc/mrtg/mrtg.cfg
echo "Options[cpu]: gauge, nopercent, growright    " >> /etc/mrtg/mrtg.cfg
echo "YLegend[cpu]: CPU loading (%)  " >> /etc/mrtg/mrtg.cfg
echo "ShortLegend[cpu]: %  " >> /etc/mrtg/mrtg.cfg
echo "LegendO[cpu]: &nbsp; CPU us;  " >> /etc/mrtg/mrtg.cfg
echo "LegendI[cpu]: &nbsp; CPU sy;  " >> /etc/mrtg/mrtg.cfg
echo "Title[cpu]: CPU Loading  " >> /etc/mrtg/mrtg.cfg
echo "PageTop[cpu]: <H1>CPU Loading</H1>  " >> /etc/mrtg/mrtg.cfg


echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Configure Memory Monitor "
echo -e "####################################"
echo -e "\033[0m"

echo -e "\033[32myum -y install sysstat\033[0m"
#yum -y install sysstat

echo -e "\033[32mMake /etc/mrtg/mem.sh\033[0m"

echo "#!/bin/bash  " > /etc/mrtg/mem.sh
echo "# run this script to check the mem usage.  " >> /etc/mrtg/mem.sh
echo "totalmem=\`/usr/bin/free |grep Mem |awk '{print \$2}'\`  " >> /etc/mrtg/mem.sh
echo "usedmem=\`/usr/bin/free |grep Mem |awk '{print \$3}'\`  " >> /etc/mrtg/mem.sh
echo "UPtime=\`/usr/bin/uptime | awk '{print \$3\"\"\$4\"\"\$5}'\`  " >> /etc/mrtg/mem.sh
echo "echo \$totalmem  " >> /etc/mrtg/mem.sh
echo "echo \$usedmem  " >> /etc/mrtg/mem.sh
echo "echo \$UPtime  " >> /etc/mrtg/mem.sh
echo "hostname  " >> /etc/mrtg/mem.sh


#/bin/cp -f mem.sh /etc/mrtg/mem.sh
chmod 755 /etc/mrtg/mem.sh

echo -e "\033[32mModify /etc/mrtg/mrtg.cfg\033[0m"

sed -i -e "/ram/d" /etc/mrtg/mrtg.cfg
echo " "  >> /etc/mrtg/mrtg.cfg
echo "Target[ram]: \`/etc/mrtg/mem.sh\`  " >> /etc/mrtg/mrtg.cfg
echo "#Unscaled[ram]: dwym  " >> /etc/mrtg/mrtg.cfg
echo "MaxBytes[ram]: 2048000  " >> /etc/mrtg/mrtg.cfg
echo "Title[ram]:Memory  " >> /etc/mrtg/mrtg.cfg
echo "ShortLegend[ram]: &  " >> /etc/mrtg/mrtg.cfg
echo "kmg[ram]:kB,MB  " >> /etc/mrtg/mrtg.cfg
echo "kilo[ram]:1024  " >> /etc/mrtg/mrtg.cfg
echo "YLegend[ram]: &nbsp; Memory Usage :  " >> /etc/mrtg/mrtg.cfg
echo "Legend1[ram]: &nbsp; Total Memory :  " >> /etc/mrtg/mrtg.cfg
echo "Legend2[ram]: &nbsp; Used Memory :  " >> /etc/mrtg/mrtg.cfg
echo "LegendI[ram]: &nbsp; Total Memory :  " >> /etc/mrtg/mrtg.cfg
echo "LegendO[ram]: &nbsp; Used Memory :  " >> /etc/mrtg/mrtg.cfg
echo "Options[ram]: growright,gauge,nopercent  " >> /etc/mrtg/mrtg.cfg
echo "PageTop[ram]:<H1>Memory</H1>  " >> /etc/mrtg/mrtg.cfg


echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Configure Connections Monitor "
echo -e "####################################"
echo -e "\033[0m"

echo -e "\033[32myum -y install sysstat\033[0m"
#yum -y install sysstat

echo -e "\033[32mMake /etc/mrtg/connections.sh\033[0m"

echo "#!/bin/bash  " > /etc/mrtg/connections.sh
echo "echo \`netstat -a | grep www|awk '{print \$5}'|sort | wc -l|awk '{print\$1 - 1}'\`  " >> /etc/mrtg/connections.sh
echo "# netstat -a | grep www|awk '{print \$5}'|sort| uniq  " >> /etc/mrtg/connections.sh
echo "echo \`netstat -a | grep www|awk '{print \$5}'|cut -d\":\" -f1|sort| uniq |wc -l | awk '{print \$1 - 1}'\`  " >> /etc/mrtg/connections.sh
echo "# netstat -a | grep www|awk '{print \$5}'|cut -d\":\" -f1|sort| uniq  " >> /etc/mrtg/connections.sh
echo "UPtime=\`/usr/bin/uptime | awk '{print \$3 " " \$4 " " \$5}'\`  " >> /etc/mrtg/connections.sh
echo "echo \$UPtime  " >> /etc/mrtg/connections.sh
echo "echo yourwebserver.host.name  " >> /etc/mrtg/connections.sh

#/bin/cp -f connections.sh /etc/mrtg/connections.sh
chmod 755 /etc/mrtg/connections.sh

echo -e "\033[32mModify /etc/mrtg/mrtg.cfg\033[0m"

sed -i -e "/connections/d" /etc/mrtg/mrtg.cfg
echo " "  >> /etc/mrtg/mrtg.cfg
echo "Target[connections]: \`/etc/mrtg/connections.sh\`  " >> /etc/mrtg/mrtg.cfg
echo "MaxBytes[connections]: 500  " >> /etc/mrtg/mrtg.cfg
echo "Options[connections]: gauge, nopercent, growright  " >> /etc/mrtg/mrtg.cfg
echo "YLegend[connections]: Online Users  " >> /etc/mrtg/mrtg.cfg
echo "ShortLegend[connections]: %  " >> /etc/mrtg/mrtg.cfg
echo "LegendI[connections]: &nbsp; connections (Input) :  " >> /etc/mrtg/mrtg.cfg
echo "LegendO[connections]: &nbsp; connections (Output) :  " >> /etc/mrtg/mrtg.cfg
echo "Title[connections]: WWW connections  " >> /etc/mrtg/mrtg.cfg
echo "PageTop[connections]: <H1> WWW connections </H1>  " >> /etc/mrtg/mrtg.cfg
#echo "<TABLE>  " >> /etc/mrtg/mrtg.cfg
#echo "  <TR><TD>System:</TD>   <TD>WWW connections</TD></TR>  " >> /etc/mrtg/mrtg.cfg
#echo "  <TR><TD>Maintainer:</TD> <TD>Lu</TD></TR>  " >> /etc/mrtg/mrtg.cfg
#echo "</TABLE>  " >> /etc/mrtg/mrtg.cfg

#mii-tool
#ip  link

echo -e "\033[31m"
echo -e "############# Step #################################"
echo -e " To generate MRTG Log, suggest to run three times "
echo -e "####################################################"
echo -e "\033[0m"

#To generate MRTG Log, suggest to run three times
echo -e "\033[32menv LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg\033[0m"
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
echo -e "\033[32menv LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg\033[0m"
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
echo -e "\033[32menv LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg\033[0m"
env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " To generate index.html "
echo -e "##################################"
echo -e "\033[0m"

echo -e "\033[32mindexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg\033[0m"
indexmaker /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html

echo -e "\033[31m"
echo -e "############# Step ###############"
echo -e " Run MRTG "
echo -e "##################################"
echo -e "\033[0m"

echo -e "\033[32mps aux | grep snmpd \033[0m"
ps aux | grep snmpd
echo -e "\033[32m Configuration :/etc/mrtg/mrtg.cfg\033[0m"
echo -e "\033[32m Configuration :/etc/httpd/conf.d/mrtg.conf\033[0m"
echo -e "\033[32m Configuration :/usr/local/etc/snmp/snmpd.conf\033[0m"
echo -e "\033[32m Log :/var/log/snmpd.log \033[0m"

echo -e "\033[32mfirefox http://localhost/mrtg &\033[0m"
firefox http://localhost/mrtg &


相關文章

[教學][研究] MRTG 快速安裝程式 (CentOS 5.1)
http://forum.icst.org.tw/phpBB2/viewtopic.php?t=14871

[教學][研究] F7 (Fedora 7) 上安裝 MRTG (yum安裝)
http://forum.icst.org.tw/phpBB2/viewtopic.php?t=13689

FC4 (Fedora Core 4) 上如何安裝 MRTG
http://forum.icst.org.tw/phpBB2/viewtopic.php?t=7014

FC3 (Fedora Core 3) 上安裝 MRTG 步驟
http://forum.icst.org.tw/phpBB2/viewtopic.php?t=8168

監控網路鏈路流量負載軟體Mrtg使用指南
http://forum.icst.org.tw/phpBB2/viewtopic.php?t=7094

_________________
天道循環,生死不昧,真空妙有,還於本然!
諦聽我們的靈魂之聲,所有飄零的靈魂,此世虛幻,此生一夢,生者必死!
勢不可去盡,話不可說盡,福不可享盡,規矩不可行盡,凡事太盡,緣分勢必早盡!
免費貼圖空間 http://www.picfury.com/
免費貼圖空間 viewtopic.php?t=8816
免費上傳空間 viewtopic.php?t=6558


回頂端
   
 
顯示文章 :  排序  
發表新文章 回覆主題  [ 2 篇文章 ] 

所有顯示的時間為 UTC + 8 小時


誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客


不能 在這個版面發表主題
不能 在這個版面回覆主題
不能 在這個版面編輯文章
不能 在這個版面刪除文章

搜尋:
前往 :  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
正體中文語系由 竹貓星球 維護製作