Linux Centos5 锁定-可能是内存问题?

Linux Centos5 锁定-可能是内存问题?

这是一张 VPS 托管的 Centos5 64 位 Linux 服务器的 OCR 截图,该服务器刚刚冻结了。我现在已经重新启动了此 VPS 客户端,但如果有谁了解以下内容,可以告知是什么原因导致了锁定,我将不胜感激。

截图如下:https://i.stack.imgur.com/RVSs8.png

我的 OCR 粗略图如下:

cpu 1 cold: high 0, batch 1 used:0 DMA32 per-cpu: cpu 0 hot: high 186, batch 31 used:29 cpu 0 cold: high 62, batch 15 used:27 cpu 1 hot: high 186, batch 31 used:58 cpu 1 cold: high 62, batch 15 used:52 Normal per-cpu: empty HighMem per-cpu: empty Free pages: 7360kB (31KB HighMem) Active:127313 inactive:82099 dirty:0 writeback:0 unstable:0 free:1840 slab:18478 mapped-file:546 mapped-anon:210605 pagetables:14991 DMA free:3240kB min:32kB low:40kB high:48kB active:0kB inactive:0kB present:9052H pages_scanned:0 all_unreclairnable? yes lowmem reserve[]: 0 1002 1002 1002 DMA32 free:4120kB min:4032kB low:5040kB high:6048kB active:509272kB inactive:328376kB present:102616 afl pages_scanned :2342 all_unreclairnable, no lowmem_reserve[] : 0 0 0 0 Normal free:0kB min:0kB low:0kB high:0kB active:0kB inactive:0kB present:0kB pages_scanned:0 all_unr eclaimable? no lowmem_reserve[]: 0 0 0 0 HighMem free:0kB min: 128kB low : 128kB high :128kB active:0kB inactive:0kB present :0kB pages_scanned:0 I all_unreclaimable? no lowmem reserve[]: 0 0 0 0 DMA: 0.4kB 1.8kB 2.16kB 2.321,B 1.64kB 2.128kB 1.256kB 1.512kB ,1024kB 0.2048kB 0.4096kB = 3240kB DMA32: 68.4kB 1.8kB 2.16kB 57.3aB 9.64kB 1.128kB 1.256kB 0.512kB 1.1024kB 0.2048kB 0.4096kB = 4120k Normal : empty HighMem: empty 6100 pagecache pages swap cache: add 15557050, delete 15551562, find 330898601/333226192, race 14.1430 Free swap = 0kB Total swap = 1048568kB

答案1

密切关注您的交换使用情况(或只是开始记录它)。

如果您没有任何可用的监控工具(例如sar),请将下面的脚本放入 cron 中并让其每分钟运行一次。

计划任务

#minute (0-59),
#|  hour (0-23),
#|  |  day of the month (1-31),
#|  |  |  month of the year (1-12),
#|  |  |  |  day of the week (0-6, 0=Sun)
#|  |  |  |  |  commands
*   *  *  *  * /path/to/cronjob-check_swap.ksh >> /path/to/check_swap.log

CronJob-Check_Swap.ksh

## Script to call the check_swap.ksh script & Date/Time stamp the output
$DATECMD="date" ## Modify to get a date/time stamp in the format you like
printf "`$DATECMD` : `/path/to/check_swap.ksh`"

Check_Swap.ksh(适用于 Linux、Solaris 和 HP-UX 11.11)

