时间:2015-12-27 15:28 来源: 我爱IT技术网 作者:山风
MRTG 流量统计安装教学
本篇环境以centos6.6版本进行测试
Install snmpd
yum -y install net-snmp net-snmp-devel
Install iftop / sysstat / mrtg
yum -y install iftop sysstat mrtg
Setup MRTG
Setup SNMP
mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak
vi /etc/snmp/snmpd.conf
# 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
Setup SYSSTAT
mkdir /opt/mrtg
i. CPU
vi /opt/mrtg/mrtg.cpu
#!/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
# chmod 755 /opt/mrtg/mrtg.cpu
ii. MEM
vi /opt/mrtg/mrtg.mem
#!/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
# chmod 755 /opt/mrtg/mrtg.mem
c. Setup MRTG
vi /etc/mrtg/mrtg.cfg
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>
# mkdir /var/lib/mrtg
# env mrtg /etc/mrtg/mrtg.cfg
# env mrtg /etc/mrtg/mrtg.cfg
# env mrtg /etc/mrtg/mrtg.cfg
# indexmaker /etc/mrtg/mrtg.cfg > /var/www/mrtg/index.html
# vi /etc/httpd/conf.d/mrtg.conf
Alias /mrtg /var/www/mrtg
<Location /mrtg>
Order deny,allow
allow from all
</Location>设置排程
通过 crontab -e 加上以下指令
*/5 * * * * env mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log Optimizate TCP/IP configuration # vi /etc/sysctl.conf
# 加上以下的设置 (要注意已经有的则调整参数即可)
# 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
最后执行
sysctl -p
即可无须重开机便启用此设置
如要监看更多设备可以参考另一篇sh文件名记得要修改
MRTG CPU,NIC,MEM,SWAP,DISK usage, DISK I/O.监控
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)

[晕]要看少妇私藏图闺房蜜照,就去→ http://sebi.club
行,有意义,我顶 谢谢您了