Archive for the ‘Linux’ Category

0083 | GeoDNS for BIND 9.2+

Wednesday, November 4th, 2009 Posted in IP Network, Linux | 2 Comments »

เอาไว้ทำ CDN ได้ครับ ให้ dns lookup ออกมาตามประเทศ

shell script (จำที่มาไม่ได้ ขออภัยด้วยครับ)

#!/bin/bash
cd /tmp
/bin/rm -f GeoIPCountryCSV.zip
wget -T 5 -t 1 http://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
unzip GeoIPCountryCSV.zip || exit 1
 
echo -n "Creating CNM (Country,Net/Mask) CSV file..."
awk -F \" 'function s(c,b,e,l,m,n) {l = log(e-b+1)/log(2); m = 2^32-2^int(l); n = and(m,e); if (n == and(m,b)) {printf "%s,%u.%u.%u.%u/%u\n",c,b/2^24%256,b/2^16%256,b/2^8%256,b%256,32-l} else {s(c,b,n-1); s(c,n,e)}} s($10,$6,$8)' GeoIPCountryWhois.csv > cnm.csv
rm -f GeoIPCountryWhois.csv
echo -ne "DONE\nGenerating BIND GeoIP.acl file..."
 
(for c in $(awk -F , '{print $1}' cnm.csv | sort -u)
do
  echo "acl \"$c\" {"
  grep "^$c," cnm.csv | awk -F , '{print "\t"$2";"}'
  echo -e "};\n"
done) > /etc/named.GeoIP.acl
 
rm -f cnm.csv
echo "DONE"
 
/etc/init.d/named reload
 
exit 0

แล้วไปแก้ named.conf

include "/etc/named.GeoIP.acl";
view "thailand" {
    match-clients { TH; };
        match-clients { TH; };
        zone "upic.me" {
                type master;
                file "master/th.db.upic.me";
        };
}
view "inter" {
        match-clients { any; };
        zone "upic.me" {
                type master;
                file "master/all.db.upic.me";
        };
};

อยากได้ประเทศไหนก็ลองดู code ในไฟล์ /etc/named.GeoIP.acl ละกันครับ
ส่วน… script ด้านบน
เซฟแล้วเอาใส่ใน cron ด้วยเลยจะดีมาก รันสัปดาห์ละครั้ง

Tags: , , ,

0082 | MRTG สำหรับจับการทำงานของ squid

Wednesday, November 4th, 2009 Posted in Linux, Web Server | 4 Comments »

แก้ squid.conf นิดหน่อย

acl snmppublic snmp_community public
snmp_port 3401
snmp_access allow snmppublic localhost
snmp_access deny all

แล้วเอาไอ้นี่ใส่ mrtg.cfg

LoadMIBs: /etc/squid/mib.txt
 
Target[cacheServerRequests]: cacheServerRequests&cacheServerRequests:public@localhost:3401
MaxBytes[cacheServerRequests]: 10000000
Title[cacheServerRequests]: Server Requests @ localhost
Options[cacheServerRequests]: growright, nopercent
PageTop[cacheServerRequests]: <h1>Server Requests @ localhost</h1>
YLegend[cacheServerRequests]: requests/sec
ShortLegend[cacheServerRequests]: req/s
LegendI[cacheServerRequests]: Requests&nbsp;
LegendO[cacheServerRequests]:
Legend1[cacheServerRequests]: Requests
Legend2[cacheServerRequests]:
 
Target[cacheProtoClientHttpRequests]: cacheProtoClientHttpRequests&cacheProtoClientHttpRequests:public@localhost:3401
MaxBytes[cacheProtoClientHttpRequests]: 10000000
Title[cacheProtoClientHttpRequests]: Client Http Requests @ localhost
Options[cacheProtoClientHttpRequests]: growright, nopercent
PageTop[cacheProtoClientHttpRequests]: <h1>Client Http Requests @ localhost</h1>
YLegend[cacheProtoClientHttpRequests]: requests/sec
ShortLegend[cacheProtoClientHttpRequests]: req/s
LegendI[cacheProtoClientHttpRequests]: Requests&nbsp;
LegendO[cacheProtoClientHttpRequests]:
Legend1[cacheProtoClientHttpRequests]: Requests
Legend2[cacheProtoClientHttpRequests]:
 
Target[cacheHttpHits]: cacheHttpHits&cacheHttpHits:public@localhost:3401
MaxBytes[cacheHttpHits]: 10000000
Title[cacheHttpHits]: HTTP Hits @ localhost
Options[cacheHttpHits]: growright, nopercent
PageTop[cacheHttpHits]: <h1>HTTP Hits @ localhost</h1>
YLegend[cacheHttpHits]: hits/sec
ShortLegend[cacheHttpHits]: hits/s
LegendI[cacheHttpHits]: Hits&nbsp;
LegendO[cacheHttpHits]:
Legend1[cacheHttpHits]: Hits
Legend2[cacheHttpHits]:
 
