¸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¶}©lpºâ¡A¸É¥[1900
$year+=1900;
#¤ë¬O±q0¶}©lpºâ¡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¶}©lpºâ¡A¸É¥[1900
$year+=1900;
#¤ë¬O±q0¶}©lpºâ¡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!
|