WEB服务器反应极度缓慢

WEB服务器反应极度缓慢

尝试用LINUX搭建了一个WEB服务器(至强 3G 2个,2G内存,主要跑http和mysql),但发现访问服务器极度缓慢,网页打不开,TOP结果如下,请大家帮我看看是什么原因:
top - 16:42:46 up  1:30,  2 users,  load average: 563.32, 300.05, 179.08
Tasks: 2626 total, 204 running, 2422 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3%us, 88.8%sy,  0.0%ni,  0.0%id, 10.3%wa,  0.1%hi,  0.5%si,  0.0%st
Mem:   2075288k total,  2025492k used,    49796k free,     4636k buffers
Swap:  2096440k total,  1259804k used,   836636k free,    55600k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
  192 root      12  -5     0    0    0 R   26  0.0   6:01.38 kswapd0
4738 mysql     16   0 1742m 352m 2236 R   20 17.4  45:46.25 mysqld
6690 apache    16   0 59068 3928 1472 R    2  0.2   0:03.79 httpd
6765 apache    16   0 59068 3896 1472 S    2  0.2   0:00.68 httpd
7301 apache    16   0 59068 3968 1508 S    2  0.2   0:01.23 httpd
7242 apache    16   0 60156 5288 2772 D    2  0.3   0:01.16 httpd
4334 apache    16   0 60284 5964 2688 D    2  0.3   0:00.90 httpd
4584 apache    16   0 59068 3904 1472 R    2  0.2   0:06.47 httpd
6315 apache    16   0 60156 5524 2540 R    2  0.3   0:03.61 httpd
6907 apache    16   0 59952 5396 2740 R    2  0.3   0:00.92 httpd
4072 apache    16   0 60164 5556 2732 S    2  0.3   0:06.22 httpd
6574 apache    16   0 59068 3896 1472 D    2  0.2   0:01.03 httpd
3615 apache    16   0 60156 4892 2540 R    2  0.2   0:00.99 httpd
4417 apache    16   0 60284 6376 2856 R    2  0.3   0:02.29 httpd
4767 apache    16   0 60284 5344 2688 D    2  0.3   0:01.12 httpd
6229 apache    16   0 60156 5396 2736 R    2  0.3   0:05.25 httpd
6650 apache    16   0 59068 3896 1472 R    2  0.2   0:00.97 httpd

从CPU看,好象负载也不是很大,但就是不知道什么原因反应缓慢。有知道请指点,谢谢。如果此时PING服务器的话,回应时间很短,

我的HTTPD.CONF文件内容如下:


ServerTokens OS

ServerRoot "/etc/httpd"

PidFile run/httpd.pid

Timeout 120

KeepAlive Off

MaxKeepAliveRequests 100

KeepAliveTimeout 15


<IfModule prefork.c>
StartServers       8
MinSpareServers   25
MaxSpareServers   50
ServerLimit      50000
MaxClients       30000
MaxRequestsPerChild  10000
</IfModule>

<IfModule worker.c>
StartServers         2
MaxClients         150
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

Listen 80

LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_alias_module modules/mod_authn_alias.so
LoadModule authn_anon_module modules/mod_authn_anon.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_default_module modules/mod_authn_default.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_owner_module modules/mod_authz_owner.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_dbm_module modules/mod_authz_dbm.so
LoadModule authz_default_module modules/mod_authz_default.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule include_module modules/mod_include.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule logio_module modules/mod_logio.so
LoadModule env_module modules/mod_env.so
LoadModule ext_filter_module modules/mod_ext_filter.so
LoadModule mime_magic_module modules/mod_mime_magic.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule usertrack_module modules/mod_usertrack.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule dav_module modules/mod_dav.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule info_module modules/mod_info.so
LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
LoadModule actions_module modules/mod_actions.so
LoadModule speling_module modules/mod_speling.so
LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule cache_module modules/mod_cache.so
LoadModule suexec_module modules/mod_suexec.so
LoadModule disk_cache_module modules/mod_disk_cache.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule mem_cache_module modules/mod_mem_cache.so
LoadModule cgi_module modules/mod_cgi.so