#!/bin/ksh
# check_swap.ksh
#   Outputs swap usage in a human-readable one-liner.
#   Used to quickly check a system's swap.
#
#   Works on the following platforms;
#    HP-UX B.11.11 on PA-RISC
#    SunOS 5.10 on SPARC (global zone)
#    SunOS 5.10 on SPARC (non-global)
#    RHEL5/6 on x86 & x86_64
#    
##############################################################################
## GENERIC ENVIRONMENT VARIABLES
#     The full paths of things. Should be consistent across all platforms.
OSTYPE=$( /bin/uname )
PRINTF=/usr/bin/printf
GREP=/bin/grep
ECHO=/bin/echo
AWK=/bin/awk
SED=/bin/sed
##############################################################################
## SPECIFIC ENVIRONMENT VARIABLES
#     Variables used for this script
SWAP_TOTAL=0
SWAP_USED=0
SWAP_FREE=0
PERCENT_USED=0
PERCENT_FREE=0
##############################################################################
## DEBUG 
#     A function that we sprinkle in our script to show us the raw vars.
DEBUG(){
   ${PRINTF} "=====  DEBUG =====\n"
   [ -z ${OSTYPE} ]   || ${PRINTF} "                  OSTYPE = ${OSTYPE} \n"
   [ -z ${DATETIME} ] || ${PRINTF} "             Date / Time = ${DATETIME} \n"
   [ -z ${SWAP} ]     || ${PRINTF} "            Swap Command = ${SWAP} \n"
   [ -z ${SOD_T} ]    || ${PRINTF} " Swap-On-Disk Total (MB) = ${SOD_T} \n"
   [ -z ${SOD_F} ]    || ${PRINTF} " Swap-On-Disk Free  (MB) = ${SOD_F} \n"
   [ -z ${SOD_U} ]    || ${PRINTF} " Swap-On-Disk Used  (MB) = ${SOD_U} \n"
   [ -z ${STMP} ]     || ${PRINTF} "    Swap Total/Used (MB) = ${STMP} \n"
   ${PRINTF} "=====  DEBUG =====\n"
}
##############################################################################
## THRESHOLD CONTROLS - Where we define our thresholds and color-coding.
#  
# Colors
  cf="\033[0m"  # Color Off
  hi="\033[31m" # Red
  lo="\033[33m" # Yellow
  go="\033[32m" # green
