Shunze ¾Ç¶é >¹q¸£¸ê°T¾Ç¨t >¦Y³n¤£¦Yµw > ¡m¤À¨É¡nUbuntu¦w¸Ëntopng «¢Åo¡AÁÙ¨S¦³µù¥U©ÎªÌµn¤J¡C½Ð§A[µù¥U|µn¤J]
« ¤W¤@½g¥DÃD ¤U¤@½g¥DÃD » Åã¥Ü¦¨¦C¦L¼Ò¦¡ | ¼W¥[¨ì§Úªº³Ì·R
µoªí·s¥DÃD µoªí¦^ÂÐ
§@ªÌ
¥DÃD
shunze
¤u¤Í§B§B


µù¥U¤é´Á: 2002 04
¨Ó¦Û: ¼é¦Á²×¤î¤§¦a
¤å³¹: 2380

shunze Â÷½u
¡m¤À¨É¡nUbuntu¦w¸Ëntopng¤Þ¥Î¦^ÂÐ ½s¿è/§R°£¤å³¹ ·j´M¥Ñ  µoªíªº¨ä¥L¤å³¹ ¦^³øµ¹ª©¥D IP ¦ì¸m ¦^¦¹­¶³Ì¤W¤è

©ú©úntop¥Îªº¦n¦nªº¡A¦Ó¥B¤]ªá¤F®É¶¡¥h°µ°ÝÃDªº³B²z¡A¬°¤°»ò·Q¦w¸Ëntopng¡H
¨º¬O¦]¬°ntop¦bL7ªº¤ÀªR¤W°µªº¤£¦n¡Afacebook»Pyoutube³£µLªkÃѧO¡F
¦A¥[¤Whost name¦Ñ¬O³Q¸ÑĶ¬°©Ç©Çªºhost name¡A¦Ó¥BclientºÝ¥u¯àÃѧO¨ìwinxp¡C
¬JµMntop¶}µo¹Î¶¤³£¤£¦A³B²zntop¡A±N¾Ô¤O¶°¤¤¦b·s¤@¥Nªº¬y¶q¤ÀªR³nÅéntopng¡A
¨º»ò¤]¶¶À³¼é¬y¨ÓÅéÅç¤@¤Untopng§a¡ã

Ntopng©óubuntu 14.04ªº¦w¸Ë¡A½Ð°Ñ¦Ò³o¤@½g ntopng 1.2.2 on Ubuntu 14.04, revisited¡C
¥u­n·ÓµÛ§@ªÌ»¡©ú¡A¤@¨B¤@¨B¨Ì§Ç¦w¸Ë¡A°ò¥»¤W¬O¤£·|¦³¥ô¦ó°ÝÃD¡C
¤£¹L¬JµM­n°µµ§°O¡A´N¨Ó°µ­Ó¤¤¤åª©ªº¦w¸Ë°O¿ý§a¡ã


¦w¸Ë§¹ubuntu 14.04«á¡A½Ð¥ý§ó·s¤@¤U®M¥ó²M³æ¡C

apt-get update


¤U¸üntopngªºDebian®M¥óÀÉapt-ntop-stable.deb¡C


¦w¸ËdebÀÉ¡C
dpkg -i apt-ntop-stable.deb
¦^À³°T®§¦p¤U
Selecting previously unselected package apt-ntop-stable.
(Reading database ... 55712 files and directories currently installed.)
Preparing to unpack apt-ntop-stable.deb ...
Unpacking apt-ntop-stable (2.1-288) ...
Setting up apt-ntop-stable (2.1-288) ...
Adding ntop key to apt keyring
OK


³o®É¥i¥H¬d¬Ý¤@¤U»Pntop¦³Ãöªº®M¥ó¸ê°T¡C
dpkg -l | grep ntop
¦^À³°T®§¦p¤U
ii apt-ntop-stable 2.1-288 all ntop apt package repository


¦C¥X»Papt-ntop-stable¦³ÃöÁpªº¤å¥ó¡C
dpkg -L apt-ntop-stable
¦^À³°T®§¦p¤U
/.
/etc
/etc/nbox
/etc/nbox/ntop-apt.key
/etc/apt
/etc/apt/sources.list.d
/etc/apt/sources.list.d/ntop-stable.list


µM«á¦A¦¸§ó·s®M¥ó²M³æ¡C
apt-get update


³Ì«á³z¹Lapt-get«ü¥O¨Ó¦w¸Ënbox¬ÛÃö®M¥ó¡C
apt-get -y install pfring nprobe ntopng ntopng-data n2disk nbox
¸Ë§¹«á¡A¦^À³°T®§¦p¤U

IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT

You can now point your browser to https://localhost/

The default user is nbox with password nbox

IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT


³z¹Lapt-get¦w¸Ë¦nnbox®M¥ó«á¡A
ÁöµM¨t²Î¦^À³¤w¥i³z¹Lhttpsµn¤Jnbox¡A¦ý³o¸Ì¦³¤@­Óbug¡I
¦¹®Éµn¤Jhttps¯¸¥x®É¡A·|¥X²{ Service Unavailable ªº¿ù»~µe­±¡C

³o­Óbug«Ü²³æ³B²z¡A­«±Ò¤@¤Uapache2ªA°È¡A´N¥i¥H¸Ñ¨MÅo¡ã
service apache2 restart

­«±Òapache2ªA°È«á¡A¤w¥i¥Î¹w³]±b±K nbox/nbox µn¤Jnbox¯¸¥x¡C

