传奇外传私服 tcp 协议TIMEWAIT状态详解 - lidp的专栏 - 博客频道 - CSDN.NET使用shell脚本进行服务器系统

echo "/n"
}

AIX) AIX_paging_mon
;;
HP-UX) HP_UX_swap_mon
;;
Linux) Linux_swap_mon
;;
SunOS) SUN_swap_mon
;;
esac

1. 实现终止TCP全双工链接的可靠性,即保证tcp连接可靠断开。

THISHOST=$(hostname) # Host name of this machine

# Convert the KB measurements to MB measurements

上一篇文章提到执行主动关闭的一端进入 tcp TIME_WAIT状态,关于原因,unix网络编程卷一中给出两点:

# Start a while loop and feed the loop from the bottom using
# the $PAGING_STAT file as redirected input

done < $PAGING_STAT

###########################################################

#!/usr/bin/ksh

echo "/n"
}

tput smso # Turn on reverse video!
echo "/n/nWARNING: Swap Space has Exceeded the ${PC_LIMIT}% Upper Limit!/n"
tput rmso # Turn off reverse video!
fi

THISHOST=$(hostname) # Host name of this machine

###########################################################
################## BEGINNING OF MAIN ######################
###########################################################

echo "/n"
}


PC_LIMIT=65 # Upper limit of Swap space percentage
# before notification

# Find the Operating System and execute the correct function

# Grap the integer portion of the percent used to
# test for the over limit threshold

echo "/nTotal Amount of Swap Space:/t${SW_TOTAL_MB}MB"
echo "Total KB of Swap Space Used:/t${SW_USED_MB}MB"
echo "Total KB of Swap Space Free:/t${SW_FREE_MB}MB"
echo "/nPercent of Swap Space Used:/t${PERCENT_USED}%"
echo "/nPercent of Swap Space Free:/t${PERCENT_FREE}%"

PERCENT_FREE=$(bc <<EOF
scale=4
($SW_FREE / $SW_TOTAL) * 100
EOF
)

case $(uname) in

echo "/n"
}

free -m grep -i swap while read junk SW_TOTAL SW_USED SW_FREE
do
PERCENT_USED=$(bc <<EOF
scale=4
($SW_USED / $SW_TOTAL) * 100
EOF
)

# Check to see if the percentage used maxmum threshold
# has beed exceeded

###########################################################

# Produce the rest of the paging space report:
echo "/nTotal Amount of Swap Space:/t${SW_TOTAL}MB"
echo "Total KB of Swap Space Used:/t${SW_USED}MB"
echo "Total KB of Swap Space Free:/t${SW_FREE}MB"
echo "/nPercent of Swap Space Used:/t${PERCENT_USED}%"
echo "/nPercent of Swap Space Free:/t${PERCENT_FREE}%"

echo "/nTotal Amount of Swap Space:/t${SW_TOTAL}MB"
echo "Total MB of Swap Space Used:/t${SW_USED}MB"
echo "Total MB of Swap Space Free:/t${SW_FREE}MB"
echo "/nPercent of Swap Space Used:/t${PERCENT_USED}"
echo "/nPercent of Swap Space Free:/t${PERCENT_FREE}%"

echo "/n/nWARNING: Paging Space has Exceeded the ${PC_LIMIT}% /
Upper Limit!/n"

# Grab the integer portion of the percent used

PAGING_STAT=/tmp/paging_stat.out # Paging Stat hold file

while read TOTAL PERCENT
do
# Clean up the data by removing the suffixes
PAGING_MB=$(echo $TOTAL cut -d 'MB' -f1)
PAGING_PC=$(echo $PERCENT cut -d% -f1)

# Add an extra new line to the output

# Produce the rest of the paging space report:
echo "/nTotal MB of Paging Space:/t$TOTAL"
echo "Total MB of Paging Space Used:/t${MB_USED}MB"
echo "Total MB of Paging Space Free:/t${MB_FREE}MB"
echo "/nPercent of Paging Space Used:/t${PERCENT}"
echo "/nPercent of Paging Space Free:/t${PAGING_PC_FREE}%"

###########################################################

lsps -s tail +2 > $PAGING_STAT

PERCENT_FREE=$(bc <<EOF
scale=4
($SW_FREE / $SW_TOTAL) * 100
EOF
)