Include conf.d/*.conf


User apache
Group apache


ServerAdmin root@localhost


UseCanonicalName Off

DocumentRoot "/www/html/"

<Directory />
    Options FollowSymLinks
    AllowOverride None
</Directory>


<Directory "/www/html">

    Options Indexes FollowSymLinks

    AllowOverride None

    Order allow,deny
    Allow from all

</Directory>

<IfModule mod_userdir.c>
    UserDir disable


</IfModule>


DirectoryIndex index.php index.html index.html.var

AccessFileName .htaccess

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
</Files>

TypesConfig /etc/mime.types

DefaultType text/plain

<IfModule mod_mime_magic.c>
    MIMEMagicFile conf/magic
</IfModule>

HostnameLookups Off



ErrorLog logs/error_log

LogLevel warn

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent




CustomLog logs/access_log combined

ServerSignature On

Alias /icons/ "/www/icons/"

<Directory "/www/icons">
    Options Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

<IfModule mod_dav_fs.c>
    DAVLockDB /var/lib/dav/lockdb
</IfModule>

ScriptAlias /cgi-bin/ "/www/cgi-bin/"

<Directory "/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>



IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable

AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*

AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core

AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^

DefaultIcon /icons/unknown.gif


ReadmeName README.html
HeaderName HEADER.html


AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw

LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW

ForceLanguagePriority Prefer Fallback

AddDefaultCharset GB2312



AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz



AddHandler type-map var

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml




Alias /error/ "/www/error/"

<IfModule mod_negotiation.c>
<IfModule mod_include.c>
    <Directory "/www/error">
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
        Allow from all
        LanguagePriority en es de fr
        ForceLanguagePriority Prefer Fallback
    </Directory>


</IfModule>
</IfModule>

BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0

BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully


NameVirtualHost *:80


<VirtualHost *:80>
    ServerAdmin xdzms@126.com
    DocumentRoot /www/ww2.xdzms.cn
    ServerName www.xdzms.cn
    ErrorLog logs/www.xdzms.cn-error_log
    CustomLog logs/www.xdzms.cn-access_log common
</VirtualHost>
我的MY.CNF文件内容如下:

[mysqld]
datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql
old_passwords=1

skip-locking

skip-name-resolve

skip-networking

skip-locking

skip-name-resolve

back_log = 384

max_allowed_packet = 64M

query_cache_size = 64M

query_cache_limit = 8M

connect_timeout=20

key_buffer_size=512M  

max_connections=100000

wait_timeout=10

read_buffer_size=32M

sort_buffer_size = 6M

myisam_sort_buffer_size=128M

join_buffer_size = 32M

table_cache=1024

thread_cache=64

default-character-set=gbk

thread_concurrency = 8



[client]
default-character-set =gbk




[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
有88.8%的cpu是系统占用的,看看系统在干什么
我遇到过这样的问题 是因为mysql 语句过于复杂 (对多个表关联查询) 把 语句优化下就好了
可以通过 查看mysql进程看是否有语句用时过长(如果有哪条语句一直在运行说明这条语句有问题)
确定是MYSQL?
88.8%sy,  
表示系统等待设备驱动系统调用的比例高
罪魁祸首:效率低下的设备驱动程序,硬件故障导致的假中断,
CPU速度慢或数量不足

用sar 1 5 等命令看下。是不是某个程序占用了大量的资源,再作判断。
从top的结果来看
首先你有2400+的httpd进程,每个进程需要占用一定的内存,这么多的httpd导致内存用尽,然后系统大量使用swap,使用swap之后肯定会导致iowait。

1。你是否有这么大的访问量,导致有2400+的httpd并发,如果是,把apache改为worker模式,或者改用nginx,或者加2G内存
2。如果不是,那么应该就是mysql有慢查询(极其慢),导致httpd进程不能快速释放

解释的够清楚了吧
如果还搞不定,找我