¦w¸Ë§¹nbox«á¡AntopngÁÙ¥¼¯à¥¿±`´£¨ÑªA°È¡C
­nÅýntopng±Ò°Ê¡A»Ý¥ý¨ìApplications / ntopng / Configuration / General¤¤¶i¦æntopngªº²ÕºA³]©w¡C



¦b²ÕºA³]©w¤¤¡A°£¤F­n«ü©wºÊ±±ªº¬y¶q¤¶­±¥~¡A
ÁÙ¥i¥H³]©wntopng¦b¶}¾÷®É¦Û°Ê±Ò¥Î¡B¥»¦aºô¬q(¦hºô¥d®ÉÁÙº¡¦³¥Îªº)»P´£¨ÑªA°Èªºport(¹w³]¬°3000)¡C

³]©w§¹¦¨¡A«ö¤USave changes¡A¦^¨ìStatus­¶ÅÒ¡A©óntopng­n¤ÀªRªººô¥d¤¶­±¤W«ö¤UOn¡Antopng´N±Ò°Ê¤F¡ã



Ntopng¦¨¥\±Ò°Ê«á¡A´N¥i¥Hª½±µ¥H admin/admin ªº±b±K¤Îºô§} http://localhost:3000 ¨Óµn¤Jntopng¡C



Ntopngªº¥D­n¥\¯à°£¤Fdashboard¥~¡A°Ï¤À¬°Flow¡BHost»PInterface¡C

¦bFlow¤¤¡A¥i¥H¨Ìthroughput¨Ó±Æ§Ç¥Ø«eºô¸ô¤¤©Ò¦³applicationªº¬y¶q¡A³oºâ¬O¤ñ¸û±`¥Îªº¥\¯à¤§¤@¡C



¤]¥i¥H¨Ì¯S©wapplication¨Ó¶i¦æ±Æ§Ç¡C




¦bHost¤¤¡A¥i¶i¦æ©Ò¦³hostªº±Æ§Ç¡A°£¤F¥i¨Ìthroughput±Æ§Ç¥~¡AÁÙ¥i¥H¹LÂoLocal/RemoteªºhostÃþ§O¡C



·íµM¤]¥i¥H¹³¤W¤@¥Nntop¤@¼Ë¡A¬d¸ß¦U§Ohostªº¸ê°T¡C


