原先我裝的是 ntop-3.3.9-7.el5.i386.rpm ,但是這個版本啟動時就出現無法開啟 GeoIP 檔案的問題,後來在設定 ntop.conf 又遇到當使用 --known-subnets 參數時,ntop 就會啟動失敗。沒有 --known-subnets 功能,其他內部網段跟 Internet 的資訊混在一起,這點我的環境實在不方便。而且不定時就 crash ,就算換其他版本還是一樣。問了 Google 大神,祂給了許多不確定的答案,哎......
在眾多答案之中唯一公認較好的方式:還是自己 make 。好吧,那就來吧!
環境
OS:CentOS 5.4
Kernel: 2.6.26.10(自行編釋)
eth1: (Internet)
eth0: 192.168.10.0/24 ,透過其它 router 會有 192.168.0.0/16 的網段
安裝 CentOS 5 已具備的 rpm 套件: zlib zlib-devel libtool libtool-ltdl automake autoconf libpcap libevent gdbm m4 openssl openssl-devel
# yum -y install zlib zlib-devel libtool libtool-ltdl automake autoconf libpcap libpcap-devel libevent gdbm gdbm-devel m4 openssl openssl-devel
安裝其他 rpm 套件: rrdtool rrdtool-devel
i386:
# wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/i386/rrdtool-1.2.27-3.el5.i386.rpm
# wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/i386/rrdtool-devel-1.2.27-3.el5.i386.rpm
x86_64:
# wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/x86_64/rrdtool-1.2.27-3.el5.x86_64.rpm
# wget ftp://ftp.pbone.net/mirror/download.fedora.redhat.com/pub/fedora/epel/5/x86_64/rrdtool-devel-1.2.27-3.el5.x86_64.rpm
# rpm -Uvh rrdtool-1.2.27-3.el5.x86_64.rpm rrdtool-devel-1.2.27-3.el5.x86_64.rpm
編譯及安裝 ntop-3.3.10
# wget http://downloads.sourceforge.net/project/ntop/ntop/ntop-3.3.10/ntop-3.3.10.tar.gz?use_mirror=ncu
# tar xzf ntop-3.3.10.tar.gz
# cd ntop-3.3.10/
# ./autogen.sh
出現以下錯誤訊息:
Error! You need to have libevent 1.4.X or better.
# rpm -qa | grep libevent
libevent-1.1a-3.2.1
查一下CentOS5.4 的 libevent 的版本是 1.1a ,其他的 rpm 也只到 1.3,所以只好自行 make 。
編譯及安裝 libevent-1.4.13-stable.tar.gz
# wget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz
# tar xzf libevent-1.4.13-stable.tar.gz
# cd libevent-1.4.13-stable/
# ./configure
# make
# make install
libevent 會裝至下列目錄:
/usr/local/lib
/usr/local/include
/usr/local/share/man/man3
裝好 libevent-1.4.13-stable,再做一次!
# ./autogen.sh
如果 TCP 80 port 網路不通時,就要自行下載以下四個檔案,放在 ntop-3.3.10/
http://www.lua.org/ftp/lua-5.1.4.tar.gz
http://www.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
http://www.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz
# ./autogen.sh
出現以下錯誤訊息:
configure: error: cannot find macro directory `m4'
建立 m4 目錄後,再做一次!
# mkdir m4
# ./autogen.sh
終於看到令人感動的訊息:
.... autogen.sh done
just type make to compile ntop
# make
# make install
建立帳號 ntop(uid:105) 及群組 ntop(gid:105) ,uid gid 自行決定
# echo 'ntop:x:105:105:ntop:/usr/local/var/ntop:/sbin/nologin' >> /etc/passwd
# echo 'ntop:x:105:' >> /etc/group
建立及設定 /usr/local/etc/ntop.conf
# vi /usr/local/etc/ntop.conf
--user ntop
--db-file-path /usr/local/var/ntop
--interface eth0
-4
-x 16384
-X 65536
--trace-level 3
--http-server 3000
--disable-schedyield
--skip-version-check=yes
--local-subnets 192.168.0.0/16
--known-subnets 192.168.0.0/16
--db-file-path /usr/local/var/ntop
--interface eth0
-4
-x 16384
-X 65536
--trace-level 3
--http-server 3000
--disable-schedyield
--skip-version-check=yes
--local-subnets 192.168.0.0/16
--known-subnets 192.168.0.0/16
註:ntop 會自動設定 eth0 上的網段,以我的環境為例:我的 eth0 是 192.168.10.0/24 ,在 ntop.conf 就不用特別定義 192.168.10.0/24 ,但因為我的 eth0 透過其它 router 會有 192.168.0.0/16 上的 host ,為了分類上的方便才使用 --local-subnets 及 --known-subnets 來定義 192.168.0.0/16 。
目錄建立與權限設定
# mkdir /usr/local/var/ntop/rrd
# chmod 700 /usr/local/var/ntop/rrd
# chown -R ntop:ntop /usr/local/share/ntop /usr/local/etc/ntop /usr/local/var/ntop/rrd
目錄建立與權限設定
# mkdir /usr/local/var/ntop/rrd
# chmod 700 /usr/local/var/ntop/rrd
# chown -R ntop:ntop /usr/local/share/ntop /usr/local/etc/ntop /usr/local/var/ntop/rrd
建立 admin 密碼
# ntop @/usr/local/etc/ntop.conf --set-admin-password=<密碼>
建立 ntop 為 Daemon Service
# vi /etc/rc.d/init.d/ntop
#!/bin/bash
# Source function library.
. /etc/rc.d/init.d/functions
# Path to the ntop program
prog=ntop
ntop=/usr/local/bin/$prog
pidfile=/var/run/$prog.pid
config=/usr/local/etc/$prog.conf
start() {
echo -n $"Starting $prog: "
[ -x $ntop ] || exit 1
[ -r "$config" ] || exit 6
if [ ! -r "/usr/local/var/$prog/${prog}_pw.db" ]; then
echo "service not configured, run $prog manually"
exit 6
fi
# ntop has string errors in locales other than "C"
LANG=C daemon "$ntop @$config --daemon > /dev/null"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $ntop
RETVAL="$?"
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $pidfile
}
reload() {
echo -n $"Reloading $prog: "
killproc $ntop -HUP
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $ntop
RETVAL=$?
;;
restart)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f $pidfile ] ; then
stop
start
fi
RETVAL=$?
;;
reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status}"
RETVAL=3
esac
exit $RETVAL
註:此 script 取自 ntop-3.3.9-7.el5.i386.rpm ,我修改路徑而已。
# chmod 755 /etc/rc.d/init.d/ntop
# chown root:root /etc/rc.d/init.d/ntop
# chkconfig --add ntop
# chkconfig ntop on
# service ntop start
建立 ntop 為 Daemon Service
# vi /etc/rc.d/init.d/ntop
#!/bin/bash
# Source function library.
. /etc/rc.d/init.d/functions
# Path to the ntop program
prog=ntop
ntop=/usr/local/bin/$prog
pidfile=/var/run/$prog.pid
config=/usr/local/etc/$prog.conf
start() {
echo -n $"Starting $prog: "
[ -x $ntop ] || exit 1
[ -r "$config" ] || exit 6
if [ ! -r "/usr/local/var/$prog/${prog}_pw.db" ]; then
echo "service not configured, run $prog manually"
exit 6
fi
# ntop has string errors in locales other than "C"
LANG=C daemon "$ntop @$config --daemon > /dev/null"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $ntop
RETVAL="$?"
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $pidfile
}
reload() {
echo -n $"Reloading $prog: "
killproc $ntop -HUP
RETVAL=$?
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $ntop
RETVAL=$?
;;
restart)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f $pidfile ] ; then
stop
start
fi
RETVAL=$?
;;
reload)
reload
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status}"
RETVAL=3
esac
exit $RETVAL
註:此 script 取自 ntop-3.3.9-7.el5.i386.rpm ,我修改路徑而已。
# chmod 755 /etc/rc.d/init.d/ntop
# chown root:root /etc/rc.d/init.d/ntop
# chkconfig --add ntop
# chkconfig ntop on
# service ntop start
ntop 會安裝至下列目錄:
/usr/local/bin
/usr/local/etc
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/lib
/usr/local/man/man8
/usr/local/share/ntop
/usr/local/var/ntop
參考資料:
http://forum.icst.org.tw/phpbb/viewtopic.php?f=24&t=14843
/usr/local/share/ntop
/usr/local/var/ntop
參考資料:
http://forum.icst.org.tw/phpbb/viewtopic.php?f=24&t=14843