function AIX_paging_mon
{
################ DEFINE VARIABLES HERE ####################

# Load the data in a file without the column headings

2. 让老的重复分节在网络中消失
第一个原因的解释,执行主动关闭的一端最终会发ACK给对端,如果这个ACK最终丢失,那么发FIN的对端将由于在等待ACK超时后重发FIN分节,传奇外传私服,而如果主动关闭的一端在发完最终的ACK后清除此连接上状态信息,当再次收到对端的FIN分节时由于找不到对应的连接而报错,所以,如果TCP想彻底终止某个连接上两个方向的数据流(即全双工关闭),那么它必须处理连接终止序列四个分节中任何一个分节丢失的情况,这就是为何执行主动关闭的一端进入TIME_WAIT状态的第一个原因,因为它可能不得不重发最终的ACK分节给对端。

第二个原因,假设在一对ip及port上有一个连接,关闭这个连接后立即又建立起新的连接(同ip port),后一个连接为前一个的化身,因为ip port相同,传世私服,tcp 必须防止来自某个连接的老分组在连接终止后再现,从而影响新连接的数据交互,所以tcp不能给处于TIME_WAIT状态的连接启动新的化身,从而被误解成属于同一连接。
TIME_WAIT状态的持续时间是最长分节生命期MSL(max segment lifetime)的2倍,魔域私服,即2MSL,天龙八部私服,既然tcp规定一个分节在网络中最大生存时间是 MSL,这足够让某个方向上的分节最多存活MSL秒即被丢弃,另一个方向的应答最多存活MSL秒也被丢弃,通过这个规则,冒险岛sf,就能保证当成功建立一个tcp连接时,来自该链接的之前所有连接的老的重复分组在网络中已消失。


每个TCP/IP 协议栈必须选择一个 MSL值,rfc 1122建议值为2分钟,而源自berkely的实现是30秒,需要注意的是如果此值过大,则在高并发服务器中tcp/ip协议栈必然要维护大量的TIME_WAIT状态的连接而消耗资源,所以一般作网络服务器优化时通常经过改小此值来减少维护此状态的资源。

详细设置及解决如下:

timeout_timewait 参数
描述:确定 TCP/IP 在释放已关闭的连接并再次使用其资源前必须经过的时间。关闭与释放之间的这段时间称为 TIME_WAIT 状态或者两倍最大段生存期(2MSL)状态。此时间期间,重新打开到客户机和服务器的连接的成本少于建立新连接。通过减少此条目的值,TCP/IP 可以更快地释放关闭的连接,并为新连接提供更多资源。如果正在运行的应用程序需要快速释放连接、创建新的连接,并且因为许多连接处于 TIME_WAIT 状态而导致低吞吐量,那么调整此参数。
如何查看或设置:
在我的ubuntu系统上此值为:
#cat /proc/sys/net/ipv4/tcp_fin_timeout
60
发出以下命令,将 timeout_timewait 参数设置为 30 秒:

#echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout


function Linux_swap_mon
{

if (( PC_LIMIT <= INT_PERCENT_USED ))
then
# Percent used has exceeded the threshold, send notification

function HP_UX_swap_mon
{
############# CAPTURE AND PROCESS THE DATA ################

tput smso # Turn on reverse video!
echo "/n/nWARNING: Swap Space has Exceeded the/
${PC_LIMIT}% Upper Limit!/n"
tput rmso # Turn reverse video off!
fi

echo "/nSwap Space Report for $THISHOST/n"
date

# Start a while read loop by using the piped in input from
# the swapinfo -tm command output.


swapinfo -tm grep dev while read junk SW_TOTAL SW_USED /
SW_FREE PERCENT_USED junk2
do
# Calculate the percentage of free swap space

done

INT_PERCENT_USED=$(echo $PERCENT_USED cut -d. -f1)

rm -f $PAGING_STAT

function SUN_swap_mon
{
SW_USED=$(swap -s awk '{print $9}' cut -dk -f1)
SW_FREE=$(swap -s awk '{print $11}' cut -dk -f1)
((SW_TOTAL = SW_USED + SW_FREE))
PERCENT_USED=$(bc <<EOF
scale=4
($SW_USED / $SW_TOTAL) * 100
EOF
)

tput rmso # Turn off reverse video
fi

((PERCENT_FREE = 100 - $(echo $PERCENT_USED cut -d% -f1) ))

if (( PC_LIMIT <= $(echo $PERCENT_USED cut -d% -f1) ))
then
# Swap space is over the predefined limit, send notification

tput smso # Turn on reverse video!


((SW_TOTAL_MB = SW_TOTAL / 1000))
((SW_USED_MB = SW_USED / 1000))
((SW_FREE_MB = SW_FREE / 1000))


# Calculate the missing data: %Free, MB used and MB free
(( PAGING_PC_FREE = 100 - PAGING_PC ))
(( MB_USED = PAGING_MB * PAGING_PC / 100 ))
(( MB_FREE = PAGING_MB - MB_USED ))

###########################################################
################ DEFINE VARIABLES HERE ####################

PC_LIMIT=65 # Upper limit of Swap space percentage
# before notification

# Check for paging space exceeded the predefined limit
if ((PC_LIMIT <= PAGING_PC))
then
# Paging space is over the limit, send notification

if (( PC_LIMIT <= INT_PERCENT_USED ))
then
tput smso
echo "/n/nWARNING: Paging Space has Exceeded the /
${PC_LIMIT}% Upper Limit!/n"
tput rmso
fi

###########################################################
############# CAPTURE AND PROCESS THE DATA ################

done

# Produce the remaining part of the report

# End of all-in-one_swapmon.ksh

INT_PERCENT_USED=$(echo $PERCENT_USED cut -d. -f1)

# Check for paging space exceeded the predefined limit


上一篇: 传奇外传sf Z-blog,拯救死站走出沙盒。。。 - 新站长杂谈栏 - 落伍者站长论坛 -
下一篇:下面没有链接了