¡ôª`·N¬Ý¡AWindows 8.1¤w¥i¦¨¥\ªº³QÃѧO¤F¡ã

¦U§OhostùØ´£¨Ñªº¸ê°Tºâ¬O¬Û·íÂ×´I¡A¨Ò¦ppeers¤¤·|Åã¥Ü¦¹host»Premote hostªº³s½uÀ³¥Î¸ê°T¡C



¦Óprotocols«h·|Åã¥Ü¦¹host©Ò¨Ï¥Îªº¦UºØL7 application¬y¶q¤ÀªR¡C



Flows«hÅã¥Ü¤Fhostªº»Premote hostªºthroughput¡C



Geomapºâ¬O¤@­Ó¤ñ¸û¬¯ªºpeerÅã¥Ü¤è¦¡¡C³z¹LGeomapÅã¥Ü¦¹host»Premote hostªº¦a°ì¥@¬ÉÆ[¡C


¡ô¨C¤@±ø³s½u·|¦]³s½u³t«×¤£¦P¡A¦Ó¥H¤£¦Pªº²¾°Ê³t«×¨ÓÅã¥Ü¡C

¦ÓHostùتºAutonomous Systems«h·|§â¤£¦P°Ï°ìªº¬y¶q¡A·J¾ãÅã¥Ü¡C




¦bInterfaceùØ¡A«h¥i¥H¨Ì«ü©wªº®É¶¡¶¡¹j¨ÓÅã¥Ü¾ã­Óºô¸ô¤¶­±ªº¬y¶q¹Ï¡C



·íµM¤]¥i¥H¨Ì¯S©wªºapplication¨ÓÅã¥Ü¨ä¬y¶q¡C



¤£¹L¡A³o³¡¤À»P¤W¤@¥Nntop¤ñ¸û°_¨Ó¡A¶¶¤lı±ontopng¤ñ¸û®z¡C
°£¤FµLªk¤@¦¸Åã¥Ü©Ò¦³application¥~¡AX¶b¤]¨S¦³®É¶¡Åã¥Ü¡A
¦b®É¶¡ªº¤ñ¹ï¤W¡A·|Åý¤H¤ñ¸û§xÂZ¡C

¥t¥~¦b¤W¤U¸üªº¾ú¥v±Æ§Ç¡Antopng°µªº«Ü®t¡A
§Ú§¹¥þ¬Ý¤£À´Top Hosts(local)ªº·N¸q¡A¤]¬Ý¤£À´Top Host Traffic¨º­Ó¯x°}±Æ¦C©Ò®i²{ªº¥ø¹Ï¡H
¦Ó¥BÁÙ¤Ö¤F¹L¥h¤@¤p®É¡A¤@¤Ñ¡A¤@¶g³o¨Ç¾ú¥v¬y¶q±Æ§Ç¡A
³o¥\¯à¦b¶¶¤l¬Ý¨Ó¡AÀ³¸Ó¬O«Ü­«­nªºªF¦è¤~¹ï¡I

Ntopngªº¥D­n¥\¯à´N¤À¨É¨ì³oÃä¡A¦³¿³½ìªºªB¤Í¥i¥H¦Û¤v¬[¤@­Ó¨Óª±ª±¬Ý¡A
¸òµÛ¦w¸Ë»¡©ú¤@¨B¨B¾Þ§@¡A«OÃÒ¦¨¥\¡I


°Ñ¦Ò¸ê®Æ
ntopng 1.2.2 on Ubuntu 14.04, revisited



♥¶¶¤l¦Ñ±Cªººô©ç¡A½Ð¦hÃö·Ó¡ã

If you don't like something, change it.
If you can't change it, change your attitude.
Don't complain!




2015-04-11, 10:12 shunze ªº­Ó¤H¸ê®Æ §â shunze ¥[¤J¦n¤Í¦Cªí µo°eEmailµ¹ shunze ÂsÄý shunze ªººô¯¸ MSN : shunze@gmail.com
shunze
¤u¤Í§B§B


µù¥U¤é´Á: 2002 04
¨Ó¦Û: ¼é¦Á²×¤î¤§¦a
¤å³¹: 2380

shunze Â÷½u
¡m¤À¨É¡nntopng¾ã²z§ó·s¤Þ¥Î¦^ÂÐ ½s¿è/§R°£¤å³¹ ·j´M¥Ñ  µoªíªº¨ä¥L¤å³¹ ¦^³øµ¹ª©¥D IP ¦ì¸m ¦^¦¹­¶³Ì¤W¤è

¸g¹L¤F´X¦¸ªº¦w¸Ë´ú¸Õ¡A¶¶¤l»Ý­n¹ïntopng°µÂI¸É¥R¡C

  1. nbox¬O·s¤@¥Nntopªº®M¥ó¾ã¦X¤¶­±¡A
    ¤º®e¥]§t¤F¤Fntopng¥~¡Bpfring¡Bnprobe¡Bn2diskµ¥¦h­Ó®M¥ó¡C
    ¥»¥H¬°¥u»Ý­nntopng®M¥óªº¸Ü¡A¥i¥H½Õ¾ã¬°¦p¤Uªº¤è¦¡¨Ó¶i¦æ¦w¸Ë¡C
    apt-get -y install ntopng ntopng-data nbox

    ¦ý¹ê»Ú¦w¸Ë¤§«á¡Aµo²{¤Ö¸Ë¤Fpfring¡Bnprobe¡Bn2diskµ¥®M¥óªº¸Ü¡Antopng¦b°õ¦æ®É·|¦]¬°¤Ö¤F«Ü¦h¥²­n®M¥ó¦ÓµLªk±Ò°Ê¡C

    ­Y¸ò¶¶¤l¤@¼Ë¨S¦³«H¤ß¡A«ØijÁÙ¬O§¹¾ã¸Ë¦n©Ò¦³nboxªº®M¥ó¡F
    ÁöµM¦h¤FÂIÂø¤CÂø¤KªºªF¦è¡A¦Ü¤Ö¦b±Ò°Êntopngªº¹Lµ{¤¤¬O¤£·|¥X°ÝÃDªº¡C

  2. ³Qntopng¦Y±¼ªºµwºÐªÅ¶¡¬O¤£·|¥D°ÊÄÀ©ñªº¡I
    °£¤F·Ç³Æ¨¬°÷¤jªºµwºÐ¥~¡A¥D°Êªº²M°£¹L´Á¸ê®Æªº¡C

    ºô¸ô¤W¦³¤@½g¤å³¹¦³¤À¨É¦p¦ó©w´Á±Æµ{²M°£¹L´Á¸ê®Æ¡C
    ¡÷Howto prevent ntopng causing out of disk space and inodes?

    ¥i±N¥H¤Uscript¥[¤Jcrontab¤¤¡AÅý¥¦¨C¤Ñ­â±á¤@ÂI¥D°Ê²M°£¤j©ó30¤Ñªº¸ê®Æ¡C
    0 1 * * *    root    /usr/bin/find /var/tmp/ntopng/*/top_talkers/* -mtime +30 -delete


  3. Professionalª©¥»ªºntopng¦h¤F¥H¤U¸ê°TÂ×´Iªºdashboard¤Î¤@±i¾ã¦Xreport¡C





    ³o­Ó¤º®eÂ×´I¾ã¦X¸ê°T½T¹ê·m²´¡A¦ý°£¤F¤§¥~¡A¦ü¥G·Pı¤£¨ìProfessionalª©ªº¨ä¥¦Àu¶Õ¡H

    ¨ä¹ê°£¤F­è¸Ë§¹10¤ÀÄÁªºProfessionalª©¸Õ¥Î´Á­­¡A±z¤]¥i¥H§Û¤Untopngªº system ID µM«áµo«Hµ¹ntopng¨ú±o30¤Ñ¸Õ¥Î±ÂÅv¡C
    ¥ý¸Õ¥Î¬Ý¬Ý¡A¦A¨M©w­n¤£­nªá¿ú¶R«§¡ã



♥¶¶¤l¦Ñ±Cªººô©ç¡A½Ð¦hÃö·Ó¡ã

If you don't like something, change it.
If you can't change it, change your attitude.
Don't complain!




2015-07-14, 21:39 shunze ªº­Ó¤H¸ê®Æ §â shunze ¥[¤J¦n¤Í¦Cªí µo°eEmailµ¹ shunze ÂsÄý shunze ªººô¯¸ MSN : shunze@gmail.com
shunze
¤u¤Í§B§B


µù¥U¤é´Á: 2002 04
¨Ó¦Û: ¼é¦Á²×¤î¤§¦a
¤å³¹: 2380

shunze Â÷½u
¡m¤À¨É¡nntopng¨«¨«°±°±¡I¡H¤Þ¥Î¦^ÂÐ ½s¿è/§R°£¤å³¹ ·j´M¥Ñ  µoªíªº¨ä¥L¤å³¹ ¦^³øµ¹ª©¥D IP ¦ì¸m ¦^¦¹­¶³Ì¤W¤è

¶¶¤lªºntopng¯¸¥x¤¤Á`¬O·|²@µL¼x¥üªº¦Û°Ê°±¤îªA°È¡H
ÁöµM³z¹L«ü¥O­«±ÒªA°È¥i«ì´_ntopngªº¹B§@¡A¦ý½Ö¦³®É¶¡¦Ñ¨nµÛ¥¦¬Ý°Ú¡H

