Install snmpd
1 | # yum -y install net-snmp net-snmp-devel |
1 | # yum -y install net-snmp net-snmp-devel |
1 | # yum -y install iftop sysstat mrtg |
1 2 | #mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak #vi /etc/snmp/snmpd.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # First, map the community name (COMMUNITY) into a security name # (local and mynetwork, depending on where the request is coming # from): # sec.name source community com2sec notConfigUser default public #### # Second, map the security names into group names: # sec.model sec.name group notConfigGroup v1 notConfigUser group notConfigGroup v2c notConfigUser #### # Third, create a view for us to let the groups have rights to: # incl/excl subtree mask view all included .1 80 #### # Finally, grant the 2 groups access to the 1 view with different # write permissions: # context sec.model sec.level match read write notif access notConfigGroup "" any noauth exact all none none |
1 | # mkdir /opt/mrtg |
1 2 3 4 5 6 7 8 | #!/bin/bash cpuusr=` /usr/bin/sar -u 1 3 | grep Average | awk '{print $3}' ` cpusys=` /usr/bin/sar -u 1 3 | grep Average | awk '{print $5}' ` UPtime=` /usr/bin/uptime | awk '{print $3.$4.$5}' ` echo $cpuusr echo $cpusys echo $UPtime hostname |
1 2 3 4 5 6 | #!/bin/bash echo ` /usr/bin/free -m | grep Mem | awk '{print $3}' ` echo ` /usr/bin/free -m | grep Swap | awk '{print $3}' ` echo ` /usr/bin/uptime | awk '{print $3 " " $4 " " $5}' ` hostname |
1 2 3 4 5 6 7 8 9 10 | #!/bin/bash hd= /mnt/hda total=` df -k | grep $hd | awk '{print $1}' ` usage=` df -k | grep $hd | awk '{print $2}' ` echo "$total" ; echo "$usage" ; hostname echo ` /usr/bin/uptime | awk '{print $3 " " $4 " " $5}' ` |
1 2 3 4 5 6 7 | #!/bin/sh hd=sda IOSTAT=$(iostat -d $hd 1 4 | awk '{print $3 " " $4}' | grep '[0-9]*\.[0-9]*' ) echo "$IOSTAT" | cut -d ' ' -f 1 | xargs | awk '{printf "%12d\n",($2+$3+$4)/3*512}' echo "$IOSTAT" | cut -d ' ' -f 2 | xargs | awk '{printf "%12d\n",($2+$3+$4)/3*512}' |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | HtmlDir: /var/www/mrtg ImageDir: /var/www/mrtg LogDir: /var/lib/mrtg ThreshDir: /var/lib/mrtg Target[eth0]: 2:public@127.0.0.1 MaxBytes[eth0]: 12500000 Title[eth0]: Traffic Analysis PageTop[eth0]: <H1>127.0.0.1 eth0< /H1 > Target[cpu]: ` /opt/mrtg/mrtg .cpu` MaxBytes[cpu]: 100 Options[cpu]: gauge, nopercent YLegend[cpu]: CPU loading (%) ShortLegend[cpu]: % LegendO[cpu]: CPU us; LegendI[cpu]: CPU sy; Title[cpu]: CPU Loading PageTop[cpu]:<H1>CPU Loading< /H1 > Target[mem]: ` /opt/mrtg/mrtg .mem` MaxBytes[mem]: 2048000 kmg[mem]: KB kilo[mem]: 1024 Options[mem]: gauge,nopercent YLegend[mem]: Memory Usage: Legend1[mem]: Total Memory: Legend2[mem]: Used Memory: LegendI[mem]: Total Memory: LegendO[mem]: Used Memory: Title[mem]: MEMORYWORKLOAD PageTop[mem]:<H1>Memory< /H1 > Target[disk]: ` /opt/mrtg/df .sh` Title[disk]: Disk Space Unscaled[disk]: dwym MaxBytes[disk]: 524288000 kmg[disk]: KB,MB,GB LegendI[disk]: Total Disk Space LegendO[disk]: Used Disk Space Legend1[disk]: Total Disk Space Legend2[disk]: Used Disk Space YLegend[disk]: Megabytes ShortLegend[disk]: & Options[disk]: gauge,nopercent PageTop[disk]: <h1>Disk Space< /h1 > Target[diskIO]: ` /opt/mrtg/diskperf .sh` Title[diskIO]: Disk I /O Utilization Report MaxBytes[diskIO]: 62914560 PageTop[diskIO]: <h1>Disk I /O Utilization Report< /h1 > kmg[diskIO]: B,KB,MB LegendI[diskIO]: Disk I /O KBread /sec LegendO[diskIO]: Disk I /O KBwrite /sec Legend1[diskIO]: Disk I /O KBread /sec Legend2[diskIO]: Disk I /O KBwrite /sec YLegend[diskIO]: Kbytes ShortLegend[diskIO]: & Options[diskIO]: gauge,nopercent |
1 2 3 4 5 | # mkdir /var/lib/mrtg # env LANG=C mrtg /etc/mrtg/mrtg.cfg # env LANG=C mrtg /etc/mrtg/mrtg.cfg # env LANG=C mrtg /etc/mrtg/mrtg.cfg # indexmaker /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html |
1 2 3 4 5 6 | Alias /mrtg /var/www/mrtg <Location /mrtg > Order deny,allow allow from all < /Location > |
1 | * /5 * * * * env LANG=C mrtg /etc/mrtg/mrtg .cfg --logging /var/log/mrtg .log |
1 2 3 | # vi /etc/sysctl.conf # 加上以下的設定 (要注意已經有的則調整參數即可) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # Use TCP syncookies when needed net.ipv4.tcp_synack_retries=3 net.ipv4.tcp_syn_retries=3 net.ipv4.tcp_max_syn_backlog=2048 # Enable TCP window scaling net.ipv4.tcp_window_scaling = 1 # Increase TCP max buffer size net.core.rmem_max = 16777216 net.core.wmem_max = 16777216 # Increase Linux autotuning TCP buffer limits net.ipv4.tcp_rmem = 4096 87380 16777216 net.ipv4.tcp_wmem = 4096 65536 16777216 # Increase number of ports available net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 300 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 net.ipv4.ip_local_port_range = 5000 65000 |
1 | sysctl -p |