Target[cacheCpuUsage]: cacheCpuUsage&cacheCpuUsage:public@localhost:3401
MaxBytes[cacheCpuUsage]: 100
AbsMax[cacheCpuUsage]: 100
Title[cacheCpuUsage]: CPU Usage @ localhost
Options[cacheCpuUsage]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheCpuUsage]: dwmy
PageTop[cacheCpuUsage]: <h1>CPU Usage @ localhost</h1>
YLegend[cacheCpuUsage]: usage %
ShortLegend[cacheCpuUsage]:%
LegendI[cacheCpuUsage]: CPU Usage&nbsp;
LegendO[cacheCpuUsage]:
Legend1[cacheCpuUsage]: CPU Usage
Legend2[cacheCpuUsage]:
 
Target[cacheSysNumReads]: cacheSysNumReads&cacheSysNumReads:public@localhost:3401
MaxBytes[cacheSysNumReads]: 10000000
Title[cacheSysNumReads]: HTTP I/O number of reads @ localhost
Options[cacheSysNumReads]: growright, nopercent
PageTop[cacheSysNumReads]: <h1>HTTP I/O number of reads @ localhost</h1>
YLegend[cacheSysNumReads]: reads/sec
ShortLegend[cacheSysNumReads]: reads/s
LegendI[cacheSysNumReads]: I/O&nbsp;
LegendO[cacheSysNumReads]:
Legend1[cacheSysNumReads]: I/O
Legend2[cacheSysNumReads]:
 
Target[cacheCurrentFileDescrCnt]: cacheCurrentFileDescrCnt&cacheCurrentFileDescrCnt:public@localhost:3401
MaxBytes[cacheCurrentFileDescrCnt]: 1000000000
Title[cacheCurrentFileDescrCnt]: Used File Descriptors
Options[cacheCurrentFileDescrCnt]: gauge, growright, nopercent
PageTop[cacheCurrentFileDescrCnt]: <h1>Number of used file descriptors @ localhost</h1>
YLegend[cacheCurrentFileDescrCnt]: # of FDs
ShortLegend[cacheCurrentFileDescrCnt]: FDs
LegendI[cacheCurrentFileDescrCnt]: File Descriptors&nbsp;
LegendO[cacheCurrentFileDescrCnt]:
Legend1[cacheCurrentFileDescrCnt]: File Descriptors
Legend2[cacheCurrentFileDescrCnt]:
 
Target[cacheRequestHitRatio]: cacheRequestHitRatio.5&cacheRequestHitRatio.60:public@localhost:3401
MaxBytes[cacheRequestHitRatio]: 100
AbsMax[cacheRequestHitRatio]: 100
Title[cacheRequestHitRatio]: Request Hit Ratio @ localhost
Options[cacheRequestHitRatio]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheRequestHitRatio]: dwmy
PageTop[cacheRequestHitRatio]: <h1>Request Hit Ratio @ localhost</h1>
YLegend[cacheRequestHitRatio]: %
ShortLegend[cacheRequestHitRatio]: %
LegendI[cacheRequestHitRatio]: Median Hit Ratio (5min)&nbsp;
LegendO[cacheRequestHitRatio]: Median Hit Ratio (60min)&nbsp;
Legend1[cacheRequestHitRatio]: Median Hit Ratio
Legend2[cacheRequestHitRatio]: Median Hit Ratio
 
Target[cacheRequestByteRatio]: cacheRequestByteRatio.5&cacheRequestByteRatio.60:public@localhost:3401
MaxBytes[cacheRequestByteRatio]: 100
AbsMax[cacheRequestByteRatio]: 100
Title[cacheRequestByteRatio]: Byte Hit Ratio @ localhost
Options[cacheRequestByteRatio]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheRequestByteRatio]: dwmy
PageTop[cacheRequestByteRatio]: <h1>Byte Hit Ratio @ localhost</h1>
YLegend[cacheRequestByteRatio]: %
ShortLegend[cacheRequestByteRatio]:%
LegendI[cacheRequestByteRatio]: Median Hit Ratio (5min)&nbsp;
LegendO[cacheRequestByteRatio]: Median Hit Ratio (60min)&nbsp;
Legend1[cacheRequestByteRatio]: Median Hit Ratio
Legend2[cacheRequestByteRatio]: Median Hit Ratio

จริงๆ มันมีอีกเพียบเลย แต่ไม่รู้จะใส่ไว้ทำไม รก

Tags: ,