虚拟化容器,大数据,DBA,中间件,监控。

linux httpd进程占用CPU高解决方法

08 10月
作者:admin|分类:应用管理
服务器最近一直出现httpd进程占用CPU很高,甚至100%

查看80端口的连接信息:
lsof -i:80
发现有很多连接都是到同一地区的IP。
看来是有站点被挂马了。需要找出被挂马的文件

这些文件导至httpd不断增加,CPU占用后不释放
解决方法:
一,开启apache的日志监控,找出当前被访问的站点,然后检查这些文件是否有异常。
以下是apachetop一个日志监控工具的安装:

通过apachetop这个工具可以动态的查看apache的日志文件,还可以直观的看到访问的每个地址的请求数、速度及流量等信息.
 

http://www.webta.org/projects/apachetop/

Apachetop is a curses-based top-like display for Apache information, including requests per second, bytes per second, most popular URLs, etc.

Apachetop watches a logfile generated by Apache (in standard common or combined logformat, although it doesn't (yet) make use of any of the extra fields in combined) and generates human-parsable output in realtime.

安装很简单

#yum -y install readline-devel

# wget http://www.webta.org/apachetop/apachetop-0.12.6.tar.gz
# tar xzvf apachetop-0.12.6.tar.gz
# cd apachetop-0.12.6
# ./configure
# make
# make install

分析查看日志的时候
apachetop -f access.log


下面是用法说明:

引用
ApacheTop v0.12.6 - Usage:
File options:
-f logfile open logfile (assumed common/combined) [/var/log/httpd-access.log]
(repeat option for more than one source)

URL/host/referrer munging options:
-q 保持请求字符串[no]
-l 所有的url小写[no]
-s num 保持url路径段数量 [all]
-p 在referrer前面保留协议 [no]
-r 保留每一个的主机/ip [no]

Stats options:
必须提供两个参数 default: [-T 30]
缺省设置为保持记录状态30秒,30秒后数据刷新了。为了提供更多的信息给我们分析,我们可以调节下面的参数。
-H hits 保持状态只到多少点击数
-T secs 保持状态只到多少秒

-d secs 刷新延迟时间[5]

-h 这个帮助。


当执行之后,还有命令可以切换显示状态:
引用
ApacheTop version 0.12.6, Copyright (c) 2003-2004, Chris Elsworth

ONE-TOUCH COMMANDS
d : 切换urls/referrers/hosts显示模式开关
n : 切换hits & bytes或返回代码开关
h or ? : 帮助信息
p : (un)暂停显示 (冻结更新)
q : 退出 ApacheTop
up/down : 移动星标 up/down
right/left : 进入/退出逐条显示模式
子菜单:
s: 排序: [the appropriate menu will appear for your display]
r) requests R) reqs/sec b) bytes B) bytes/sec
2) 2xx 3) 3xx 4) 4xx 5) 5xx

t: 固定显示 ON/OFF:
u) urls r) referrers h) hosts

f: 使用过滤器:
a) add/edit menu c) clear all s) show active (not done yet)
a: ADD FILTER SUBMENU
u) to urls r) to referrers h) to hosts


二,使用top命令进出占用CPU高的进程pid
然后使用 lsof | grep pid  或是lsof -p pid
找出对应进程使用的文件.

然后看这些文件是否异常,异常就删除了,
然后重启apache 服务



浏览7794 评论0
返回
目录
返回
首页
MySQL 启动报错:‘–skip-locking’ is deprecated and will be removed httpd进程占用CPU很高,甚至100%解决方案