¦Ó¥B¦³®É­Ô­«±ÒntopngªA°ÈÁÙ¨S¦³¥Î¡I¡H
¬d¬Ýntopng log¤~µo²{­ì¨Ó¬Oredis-server¤]±¾¤F...

¦b¬d¤£¨ì°ÝÃD­ì¦]ªº±¡ªp¤U¡A¶¶¤l¼g¤F¤ä²³æªºscript¡A³z¹Lcrontab¨C5ÄÁ¥h°»´úntopngªºªA°Èª¬ºA¡A
¤@¥¹µo²{ªA°È°±¤î¤F¡A´N¥D°Ê³z¹L¦¹ºÊ±±±Æµ{¥h­«±Òntopng¤Îredis-serverªA°È¡C

Script¤º®e¦p¤U¡A½Ð¦b/etc/ntopng/¸ô®|¤U±N¦¹scriptÀx¦s¬°ÀɦW restart_ntopng.pl ªºÀɮסA¨ÃÅܧó¨äÅv­­¬°755¡C

#!/usr/bin/perl

#ºÊ´úntopngªA°È¬O§_¶i¦æ,­YµL­«±ÒªA°È
$sntopng = `service ntopng status`;
$sntopng =~ s/^\s+//; # ¥hÀY
$sntopng =~ s/\s+$//; # ¥h§À

if($sntopng eq "ntopng is not running"){
    `service redis-server restart`;
    sleep(30);
    `service ntopng restart`;
    $time = time();
    ($second,$minute,$hour,$day,$month,$year) = localtime($time);
    #¦~¬O±q1900¶}©l­pºâ¡A¸É¥[1900
    $year+=1900;
    #¤ë¬O±q0¶}©l­pºâ¡A¸É¥[1
    $month++;
    #¿é¥Xlog¨ì/var/log/ntopng/restart.log
    `echo '$year/$month/$day $hour:$minute:$second Detect ntopng stop! Restart it.' >> /var/log/ntopng/restart.log`;
}

exit;

µM«á¦b/etc/crontab¤¤¡A¼W¥[¥H¤U¨C5¤ÀÄÁªººÊ±±±Æµ{¡C
*/5 * * * *    root /usr/bin/perl /etc/ntopng/restart_ntopng.pl


¥Ø«e´N³z¹L³o­Ó¤èªk¡A¼È®ÉÀ³¥I¦¹°ÝÃD¤F...


¦ýntopngªº¨ä¥¦ª¬ªp¡A¨Ò¦p
ERROR: Unable to create Lua interpreter
WARNING: Script failure [/usr/share/ntopng/scripts/callbacks/minute.lua][not enough memory]

¶¶¤l´N¨S¯à¤O¥h³B²z¥¦...



♥¶¶¤l¦Ñ±Cªººô©ç¡A½Ð¦hÃö·Ó¡ã

If you don't like something, change it.
If you can't change it, change your attitude.
Don't complain!




2015-08-01, 19:17 shunze ªº­Ó¤H¸ê®Æ §â shunze ¥[¤J¦n¤Í¦Cªí µo°eEmailµ¹ shunze ÂsÄý shunze ªººô¯¸ MSN : shunze@gmail.com
shunze
¤u¤Í§B§B


µù¥U¤é´Á: 2002 04
¨Ó¦Û: ¼é¦Á²×¤î¤§¦a
¤å³¹: 2380

shunze Â÷½u
¡m¤À¨É¡nntopng¨«¨«°±°±-2¤Þ¥Î¦^ÂÐ ½s¿è/§R°£¤å³¹ ·j´M¥Ñ  µoªíªº¨ä¥L¤å³¹ ¦^³øµ¹ª©¥D IP ¦ì¸m ¦^¦¹­¶³Ì¤W¤è

¦b´X¦¸ªº´ú¸Õ«áµo²{¤£¨ì¤@¶gªº®É¶¡¡Antopng´N¶}©l¥X²{²§±`¡Alogùئ³µÛ°O¾ÐÅ餣¨¬ªº¿ù»~¡C

ERROR: Unable to create Lua interpreter
WARNING: Script failure [/usr/share/ntopng/scripts/callbacks/minute.lua][not enough memory]

¤@¥¹¥X²{³oºØ¿ù»~«á¡A§Y«K¬O­«¶}¾÷¤]µLªk§ïµ½¡A
¼µ¤£¤F¦h¤[¤S·|°¨¤W±¾±¼...

¤Wºô·j´M«áµo²{°ÝÃD¥i¯à¬O¥X¦bredis-server¤W¡A¦Ó¤£¬Ontopng¡F
Redis-server¦ü¥G¤~¬O¦Y¥ú°O¾ÐÅ骺¥û¤â¡I¡H
Redis-Server¥²»Ý³z¹L force-reload¦Ó¤£¬Orestart¡A¤~¯àÄÀ©ñ¤w¦Y±¼ªº°O¾ÐÅé¡C
service redis-server force-reload

§ï¥H¦¹«ü¥O¹B¦æ«á¡AªGµMntopng¤S¥i¥H«ì´_¥¿±`¹B§@¡F
¬Ý¨Óredis-server¤~¬O³y¦¨ntopngÀWÀW±¾±¼ªº¹õ«á¶Â¤â¡I

¦A¶i¤@¨B·j´M«áµo²{redis-server¬O¥i¥H³]©w¨ä¨Ï¥Î¤§°O¾ÐÅé¤W­­ªº¡A
¨ä³]©wÀÉ©Ò¦b¸ô®|¬° /etc/redis/redis.conf¡A°O¾ÐÅé¨Ï¥Î¤W­­ªº°Ñ¼Æ¬O maxmemory¡A³æ¦ì¬°bytes¡F
¦P®É maxmemory-policy °Ñ¼Æ¥²»Ý°t¦X­×§ï¡A°O¾ÐÅ骺¤W­­³]©w¤~¯àµo´§®ÄªG¡C
¦Ó maxmemory-policy ªº°Ñ¼Æ¦@¦³¥H¤U´XºØ¡C
  • volatile-lru remove the key with an expire set using an LRU algorithm (¦¹¬°¹w³]­È)
  • allkeys-lru remove any key accordingly to the LRU algorithm
  • volatile-random remove a random key with an expire set
  • allkeys-random remove a random key, any key
  • volatile-ttl remove the key with the nearest expire time (minor TTL)
  • noeviction don't expire at all, just return an error on write operations


¨ä¹ê¶¶¤l¹ïredis-server§¹¥þ¤£À´¡A
¥u¬O¶¶µÛ¦r­±¤W»¡ªk¡A¿ï¤F allkeys-lru ¨Ó·f°t maxmemory ¨Ï¥Î¡A
¥t¥~³o¥xntopngªº°t¸m°O¾ÐÅ鬰1G¡A©Ò¥H¦b maxmemory ³¡¤À¡A¶¶¤l´N³]©w¤F 512000000(bytes) °µ¬°redis-serverªº¨Ï¥Î¤W­­¡C
vim /etc/redis/redis.conf
...
maxmemory 512000000
...
maxmemory-policy allkeys-lru
...


³Ì«á¦A§â±Æµ{°»´úntopngªA°Èªºscript°µ¤@¨Ç½Õ¾ã¡C
#!/usr/bin/perl

#ºÊ´úntopngªA°È¬O§_¶i¦æ,­YµL­«±ÒªA°È
$sntopng = `service ntopng status`;
$sntopng =~ s/^\s+//; # ¥hÀY
$sntopng =~ s/\s+$//; # ¥h§À

if($sntopng eq "ntopng is not running"){
    `service ntopng stop`;

    $time = time();
    ($second,$minute,$hour,$day,$month,$year) = localtime($time);
    #¦~¬O±q1900¶}©l­pºâ¡A¸É¥[1900
    $year+=1900;
    #¤ë¬O±q0¶}©l­pºâ¡A¸É¥[1
    $month++;

    #ºÊ´úredis-serverªA°È¬O§_¶i¦æ,­YµL­«±ÒªA°È
    $sredis = `service redis-server status`;
    $sredis =~ s/^\s+//; # ¥hÀY
    $sredis =~ s/\s+$//; # ¥h§À
    if($sredis ne "redis-server is running"){
        `service redis-server force-reload`;

        $time = time();
        ($second,$minute,$hour,$day,$month,$year) = localtime($time);
        #¦~¬O±q1900¶}©l­pºâ¡A¸É¥[1900
        $year+=1900;
        #¤ë¬O±q0¶}©l­pºâ¡A¸É¥[1
        $month++;
        `echo '$year/$month/$day $hour:$minute:$second Detect redis-server stop! Restart it.' >> /var/log/ntopng/restart.log`;
        sleep(30);
    }
    `service ntopng start`;

    $time = time();
    ($second,$minute,$hour,$day,$month,$year) = localtime($time);
    $year+=1900;
    $month++;
    #¿é¥Xlog¨ì/var/log/ntopng/restart.log
    `echo '$year/$month/$day $hour:$minute:$second Detect ntopng stop! Restart it.' >> /var/log/ntopng/restart.log`;
}

exit;

¸g¹L³o¼Ëªº½Õ¾ã«á¡AÁöµM¤@¤Ñ¤§¤¤ntopngÁÙ¬O¤£©w®Éªº·|°±¤îªA°È´X¦¸¡A
¦ý¦Ü¤ÖÁÙ¥i¥H³z¹L±Æµ{ºÊ±±¨Ó­«±ÒªA°È¡A«ì´_ntopngªº¥¿±`¹B§@¡C


°Ñ¦Ò¸ê®Æ
Redis takes up all the Memory and Crashes



♥¶¶¤l¦Ñ±Cªººô©ç¡A½Ð¦hÃö·Ó¡ã

If you don't like something, change it.
If you can't change it, change your attitude.
Don't complain!




2015-08-07, 20:17 shunze ªº­Ó¤H¸ê®Æ §â shunze ¥[¤J¦n¤Í¦Cªí µo°eEmailµ¹ shunze ÂsÄý shunze ªººô¯¸ MSN : shunze@gmail.com
shunze
¤u¤Í§B§B


µù¥U¤é´Á: 2002 04
¨Ó¦Û: ¼é¦Á²×¤î¤§¦a
¤å³¹: 2380

shunze Â÷½u
¡m¤À¨É¡nntopngµLªkµn¤J¡H¤Þ¥Î¦^ÂÐ ½s¿è/§R°£¤å³¹ ·j´M¥Ñ  µoªíªº¨ä¥L¤å³¹ ¦^³øµ¹ª©¥D IP ¦ì¸m ¦^¦¹­¶³Ì¤W¤è

¶¶¤lªºntopng¯¸¥x¦b¾É¤Jredis-serverªº°O¾ÐÅé¨Ï¥Î­­¨î¤§«á¡A
´N¨S¦Aµo¥Í°O¾ÐÅ餣¨¬»Ý­n­«±Òredis-server©Întopngªºlog¤F¡ã

¦ý©_©Çªº¬O¨C¹j¤@°}¤l¡Antopng¤W©Ò¦³±b¸¹´N·|Åܦ¨µLªkµn¤J¡H
¥²»Ýµn¤Jnbox¡A§ântopngªºªA°È°±¤î«á¦A±Ò°Ê¡Antopng¤~¯à´£¨Ñµn¤J¡C
¦Ó¥Badminªº±K½X³Q¦^´_¨ìªì©l­È¡A¨ä¥¦«áÄò«Ø¥ßªº¨Ï¥ÎªÌ±b¸¹¤]¥þ³¡¤£¨£¡I¡H
¬Ý¨Ó¤£¯à¦A¹ïredis-serverªº°ÝÃDµø¦Ó¤£¨£¤F...


¥J²Ó¦A¬Ý¤@¦¸redis-serverªº maxmemory-policy ¿ï¶µ¡A

  • volatile-lru remove the key with an expire set using an LRU algorithm
  • allkeys-lru remove any key accordingly to the LRU algorithm
  • volatile-random remove a random key with an expire set
  • allkeys-random remove a random key, any key
  • volatile-ttl remove the key with the nearest expire time (minor TTL)
  • noeviction don't expire at all, just return an error on write operations

¶¶¤l±Ä¥Îªº allkeys-lru «Ü²M·¡ªº»¡©ú¤F¡A·|²¾°£©Ò¦³ªºkey¡A
¦Óntopngªº¸ê®Æ¬Obase on redis-server (¥]¬A¨Ï¥ÎªÌ±b¸¹³]©wµ¥)¡A
®É¶¡¤@¨ì¡A±b¸¹³Q§R°£¡A¬Ý°_«o¬O¦X±¡¦X²z¡A¤@ÂI³£¤£©_©Ç°Ú¡I

©Ò¥HÁÙ¬O§â maxmemory-policy §ï¬°¹w³]ªº volatile-lru¡A³o­Ó¿ï¶µ¥u·|§R°£¦³®É¶¡­­¨î(TTL)ªºkey­È¡A
¹ï©óntopng¨t²Î©Ò¨Ï¥Îªº±b¸¹¡B±K½Xµ¥µL®É¶¡­­¨î¸ê°T«h¤£·|§R°£¡A·Pı¶Kªñ»Ý¨D¦h¤F¡I


Redis-Server¤¤¸òntopng¦³ÃöªºKEY¶µ¥Ø¦p¤U¡C
  1. "ntopng.host_labels"
  2. "ntopng.domain.tocategorize"
  3. "ntopng.user.admin.group"
  4. "ntopng.user.admin.password"
  5. "ntopng.user.admin.full_name"
  6. "ntopng.user.admin.allowed_nets"
  7. "ntopng.dns.cache.0.0.0.0"
  8. "ntopng.dns.cache.127.0.0.1"
  9. "ntopng.dns.cache.255.255.255.255"
  10. "ntopng.prefs.admin.ifname"
  11. "ntopng.prefs.table.admin"
  12. "ntopng.prefs.iface_id"
  13. "ntopng.prefs.alerts_syslog"
  14. "ntopng.prefs.flow_max_idle"
  15. "ntopng.prefs.local_host_max_idle"
  16. "ntopng.prefs.non_local_host_max_idle"
  17. "ntopng.prefs.http_traffic_dump"
  18. "ntopng.prefs.host_rrd_creation"
  19. "ntopng.prefs.host_ndpi_rrd_creation"
  20. "ntopng.prefs.intf_rrd_raw_days"
  21. "ntopng.prefs.intf_rrd_1min_days"
  22. "ntopng.prefs.intf_rrd_1h_days"
  23. "ntopng.prefs.intf_rrd_1d_days"
  24. "ntopng.prefs.other_rrd_raw_days"
  25. "ntopng.prefs.other_rrd_1min_days"
  26. "ntopng.prefs.other_rrd_1h_days"
  27. "ntopng.prefs.other_rrd_1d_days"

¥H¤W±ø¦Cªºkey¶µ¥Ø¡A¥i¥Î«ü¥O redis-cli keys ntopng* ¨Ó¬d¸ß¡C


Redis-Serverªº°ò¥»¾Þ§@»yªk¦p¤U¡C
¥i¦bubuntu©R¥O¦C¤¤ª½±µ¿é¤J§¹¾ã«ü¥O¡A
# redis-cli [keys | set | get | ttl | expire | persist | del | ¡K] <KEY-Name> {Parameter}

©Î¬O¥ý¶i¤J¨ìredis-cli¶¥¼h«á¡A¦A¤U¹F¬ÛÃö¾Þ§@«ü¥O¡C
# redis-cli
127.0.0.1:6379> [keys | set | get | ttl | expire | persist | del | ¡K] <KEY-Name> {Parameter}



´X­Óredis-server±`¥Îªº«ü¥O¤¶²Ð¦p¤U¡C
  • keys ±ø¦Ckey¶µ¥Ø¡C
    redis-cli keys <KEY-Name>

    ¬d¸ßªºkey¶µ¥Ø¦WºÙ¥i¥H¿é¤J¸U¥Î¦r¤¸ *¡A¨Ò¦p­n¬d¬Ý¸òntopng¦³Ãöªºkey®É¡A¥i¥H¿é¤J¥H¤U«ü¥O¡C
    redis-cli keys ntopng*


  • set ³]©wkey­È¡C
    redis-cli set <KEY-Name> <KEY-Value>

    ¨Ò¦p­n«Ø¤@­Óntopng¨Ï¥ÎªÌ±b¸¹KKK¡A¨ä±K½X¬°"admin"¡A§Ú­Ì¥i¥H¿é¤J¥H¤U«ü¥O¨Ó«Ø¥ß¦¹key­È¡C
    redis-cli set ntopng.user.KKK.password 21232f297a57a5a743894a0e4a801fc3

    ¨ä¤¤ 21232f297a57a5a743894a0e4a801fc3 ¬°¦r¦ê"admin"³z¹LMD5¥[±K«áªº­È¡C
    ¦blinux¤W¥i³z¹L¥H¤U«ü¥O¡A¨Ó¨ú±oMD5¥[±K«áªº¦r¦ê­È¡C
    echo -n <­n¥[±Kªº¦r¦ê> | md5sum


  • get ¨ú±okey­È¤º®e¡C
    redis-cli get <KEY-Name>


  • ttl ¨ú±okey­Èªº¦³®Ä®É¶¡¡A³æ¦ì¬í¡C
    redis-cli ttl <KEY-Name>

    ­Y¸Ókey¥Ã¤[¦³®Ä¡A¤£·|¹L´Á¡A«h¦^¶Ç-1¡C

  • expire ³]©wkey­Èªº¦³®Ä®É¶¡¡A³æ¦ì¬í¡C
    redis-cli expire <KEY-Name> <Seconds>


  • persist ³]©wkey¥Ã¤£¹L´Á¡C
    redis-cli persist <KEY-Name>


  • del §R°£key¡C
    redis-cli del <KEY-Name>



♥¶¶¤l¦Ñ±Cªººô©ç¡A½Ð¦hÃö·Ó¡ã

If you don't like something, change it.
If you can't change it, change your attitude.
Don't complain!




2015-08-24, 18:32 shunze ªº­Ó¤H¸ê®Æ §â shunze ¥[¤J¦n¤Í¦Cªí µo°eEmailµ¹ shunze ÂsÄý shunze ªººô¯¸ MSN : shunze@gmail.com
shunze
¤u¤Í§B§B


µù¥U¤é´Á: 2002 04
¨Ó¦Û: ¼é¦Á²×¤î¤§¦a
¤å³¹: 2380

shunze Â÷½u
¡m¤À¨É¡nntopngµLªkµn¤J-2¤Þ¥Î¦^ÂÐ ½s¿è/§R°£¤å³¹ ·j´M¥Ñ  µoªíªº¨ä¥L¤å³¹ ¦^³øµ¹ª©¥D IP ¦ì¸m ¦^¦¹­¶³Ì¤W¤è

¸g³o°}¤l´ú¸Õ«áµo²{¡A¤£½×maxmemory policy±Ä¥Î­þ¤@­Ó¿ï¶µ¡A
¤@©wªº®É¶¡¶g´Á«á¡Aredis-serverÁÙ¬O·|¦]°O¾ÐÅé°ÝÃD¡A¾É­Pntopngªº±b¸¹±K½XµLªkµn¤J¡C
redis-server¥X垷ªº¿ù»~°T®§¬°¡G
(error) OOM command not allowed when used memory > 'maxmemory'.

³Ì«á¥u¦³¤U redis-server flushall ¤~¯à¸Ñ°£¦¹ª¬ªp¡A
µM«á¦^¨ìnbox¤¤­«±ÒntopngªA°È¡AÅýntopng«ì´_¥¿±`¡C
·íµM­«±Ò«áªºntopng±b¸¹¸ê°T¤w«ì´_¬°¹w³]­È¡A¬ÛÃö±b¸¹¥²»Ý¨Ì»Ý¨D­«·s­×§ï©Î«Ø¥ß¡C


¬JµM¬O±`ºA©Êµo¥Í¡AÁ`§K¤£¤F­«·s³]©wntopng±b¸¹±K½Xªº¬yµ{¡A
¶¶¤l­«·s¤F«ä¦Ò»Ý¨D¡A¥ý§â maxmemory-policy ³]©w¬° volatile-lru¡Bvolatile-random ©Î volatile-ttl ªº¨ä¤¤¤@ºØ¡A
¦]¬°¥u¦³³o¤TºØpolicy¤~·|«O¯dpersist keys¤£¥h§R°£¡A¦Ó¤£¬OµL®t§O¯Åªº³q±þ¡C

µM«á§â­ì¥»¨C5¤ÀÄÁ°»´ú¤@¦¸ªºscript°µ¤F­×§ï¡A¥[¶i¤Fredis-server°O¾ÐÅ骺°»´ú¡A
¤@¥¹°O¾ÐÅé¤S³Q¦Y¥ú¤F¡A´N±Ò¥Î­«¸m¬yµ{¡C
¥ýflush redis-server¡AÄÀ¥X°O¾ÐÅé¡AµM«á³z¹Lredis-cli«ü¥O­«·s¼g¤Jadminªº±b¸¹Åv­­¡A¨Ã³]©w¨ä¥Ã¤£¹L´Á¡A³Ì«á¦A¼g¤Jlog°µ­Ó°O¿ý¡C

¥Ø«e¶¶¤l¯à°µªº¸Ñ¨M¤èªk¡A¤j·§´N¬O³o¼Ë¤F...

#!/usr/bin/perl

#ºÊ´úredis-serverªº°O¾ÐÅé¬O§_¤wº¡µLªk¼g¤J
$sredis_error = `redis-cli set ntopng.user.admin.full_name admin | grep "OOM command not allowed when used memory > 'maxmemory'"`;

if (index($sredis_error, "OOM command not allowed when used memory") != -1) {
    print "flush redis-server\n";
    #²MªÅredis-serverªºmemory
    `redis-cli flushall`;

    #­«·s¼g¤Jadminªº±b¸¹Åv­­,¨Ã³]©w¤£¹L´Á
    `redis-cli set ntopng.user.admin.group administrator`;
    `redis-cli set ntopng.user.admin.password 21232f297a57a5a743894a0e4a801fc3`;
    `redis-cli set ntopng.user.admin.full_name admin`;
    `redis-cli set ntopng.user.admin.allowed_nets 0.0.0.0/0,::/0`;
    `redis-cli persist ntopng.user.admin.group`;
    `redis-cli persist ntopng.user.admin.password`;
    `redis-cli persist ntopng.user.admin.full_name`;
    `redis-cli persist ntopng.user.admin.allowed_nets`;

    #¿é¥Xlog¨ì/var/log/ntopng/restart.log
    $time = time();
    ($second,$minute,$hour,$day,$month,$year) = localtime($time);
    $year+=1900;
    $month++;
    `echo '$year/$month/$day $hour:$minute:$second Detect Redis-Server memory exhausted! Flush it, and create account.' >> /var/log/ntopng/restart.log`;
}

#ºÊ´úntopngªA°È¬O§_¶i¦æ,­YµL­«±ÒªA°È
$sntopng = `service ntopng status`;
$sntopng =~ s/^\s+//; # ¥hÀY
$sntopng =~ s/\s+$//; # ¥h§À

if($sntopng eq "ntopng is not running"){
    `service ntopng stop`;

    $time = time();
    ($second,$minute,$hour,$day,$month,$year) = localtime($time);
    #¦~¬O±q1900¶}©l­pºâ¡A¸É¥[1900
    $year+=1900;
    #¤ë¬O±q0¶}©l­pºâ¡A¸É¥[1
    $month++;

    #ºÊ´úredis-serverªA°È¬O§_¶i¦æ,­YµL­«±ÒªA°È
    $sredis = `service redis-server status`;
    $sredis =~ s/^\s+//; # ¥hÀY
    $sredis =~ s/\s+$//; # ¥h§À
    if($sredis ne "redis-server is running"){
        `service redis-server force-reload`;

        $time = time();
        ($second,$minute,$hour,$day,$month,$year) = localtime($time);
        #¦~¬O±q1900¶}©l­pºâ¡A¸É¥[1900
        $year+=1900;
        #¤ë¬O±q0¶}©l­pºâ¡A¸É¥[1
        $month++;
        `echo '$year/$month/$day $hour:$minute:$second Detect redis-server stop! Restart it.' >> /var/log/ntopng/restart.log`;
        sleep(30);
    }
    `service ntopng start`;

    $time = time();
    ($second,$minute,$hour,$day,$month,$year) = localtime($time);
    $year+=1900;
    $month++;
    #¿é¥Xlog¨ì/var/log/ntopng/restart.log
    `echo '$year/$month/$day $hour:$minute:$second Detect ntopng stop! Restart it.' >> /var/log/ntopng/restart.log`;
}

exit;


********2015/09/22§ó·s********
¸g³o°}¤lÆ[¹î¡A³o¼Ëªº°µªk½T¹ê¦³®Ä¸Ñ¨M¤Fntopng¤£©w®É°±¤îªA°È¤Îredis¦Y¥ú°O¾ÐÅ骺°ÝÃD¡C
ntopngÁ`ºâ¥i¥H©ñ¤ß¨Ï¥Î¤F¡ã

¥Ñ shunze ¦b 2015-09-25, 10:48 ³Ì«á­×§ï.



♥¶¶¤l¦Ñ±Cªººô©ç¡A½Ð¦hÃö·Ó¡ã

If you don't like something, change it.
If you can't change it, change your attitude.
Don't complain!




2015-09-07, 13:15 shunze ªº­Ó¤H¸ê®Æ §â shunze ¥[¤J¦n¤Í¦Cªí µo°eEmailµ¹ shunze ÂsÄý shunze ªººô¯¸ MSN : shunze@gmail.com
  « ¤W¤@½g¥DÃD ¤U¤@½g¥DÃD »
µoªí·s¥DÃD µoªí¦^ÂÐ
¸õ¨ì:

Powered by: Burning Board 1.1.1 2001 WoltLab GbR