一、介紹
ntopng 高速的基於Web的流量分析與集流工具。ntopng是NTOP的新一代版本,官方原先版本的NTOP已經不再更新。ntopng是原ntop下一代版本,網絡流量實時監控顯示。ntop是基於Libpcap和它被寫在一個可移植的方式來運行在UNIX平台上,MacOSX和Win32一樣。再稍微具體點的自行上網查,下面連接是github和官網。
二、安裝
在官網中和github上面這些其實都有,簡單重復下:
我使用的是Centos平台,需要安裝一些依賴的軟件包,首先是開發工具的一大堆包
yum groupindatll 'Development Tools'
隨后安裝各種依賴的小包,github上有詳細的介紹,每個ntopng的版本可能依賴不同,但是大體上沒什么具體的變化,前提我安裝了 epel-release,下面這些包都有
yum install git autoconf automake autogen bison flex libpcap-devel libmaxminddb-devel hiredis-devel redis glib2-devel libxml2-devel sqlite-devel gcc-c++ libtool wget libcurl-devel pango-devel cairo-devel libpng-devel mysql-devel libnetfilter_queue-devel zlib-devel which libcap-devel readline-devel zeromq-devel json-c-devel geoipupdate
在github上是給出了 yum 安裝 redis 數據庫,但這里我想使用編譯來安裝redis,使用的版本是redis-4.0.11.tar,將軟件包放在/usr/local目錄下,如下:
cd /usr/local tar -xvf redis-4.0.11.tar cd redis-4.0.11.tar make make install #提示缺什么軟件包就安什么,干就完了
簡單的配置一下redis,如下:
cd /usr/local/redis-4.0.11/utils #這個下面有些好東西,會用到 cp -ra redis_init_script /etc/init.d/redis #可以簡單的掃一眼這個文件內容,看依賴哪個文件夾下面的配置
如圖可以看到,依賴一個/etc/redis/6379.conf 的文件,那就安排上
cd /usr/local/redis-4.0.11/utils
cp -ra redis.conf /etc/redis/6379.conf
redis啟動的時候默認是在前台啟動的,咱們可以改下配置文件放到后台,編輯它的配置文件,改一個yes 就可以的
然后就可以chkconfig --add redis , service redis start 之類的
下面回到 ntopng
cd /usr/local/ mkdir ntopng cd ntopng git clone git://github.com/ntop/ntopng.git #有點慢,等一等就好 git clone git://github.com/ntop/nDPI.git #nDPI是ntopng依賴的,我可能解釋有誤,可以自行到官網看一看 #下載完成后 cd nDPI/ ./autogen.sh ./configure make #到此為止,這一塊就完了,下面重頭戲,你會發現你缺少好多的依賴包 cd /usr/local 下載一個libmaxminddb-1.4.2.tar.gz,geoIP會用到該包 tar -xvf libmaxminddb-1.4.2.tar.gz cd libmaxminddb-1.4.2 ./configure make make install ldconfig
這里有一個坑,在后面編譯 ntopng 的時候 才會報出來,是關於集成在ntopng的tar包中的一個問題,在 /usr/local/ntopng/third-party/zeromq-4.1.7 下面,這個zeromq是有問題的,缺少一些東西,
問題如下所示:
cd /root/ntopng/third-party/zeromq-4.1.7; ./configure --without-documentation --without-libsodium; make configure: error: cannot find install-sh, install.sh, or shtool in config "."/config make[1] : on entre dans le répertoire ? /root/ntopng/third-party/zeromq-4.1.7 ? Makefile:2497: tweetnacl/src/.deps/libzmq_la-tweetnacl.Plo: Aucun fichier ou dossier de ce type make[1]: *** Aucune règle pour fabriquer la cible ? tweetnacl/src/.deps/libzmq_la-tweetnacl.Plo
我查找了論壇的一些評論才發現問題所在,解決方法如下
查找GitHub: Seems install-sh, install.sh, or shtool is not present in /root/ntopng/third-party/zeromq-4.1.7 解決方法: wget https://github.com/zeromq/zeromq4-1/releases/download/v4.1.7/zeromq-4.1.7.tar.gz -O /tmp/zeromq-4.1.7.tar.gz tar xf /tmp/zeromq-4.1.7.tar.gz -C /root/ntopng/third-party/
還有就是Geoip的用法,發現是僅僅把他們放在特定目錄下即可
Maxmind has changed its databases and library and ntopng has been updated as well to keep this into account. GeoLite2-ASN.mmdb GeoLite2-City.mmdb are the new file databases: ?if you are installing a packaged version of ntopng, those files will be pulled in automatically ?if you are building ntopng from sources, you can run make geoip to download them Then, just place them under httpdocs/geoip/ and ntopng will automatically pick them.
所以你可以自行去maxmind的網站上下載這些,GeoLite2-ASN_20200225.tar.gz GeoLite2-City_20200225.tar.gz GeoLite2-Country_20200225.tar.gz
解壓后放在目錄中,繼續進行編譯ntopng
cd /usr/local/ntopng ./autogen.sh ./configure make make install
就這樣完成了,下面進行一些基本的配置,但需要參考說明,https://www.ntop.org/guides/ntopng/cli_options.html
在安裝包中這里有點好東西,contrib/NST 目錄下,可以看到:
所以我們可以簡單的配置一下:
cp -ra ntopng /etc/sysconfig/ cp -ra ntopng.service /usr/lib/systemd/system/ mkdir -pv /etc/ntopng cp -ra ntopng.conf /etc/ntopng
隨后我們還要配置一下環境變量,找到/root/.bash_profile 進行添加 ,如下:
然后執行 source /root/.bash_profile 命令,這樣 環境變量也配置完成了。
創建 組 和 用戶 ,要不然默認使用nobody用戶運行
groupadd ntopng useradd -g ntopng ntopng su - ntopng #切換用戶過去 ,創建文件和目錄 mkdir /home/ntopng/data mkdir -pv /home/ntopng/var/;touch /home/ntopng/var/pid
再來看一下ntopng的配置文件,cat /etc/ntopng/ntopng.conf | grep -v "#"
--interface bond0 --http-port 3000 --local-networks 192.168.32.0/24 --data-dir /home/ntopng/data --dns-mode 1 --disable-autologout --disable-alerts --sticky-hosts none #--daemon #如果用systemctl進行控制的話,就不需要添加這行,如果手動控制的話,需要添加 --user ntopng --pid /home/ntopng/var/pid #這是一個目錄下的文件
暫時就弄這么多,具體的解釋及需要自行看看說明文檔
隨后需要修改systemctl 的腳本信息,需要滿足 咱們自己搭建的系統 環境,如下:
vim /usr/lib/systemd/system/ntopng.service #剛剛從utils中復制過來的文件,需要修改下 [Unit] Description=ntopng Service Requires=redis.service After=syslog.target network.target redis.service [Service] TimeoutStopSec=10s EnvironmentFile=/etc/sysconfig/ntopng WorkingDirectory=/home/ntopng/data #主要是工作目錄需注意 ExecStart=/usr/local/bin/ntopng $OPTIONS #啟動命令在什么位置也需要注意 [Install] WantedBy=multi-user.target
隨后執行命令:
systemctl enable ntopng systemctl start ntopng
連接3000短褲就可以看到界面了,一些小的細節可以自行進行微調。