# Thresholds
TH_PR="10:20"
TH_SZ="512:1024"
##############################################################################
## SWAP_ON_DISK - calculates the usage of swap devices
#  stu  (Swap Total, Used ) = "Total:Used" in Blocks (if needed).
#  stmp (Swap Temp)         = "Total:Used" in KiloBytes.
#  STMP (Swap Temp)         = "Total:Used" in MegaBytes.
SWAP_ON_DISK(){
  case ${OSTYPE} in
    # Solaris reports swap statistics in blocks (512 bytes = 1 block).
    SunOS)
      # Our command to query swap-on-disk
      SWAP="/usr/sbin/swap -l"
      sod_tf=$(${SWAP}|${AWK} '!/swaplo/{t+=$4;f+=$5}END{printf"%.f:%.f",t,f}')
      # Swap-on-Disk Total (Megabytes)
      SOD_T=$(( ( ( ${sod_tf%%:*} * 512 ) / 1024 ) / 1024 )) 
      # Swap-On-Disk Free (Megabytes)
      SOD_F=$(( ( ( ${sod_tf#*:}  * 512 ) / 1024 ) / 1024 )) 
      # Swap-On-Disk Used (already in Megabytes)
      SOD_U=$(( ${SOD_T} - ${SOD_F} ))
      #  STMP (Swap Temp)  = "Total:Used" in MegaBytes.
      STMP=${SOD_T}:${SOD_U}
      ;;
    # HP-UX reports swap usage in kilobytes by default.
    HP-UX)
      # Our command to query swap-on-disk
      SWAP="/usr/sbin/swapinfo -tdfm"
      # Swap Temp  = "Total:Used" (in MB)
      STMP=$( ${SWAP}|${AWK} '/total/{t+=$2;u+=$3}END{printf"%.f:%.f",t,u}')
      ;;
    #  Linux reports swap usage in kilobytes by default.
    Linux)
      # Our command to query swap-on-disk (can't use 'free -om', its a RHELism)
      SWAP="/sbin/swapon -s"
      sod_tu=$(${SWAP}|${AWK} '!/File/{t+=$3;u+=$4}END{printf"%.f:%.f",t,u}')
      sod_t=$(( ${sod_tu%%:*} / 1024 ))
      sod_u=$(( ${sod_tu#*:}  / 1024 ))
      STMP=${sod_t}:${sod_u}
      ;;
  esac
}
##############################################################################
## SWAP_AND_RESERVE - checks swap just like top, glance and HP OMW
#                     Basically, this counts the 'Reserve' of RAM as well.
#  NOTE:  On a Solaris Non-Global Zone, the 'Reserve' is defined from the
#         Global Zone, and is shared amongst each NGZ.
#         This makes this check come back 'weird' sometimes.
#         (Especially when the 'Reserve' is 25GB, which counts as 'used' swap,
#         while the NGZ itself only has 4GB or 8GB of swap from a disk.
SWAP_RESERVE(){
  case ${OSTYPE} in
    SunOS)
      # Our command to pull the 'swap summary' (includes the Reserve in RAM)
      SWAP="/usr/sbin/swap -s"
      sr_uf=$( ${SWAP}|${AWK} '{print $9":"$11}'|${SED} -e 's/k//g' )
      # Swap+Reserve Used  (in MB)
      SR_U=$(( ${sr_uf%%:*} / 1024 ))
      # Swap+Reserve Free  (in MB)
      SR_F=$(( ${sr_uf#*:} / 1024 ))
      # Swap+Reserve Total (in MB) (Sum of Used & Free)
      SR_T=$(( ${SR_U} + ${SR_F} ))
      # Swap Temp  = "Total:Used" (in MB)
      STMP=${SR_T}:${SR_U}
      ;;
    *)
      STMP=""
      ;;
  esac
}
##############################################################################
## FORMAT - splits all the vars and makes em pretty
#           Requires STMP be set, and should be "Total:Used" (we calc 'Free')
FORMAT(){
  SWAP_TOTAL=${STMP%%:*}
  SWAP_USED=${STMP#*:}
  SWAP_FREE=$(( ( ${SWAP_TOTAL} - ${SWAP_USED} ) ))
  #  Put a pretty comma every 3 digits.
  ST="`${ECHO} ${SWAP_TOTAL}|${SED} -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'`"
  SF="`${ECHO} ${SWAP_FREE} |${SED} -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'`"
  SU="`${ECHO} ${SWAP_USED} |${SED} -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'`"
  #  Calculate Percentages
  PERCENT_FREE=$(( ( ${SWAP_FREE} * 100 ) / ${SWAP_TOTAL} ))
  PERCENT_USED=$(( ( ${SWAP_USED} * 100 ) / ${SWAP_TOTAL} ))
  PF=${PERCENT_FREE}
  PU=${PERCENT_USED}
}
##############################################################################
## SCRIPT - Yay! Here we do stuff!
# Our command to query swap.
case ${OSTYPE} in
  SunOS)
    SWAP="/usr/sbin/swap -l"
    ;;
  HP-UX)
    SWAP="/usr/sbin/swapinfo -tdfm"
    ;;
  Linux)
    # (can't use 'free -om', its a RHELism)
    SWAP="/sbin/swapon -s"
    ;;
  *)
    ${PRINTF} "Unsupported OS ${OSTYPE}.\n"
    exit 1
    ;;
esac
# Verify we can query swap
  if [ ! -x ${SWAP%% *} ]; then
     ${PRINTF} "${SWAP%% *} not found or not executable by us.\n"
     exit 1
  fi
#
# Need a 'do we even have any swap to query' check here.
#
SWAP_ON_DISK
# DEBUG
[[ -z ${STMP} ]] || FORMAT
# DEBUG
[[ -z ${STMP} ]] || ${PRINTF} \
"Swap-on-Disk: ${SF}mb free (${PF}%%) of ${ST}mb total. ${SU}mb used (${PU}%%).
"
SWAP_RESERVE
[[ -z ${STMP} ]] || FORMAT
[[ -z ${STMP} ]] || ${PRINTF} \
"Swap+Reserve: ${SF}mb free (${PF}%%) of ${ST}mb total. ${SU}mb used (${PU}%%).
"
# EoF

相关内容