設定 Linux CentOS (系統部分)
  • 8,820 views,
  • 2013-09-19,
  • 上傳者: Kuann Hung,
  •  0
3fd0ac420e5724a26fd6be2223bbf693.jpg

本篇著重在如何調整 Linux 效能以及一些網管相關設定,關於設定 Apache 等服務則請參考另一篇 設定 Linux CentOS
 

 
步驟
1.
Install snmpd
# yum -y install net-snmp net-snmp-devel
2.
Install iftop / sysstat / mrtg
# yum -y install iftop sysstat mrtg
3.
Setup MRTG
 
a. 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
 
b. 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
 
  iii. DISK Usage
    # vi /opt/mrtg/df.sh
#!/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}'`
 
  iv. DISK Performance
    # vi /opt/mrtg/diskperf.sh
#!/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}'
 
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>

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
 
# 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
 
   #  vi /etc/httpd/conf.d/mrtg.conf
 
Alias /mrtg /var/www/mrtg
 
<Location /mrtg>
    Order deny,allow
    allow from all
</Location>
 
4.
設定排程
透過 crontab -e 加上以下指令
*/5 * * * * env LANG=C mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log
5.
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
即可無須重開機便啟用此設定
Facebook 討論區載入中...
資料夾 :
發表時間 :
2013-09-19 04:02:32
觀看數 :
8,820
發表人 :
Kuann Hung
部門 :
老洪的 IT 學習系統
QR Code :