工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆
浏览模式: 标准 | 列表全部文章

解决apache服务器的time_wait和fin_wait1过多等问题

对一些大流量的web服务器来说,比较常见的问题就是time_wait会很多,起因大多都是apache里 keepalive 没开的原因,将这个开启,相对会少一些,但大流量时还是比较多,这里还有另外一个参数设置

net.ipv4.tcp_max_tw_buckets = 5000

如果不想time_wait不要太多,只要把这个值调低,就肯定不会超过了

但会出现一个新问题,就是在系统日志里,会很多类似这样的警告

Nov 27 15:50:01 localhost kernel: printk: 9498 messages suppressed.
Nov 27 15:50:01 localhost kernel: TCP: time wait bucket table overflow
Nov 27 15:50:06 localhost kernel: printk: 9562 messages suppressed.
Nov 27 15:50:06 localhost kernel: TCP: time wait bucket table overflow
Nov 27 15:50:11 localhost kernel: printk: 10120 messages suppressed.
Nov 27 15:50:11 localhost kernel: TCP: time wait bucket table overflow
Nov 27 15:50:16 localhost kernel: printk: 9182 messages suppressed.
Nov 27 15:50:16 localhost kernel: TCP: time wait bucket table overflow
Nov 27 15:50:21 localhost kernel: printk: 9626 messages suppressed.

这个警告其实不影响使用和性能,只是烦而已。我曾为避免这个提示,就将 net.ipv4.tcp_max_tw_buckets 调得很大,接着 time_wait 也就很大了。这也是上面这个问题,在网上搜索到的解决办法了。不想这个警告出现,重新编译内核,可以避免。

还有另一外问题,就是 fin_wait1 过多的问题,这个情况,一般的服务器上不会有。至少我的情况是这样

但在用了集群/负载均衡(LVS)中,下面的机器,就有这种情况,也曾为解决这个问题苦恼了挺久,经过今天的测试,也可以解决了。

只要在/etc/sysctl.conf 中加入

net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_retries2 = 5
net.ipv4.tcp_orphan_retries = 3
net.ipv4.tcp_reordering = 5
net.ipv4.tcp_retrans_collapse = 0

就会减少很多了,关键的是 net.ipv4.tcp_orphan_retries 这个

不打开机箱,就知道内存使用情况(转)

在考虑添加内存的时候,经常需要清楚服务器最大支持多少内存,已经有多少内存。有多少插槽,已经用了几个插槽,但这原来一般都需要打开机箱查看同时参考原厂资料,非常麻烦。偶经过一段时间琢磨、试验,发现通过dmidecode的信息可以搞定以上的事情。

l 内存的插槽数,已经使用多少插槽.每条内存多大,已使用内存多大

 

dmidecode |grep -P -A 5 "Memory/s+Device"|grep Size:|grep -v Range

 

例:

#dmidecode |grep -P -A 5 "Memory/s+Device"|grep Size:|grep -v Range
Size: 512 MB
Size: 512 MB
Size: No Module Installed
Size: No Module Installed

说明该服务器:

有4个内存插槽
已经使用2个内存插槽
每条内存容量512M
还有2个内存插槽可用

2 支持的最大内存容量

 

dmidecode |grep -P "Maximum/s+Capacity"

 

例:

# dmidecode |grep -P "Maximum/s+Capacity"
 Maximum Capacity: 4 GB

说明该服务器支持的最大内存容量是4GB
同时由此可以得出该服务器支持的单条内存最大容量是1G

sysstat

PHP显示所有POST的变量

foreach($_POST as $k => $v)
{
  echo $k .'=>' .$v;
}

extract($_POST);

HTTP_POST_VARS["变量名"]

systat命令监测网络流量

systat命令监测网络流量

使用方法为:
systat -if 3

http://pagesperso-orange.fr/sebastien.godard/download.html

iftop 流量监测

iftop

iftop 官方网站:
http://www.ex-parrot.com/~pdw/iftop/

安装iftop,,必须先安装libpcap
http://www.tcpdump.org/release/

wget http://www.tcpdump.org/release/libpcap-0.9.8.tar.gz
tar -zxvf libpcap-0.9.8.tar.gz

cd libpcap-0.9.8
./configure
make;make install

pcap安装完成,再来安装iftop
wget http://www.ex-parrot.com/~pdw/iftop/download/iftop-0.17.tar.gz
tar zxvf iftop-0.17.tar.gz
cd iftop-0.17
./configure
make;make install


[root@localhost libpcap-1.0.0]# make
gcc -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -c ./pcap-linux.c
gcc -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -c ./pcap-usb-linux.c
gcc -O2 -fPIC -I.  -DHAVE_CONFIG_H  -D_U_="__attribute__((unused))" -c ./fad-getad.c
In file included from ./fad-getad.c:67:
/usr/include/linux/if_packet.h:52: error: expected specifier-qualifier-list before '__u32'
make: *** [fad-getad.o] Error 1

A:

#include <linux/types.h>
加入到
/usr/include/linux/if_packet.h
的最顶端.

ifstat流量监测

http://gael.roualland.free.fr/ifstat/

http://gael.roualland.free.fr/ifstat/ifstat-1.1.tar.gz
  tar xzvf ifstat-1.1.tar.gz
  cd ifstat-1.1
  ./configure
  make
  make install
然后 man ifstat
-t 显示时间 格式:HH:MM:SS   
-i 指定的网卡 ,如果有多块网卡 以","分隔
-T 显示所有接口的带宽.
# ifstat -t -i eth0 -T   

Linux查看CPU信息 转

Linux下如何查看CPU信息, 包括位数和多核信息
# uname -a
Linux euis1 2.6.9-55.ELsmp #1 SMP Fri Apr 20 17:03:35 EDT 2007 i686 i686 i386 GNU/Linux
(查看当前操作系统内核信息)
# cat /etc/issue | grep Linux
Red Hat Enterprise Linux AS release 4 (Nahant Update 5)
(查看当前操作系统发行版信息)
# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
      8  Intel(R) Xeon(R) CPU            E5410   @ 2.33GHz
(看到有8个逻辑CPU, 也知道了CPU型号)
# cat /proc/cpuinfo | grep physical | uniq -c
      4 physical id      : 0
      4 physical id      : 1
(说明实际上是两颗4核的CPU)
# getconf LONG_BIT
32
(说明当前CPU运行在32bit模式下, 但不代表CPU不支持64bit)
# cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l
8
(结果大于0, 说明支持64bit计算. lm指long mode, 支持lm则是64bit)
最后再完整看cpu物理信息, 不过大部分我们都不关心而已.
# dmidecode | grep -A48 'Processor Information$'