安装 libdatrie , 需要 libdatrie-0.2.4 或更新的版本
它依赖 libiconv .
安装:
================================
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure
make && make install
libdatrie 下载地址:
http://linux.thai.net/~thep/datrie/datrie.html#Download
安装:
================================
wget ftp://linux.thai.net/pub/ThaiLinux/software/libthai/libdatrie-0.2.4.tar.gz
tar -zxf libdatrie-0.2.4.tar.gz
cd libdatrie-0.2.4
./configure --prefix=/usr/local/libdatrie/
make ICONV_LIBS='/usr/local/lib/libiconv.so'
make install
编译出现错误 trietool.c:125: undefined reference to `libiconv'
解决办法为:./configure LDFLAGS=-L/usr/local/lib LIBS=-liconv
安装 PHP 扩展
================================
wget https://github.com/wulijun/php-ext-trie-filter/archive/master.zip
unzip master.zip
cd php-ext-trie-filter-master/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-trie_filter=/usr/local/libdatrie/
make && make install
将生成的 trie_filter.so 文件复制到 php 扩展目录,并在 php.ini 中添加该文件
修改 php.ini 文件,添加 trie_filter 扩展:extension=trie_filter.so,重启PHP。
查看phpinfo发现trie_filter 扩展可用,如下图所示:
https://github.com/wulijun/php-ext-trie-filter
=============遇到的问题===============
安装libiconv如果遇到下面的问题:
In file included from progname.c:26:0:
./stdio.h:1010:1: error: 'gets' undeclared here (not in a function)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
^
make[2]: *** [progname.o] Error 1
make[2]: Leaving directory `/usr/local/directadmin/custombuild/libiconv-1.14/srclib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/usr/local/directadmin/custombuild/libiconv-1.14/srclib'
make: *** [all] Error 2
解决方案:
cd /tmp/libiconv-1.14/srclib
vim stdio.in.h
找到这行内容:
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
替换成:
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
注意:结尾的#endif也要包括。
安装PHP如果遇到下面的问题:
/usr/include/stdio.h:325:14: note: expected ‘size_t *’ but argument is of type ‘zend_size_t *’
extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;
^
/root/soft/soft/php-ext-trie-filter/trie_filter.c:566:27: error: macro "RETVAL_STRINGL" requires 3 arguments, but only 2 given
RETVAL_STRINGL(p, plen);
^
/root/soft/soft/php-ext-trie-filter/trie_filter.c:566:5: error: ‘RETVAL_STRINGL’ undeclared (first use in this function)
RETVAL_STRINGL(p, plen);
^
解决方案:
vi php-ext-trie-filter/trie_filter.c
修改:
RETVAL_STRINGL(p, plen);
中PHP7这个宏定义只需要两个参数,
而PHP5需要三个
#if PHP_MAJOR_VERSION < 7
RETVAL_STRINGL(p, plen,0);
#else
RETVAL_STRINGL(p, plen);
#endif
解决
它依赖 libiconv .
安装:
================================
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure
make && make install
libdatrie 下载地址:
http://linux.thai.net/~thep/datrie/datrie.html#Download
安装:
================================
wget ftp://linux.thai.net/pub/ThaiLinux/software/libthai/libdatrie-0.2.4.tar.gz
tar -zxf libdatrie-0.2.4.tar.gz
cd libdatrie-0.2.4
./configure --prefix=/usr/local/libdatrie/
make ICONV_LIBS='/usr/local/lib/libiconv.so'
make install
编译出现错误 trietool.c:125: undefined reference to `libiconv'
解决办法为:./configure LDFLAGS=-L/usr/local/lib LIBS=-liconv
安装 PHP 扩展
================================
wget https://github.com/wulijun/php-ext-trie-filter/archive/master.zip
unzip master.zip
cd php-ext-trie-filter-master/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-trie_filter=/usr/local/libdatrie/
make && make install
将生成的 trie_filter.so 文件复制到 php 扩展目录,并在 php.ini 中添加该文件
修改 php.ini 文件,添加 trie_filter 扩展:extension=trie_filter.so,重启PHP。
查看phpinfo发现trie_filter 扩展可用,如下图所示:
https://github.com/wulijun/php-ext-trie-filter
=============遇到的问题===============
安装libiconv如果遇到下面的问题:
In file included from progname.c:26:0:
./stdio.h:1010:1: error: 'gets' undeclared here (not in a function)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
^
make[2]: *** [progname.o] Error 1
make[2]: Leaving directory `/usr/local/directadmin/custombuild/libiconv-1.14/srclib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/usr/local/directadmin/custombuild/libiconv-1.14/srclib'
make: *** [all] Error 2
解决方案:
cd /tmp/libiconv-1.14/srclib
vim stdio.in.h
找到这行内容:
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
替换成:
#if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)
_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
#endif
注意:结尾的#endif也要包括。
安装PHP如果遇到下面的问题:
/usr/include/stdio.h:325:14: note: expected ‘size_t *’ but argument is of type ‘zend_size_t *’
extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;
^
/root/soft/soft/php-ext-trie-filter/trie_filter.c:566:27: error: macro "RETVAL_STRINGL" requires 3 arguments, but only 2 given
RETVAL_STRINGL(p, plen);
^
/root/soft/soft/php-ext-trie-filter/trie_filter.c:566:5: error: ‘RETVAL_STRINGL’ undeclared (first use in this function)
RETVAL_STRINGL(p, plen);
^
解决方案:
vi php-ext-trie-filter/trie_filter.c
修改:
RETVAL_STRINGL(p, plen);
中PHP7这个宏定义只需要两个参数,
而PHP5需要三个
#if PHP_MAJOR_VERSION < 7
RETVAL_STRINGL(p, plen,0);
#else
RETVAL_STRINGL(p, plen);
#endif
解决
转自:http://flyer0126.iteye.com/blog/1931212
早就想研究下敏感词过滤问题,今天有些时间,正好实践一下。
1. 安装:libdatrie (http://linux.thai.net/~thep/datrie/datrie.html#Download)
早就想研究下敏感词过滤问题,今天有些时间,正好实践一下。
1. 安装:libdatrie (http://linux.thai.net/~thep/datrie/datrie.html#Download)
ngx_lua_waf 安装说明文档
作者github地址:
https://github.com/loveshell/ngx_lua_waf
ngx_lua_waf是我一个基于ngx_lua的web应用防火墙。
代码很简单,开发初衷主要是使用简单,高性能和轻量级。
现在开源出来.其中包含我们的过滤规则。如果大家有什么建议和想fa,欢迎和我一起完善。
用途:
用于过滤post,get,cookie方式常见的web攻击
防止sql注入,本地包含,部分溢出,fuzzing测试,xss,SSRF等web攻击
防止svn/备份之类文件泄漏
防止ApacheBench之类压力测试工具的攻击
屏蔽常见的扫描黑客工具,扫描器[separator]
屏蔽异常的网络请求
屏蔽图片附件类目录php执行权限
防止webshell上传
正文:
1 下载luajit 2.0并安装
http://luajit.org/download.html
直接使用源码make && make install
所以lib和include是直接放在/usr/local/lib和usr/local/include
wget http://luajit.org/download/LuaJIT-2.0.3.tar.gz
tar -zxvf LuaJIT-2.0.3.tar.gz
cd LuaJIT-2.0.3
make
make install
cd ../
2 下载nginx源码解压
wget http://nginx.org/download/nginx-1.7.6.tar.gz
注意版本号,如果机子上已经装了nginx,不想升级的话,请使用/usr/local/nginx/sbin/nginx -v 来查看版本号tar -zxvf nginx-1.2.7.tar.gz
wget http://nginx.org/download/nginx-1.7.6.tar.gz
3 下载ngx_devel_kit解压
https://github.com/simpl/ngx_devel_kit/tags
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz --no-check-certificate
tar -zxvf v0.2.19
4 下载nginx_lua_module解压
https://github.com/chaoslawful/lua-nginx-module/tags
wget https://github.com/openresty/lua-nginx-module/archive/v0.9.13rc1.tar.gz --no-check-certificate
tar -zxvf v0.9.13rc1
5 进入nginx源码文件夹
tar -zxvf nginx-1.7.6.tar.gz
cd nginx-1.7.6
6 导入环境变量,编译
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/soft/ngx_devel_kit-0.2.19 --add-module=/root/soft/lua-nginx-module-0.9.13rc1 --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"
make -j2
make install
7 请提前新建/data/logs/hack/目录攻击日志,并赋予nginx用户对该目录的写入权限。
www账户是跑nginx和php-fpm
mkdir -p /data/logs/hack/
chown -R www:www /data/logs/hack/
chmod -R 755 /data/logs/hack/
8 安装ngx_lua_waf模块
wget https://github.com/loveshell/ngx_lua_waf/archive/master.zip --no-check-certificate
unzip master
cd ngx_lua_waf-master/
mkdir /usr/local/nginx/conf/waf
mv * /usr/local/nginx/conf/waf/
然后在nginx.conf里的http配置里添加
lua_package_path "/usr/local/nginx/conf/waf/?.lua";
lua_shared_dict limit 10m;
init_by_lua_file /usr/local/nginx/conf/waf/init.lua;
access_by_lua_file /usr/local/nginx/conf/waf/waf.lua;
配置config.lua里的waf规则目录(一般在waf/conf/目录下)
RulePath = "/usr/local/nginx/conf/waf/wafconf/"
绝对路径如有变动,需对应修改
注意:waf.lua一定要放在/usr/local/nginx-help/conf/waf.lua 已经他的子目录.否则会报500错误.
/usr/local/nginx/sbin/nginx -t
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
9 过滤配置说明:
过滤规则在wafconf下,可根据需求自行调整,每条规则需换行,或者用|分割
global是全局过滤文件,里面的规则对post和get都过滤
get是只在get请求过滤的规则
post是只在post请求过滤的规则
whitelist是白名单,里面的url匹配到不做过滤
user-agent是对user-agent的过滤规则
为了不返回一些无用给用户直接把注入测试防护返回信息改为http 403状态,修改/usr/local/nginx-help/conf/init.lua
function check()
ngx.header.content_type = "text/html"
--ngx.print("403")
ngx.exit(403)
end
注意:每次更改waf.lua代码需要把nginx reload一下!
作者github地址:
https://github.com/loveshell/ngx_lua_waf
ngx_lua_waf是我一个基于ngx_lua的web应用防火墙。
代码很简单,开发初衷主要是使用简单,高性能和轻量级。
现在开源出来.其中包含我们的过滤规则。如果大家有什么建议和想fa,欢迎和我一起完善。
用途:
用于过滤post,get,cookie方式常见的web攻击
防止sql注入,本地包含,部分溢出,fuzzing测试,xss,SSRF等web攻击
防止svn/备份之类文件泄漏
防止ApacheBench之类压力测试工具的攻击
屏蔽常见的扫描黑客工具,扫描器[separator]
屏蔽异常的网络请求
屏蔽图片附件类目录php执行权限
防止webshell上传
正文:
1 下载luajit 2.0并安装
http://luajit.org/download.html
直接使用源码make && make install
所以lib和include是直接放在/usr/local/lib和usr/local/include
wget http://luajit.org/download/LuaJIT-2.0.3.tar.gz
tar -zxvf LuaJIT-2.0.3.tar.gz
cd LuaJIT-2.0.3
make
make install
cd ../
2 下载nginx源码解压
wget http://nginx.org/download/nginx-1.7.6.tar.gz
注意版本号,如果机子上已经装了nginx,不想升级的话,请使用/usr/local/nginx/sbin/nginx -v 来查看版本号tar -zxvf nginx-1.2.7.tar.gz
wget http://nginx.org/download/nginx-1.7.6.tar.gz
3 下载ngx_devel_kit解压
https://github.com/simpl/ngx_devel_kit/tags
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz --no-check-certificate
tar -zxvf v0.2.19
4 下载nginx_lua_module解压
https://github.com/chaoslawful/lua-nginx-module/tags
wget https://github.com/openresty/lua-nginx-module/archive/v0.9.13rc1.tar.gz --no-check-certificate
tar -zxvf v0.9.13rc1
5 进入nginx源码文件夹
tar -zxvf nginx-1.7.6.tar.gz
cd nginx-1.7.6
6 导入环境变量,编译
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/root/soft/ngx_devel_kit-0.2.19 --add-module=/root/soft/lua-nginx-module-0.9.13rc1 --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"
make -j2
make install
7 请提前新建/data/logs/hack/目录攻击日志,并赋予nginx用户对该目录的写入权限。
www账户是跑nginx和php-fpm
mkdir -p /data/logs/hack/
chown -R www:www /data/logs/hack/
chmod -R 755 /data/logs/hack/
8 安装ngx_lua_waf模块
wget https://github.com/loveshell/ngx_lua_waf/archive/master.zip --no-check-certificate
unzip master
cd ngx_lua_waf-master/
mkdir /usr/local/nginx/conf/waf
mv * /usr/local/nginx/conf/waf/
然后在nginx.conf里的http配置里添加
lua_package_path "/usr/local/nginx/conf/waf/?.lua";
lua_shared_dict limit 10m;
init_by_lua_file /usr/local/nginx/conf/waf/init.lua;
access_by_lua_file /usr/local/nginx/conf/waf/waf.lua;
配置config.lua里的waf规则目录(一般在waf/conf/目录下)
RulePath = "/usr/local/nginx/conf/waf/wafconf/"
绝对路径如有变动,需对应修改
注意:waf.lua一定要放在/usr/local/nginx-help/conf/waf.lua 已经他的子目录.否则会报500错误.
/usr/local/nginx/sbin/nginx -t
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
9 过滤配置说明:
过滤规则在wafconf下,可根据需求自行调整,每条规则需换行,或者用|分割
global是全局过滤文件,里面的规则对post和get都过滤
get是只在get请求过滤的规则
post是只在post请求过滤的规则
whitelist是白名单,里面的url匹配到不做过滤
user-agent是对user-agent的过滤规则
为了不返回一些无用给用户直接把注入测试防护返回信息改为http 403状态,修改/usr/local/nginx-help/conf/init.lua
function check()
ngx.header.content_type = "text/html"
--ngx.print("403")
ngx.exit(403)
end
注意:每次更改waf.lua代码需要把nginx reload一下!
改之前先建立一个登录的用户
1,只允许某个IP登录,拒绝其他所有IP
在 /etc/hosts.allow 写:
sshd: 192.168.1.207
在 /etc/hosts.deny 写:
sshd: ALL
2,禁止某个用户通过ssh登录
在/etc/ssh/sshd_conf添加
AllowUsers 用户名
或者
AllowGroups 组名
或者
DenyUsers 用户名
3、修改默认端口:默认Port为22,并且已经注释掉了;修改是把注释去掉,并修改成其它的端口。
4、禁止root用户远程登陆:修改PermitRootLogin,默认为yes且注释掉了;修改是把注释去掉,并改成no。
5、PermitEmptyPasswords no不允许空密码用户login
1,只允许某个IP登录,拒绝其他所有IP
在 /etc/hosts.allow 写:
sshd: 192.168.1.207
在 /etc/hosts.deny 写:
sshd: ALL
2,禁止某个用户通过ssh登录
在/etc/ssh/sshd_conf添加
AllowUsers 用户名
或者
AllowGroups 组名
或者
DenyUsers 用户名
3、修改默认端口:默认Port为22,并且已经注释掉了;修改是把注释去掉,并修改成其它的端口。
4、禁止root用户远程登陆:修改PermitRootLogin,默认为yes且注释掉了;修改是把注释去掉,并改成no。
5、PermitEmptyPasswords no不允许空密码用户login
TCMalloc(Thread-Caching Malloc)是google开发的开源工具──“google-perftools”中的成员,地址:http://code.google.com/p/gperftools/。与标准的glibc库的malloc相比,TCMalloc在内存的分配上效率和速度要高得多,可以在很大程度上提高MySQL服务器在高并发情况下的性能,降低系统负载。
为MySQL添加TCMalloc库的安装步骤(Linux环境):
1、64位操作系统请先安装libunwind库,32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
tar zxvf libunwind-0.99-alpha.tar.gz
cd libunwind-0.99-alpha/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
2、安装google-perftools:
wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
tar zxvf gperftools-2.0.tar.gz
cd gperftools-2.0
./configure
make && make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
3、修改MySQL启动脚本(根据你的MySQL安装位置而定):
vi /usr/local/mysql/bin/mysqld_safe
在# executing mysqld_safe的下一行,加上:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
保存后退出,然后重启MySQL服务器。
4、使用lsof命令查看tcmalloc是否起效:
/usr/sbin/lsof -n | grep tcmalloc
如果发现以下信息,说明tcmalloc已经起效:
mysqld 10847 mysql mem REG 8,5 1203756 20484960 /usr/local/lib/libtcmalloc.so.0.0.0
如果看不到这些信息,表示perftools没有配置成功,可能是因为你编译mysql时使用了参数with-mysqld-ldflags=-all-static。
为MySQL添加TCMalloc库的安装步骤(Linux环境):
1、64位操作系统请先安装libunwind库,32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。
wget http://download.savannah.gnu.org/releases/libunwind/libunwind-0.99-alpha.tar.gz
tar zxvf libunwind-0.99-alpha.tar.gz
cd libunwind-0.99-alpha/
CFLAGS=-fPIC ./configure
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
2、安装google-perftools:
wget http://gperftools.googlecode.com/files/gperftools-2.0.tar.gz
tar zxvf gperftools-2.0.tar.gz
cd gperftools-2.0
./configure
make && make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
3、修改MySQL启动脚本(根据你的MySQL安装位置而定):
vi /usr/local/mysql/bin/mysqld_safe
在# executing mysqld_safe的下一行,加上:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
保存后退出,然后重启MySQL服务器。
4、使用lsof命令查看tcmalloc是否起效:
/usr/sbin/lsof -n | grep tcmalloc
如果发现以下信息,说明tcmalloc已经起效:
mysqld 10847 mysql mem REG 8,5 1203756 20484960 /usr/local/lib/libtcmalloc.so.0.0.0
如果看不到这些信息,表示perftools没有配置成功,可能是因为你编译mysql时使用了参数with-mysqld-ldflags=-all-static。
1:load Average
1.1:什么是Load?什么是Load Average?
Load 就是对计算机干活多少的度量(WikiPedia:the system Load is a measure of the amount of work that a compute system is doing)
简单的说是进程队列的长度。Load Average 就是一段时间(1分钟、5分钟、15分钟)内平均Load。【参考文章:unix Load Average Part1:How It Works】
1.1:什么是Load?什么是Load Average?
Load 就是对计算机干活多少的度量(WikiPedia:the system Load is a measure of the amount of work that a compute system is doing)
简单的说是进程队列的长度。Load Average 就是一段时间(1分钟、5分钟、15分钟)内平均Load。【参考文章:unix Load Average Part1:How It Works】
可以通过/sbin/iptables -F清除所有规则来暂时停止防火墙: (警告:这只适合在没有配置防火墙的环境中,如果已经配置过默认规则为deny的环境,此步骤将使系统的所有网络访问中断)
如果想清空的话,先执行
/sbin/iptables -P INPUT ACCEPT
然后执行
/sbin/iptables -F
通过iptables -L 看到如下信息
同时需要保存,并重启服务
/etc/rc.d/init.d/iptables save
/etc/rc.d/init.d/iptables restart
如果想清空的话,先执行
/sbin/iptables -P INPUT ACCEPT
然后执行
/sbin/iptables -F
通过iptables -L 看到如下信息
同时需要保存,并重启服务
/etc/rc.d/init.d/iptables save
/etc/rc.d/init.d/iptables restart
整理一些常用分析网站的小命令方便大家排障,内容均来源于网络。
系统连接状态篇:
1.查看TCP连接状态
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}' 或
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
2.查找请求数请20个IP(常用于查找攻来源):
系统连接状态篇:
1.查看TCP连接状态
netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn
netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}' 或
netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'
netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'
netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn
netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c
2.查找请求数请20个IP(常用于查找攻来源):
服务器上的一些统计数据:
1)统计80端口连接数
netstat -nat|grep -i "80"|wc -l
1
2)统计httpd协议连接数
ps -ef|grep httpd|wc -l
1
3)、统计已连接上的,状态为“established'
netstat -na|grep ESTABLISHED|wc -l
2
4)、查出哪个IP地址连接最多,将其封了.
netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r +0n
netstat -na|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r +0n
最直接的方法如下:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
LAST_ACK 14
SYN_RECV 348
ESTABLISHED 70 (活动连接数,实际正在处理的请求数量,最有意义的一个字段)
FIN_WAIT1 229
FIN_WAIT2 30
CLOSING 33
TIME_WAIT 18122
状态:描述
CLOSED:无连接是活动的或正在进行
LISTEN:服务器在等待进入呼叫
SYN_RECV:一个连接请求已经到达,等待确认
SYN_SENT:应用已经开始,打开一个连接
ESTABLISHED:正常数据传输状态
FIN_WAIT1:应用说它已经完成
FIN_WAIT2:另一边已同意释放
ITMED_WAIT:等待所有分组死掉
CLOSING:两边同时尝试关闭
TIME_WAIT:另一边已初始化一个释放
LAST_ACK:等待所有分组死掉
也就是说,这条命令可以把当前系统的网络连接状态分类汇总。
1)统计80端口连接数
netstat -nat|grep -i "80"|wc -l
1
2)统计httpd协议连接数
ps -ef|grep httpd|wc -l
1
3)、统计已连接上的,状态为“established'
netstat -na|grep ESTABLISHED|wc -l
2
4)、查出哪个IP地址连接最多,将其封了.
netstat -na|grep ESTABLISHED|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r +0n
netstat -na|grep SYN|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -r +0n
最直接的方法如下:
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
LAST_ACK 14
SYN_RECV 348
ESTABLISHED 70 (活动连接数,实际正在处理的请求数量,最有意义的一个字段)
FIN_WAIT1 229
FIN_WAIT2 30
CLOSING 33
TIME_WAIT 18122
状态:描述
CLOSED:无连接是活动的或正在进行
LISTEN:服务器在等待进入呼叫
SYN_RECV:一个连接请求已经到达,等待确认
SYN_SENT:应用已经开始,打开一个连接
ESTABLISHED:正常数据传输状态
FIN_WAIT1:应用说它已经完成
FIN_WAIT2:另一边已同意释放
ITMED_WAIT:等待所有分组死掉
CLOSING:两边同时尝试关闭
TIME_WAIT:另一边已初始化一个释放
LAST_ACK:等待所有分组死掉
也就是说,这条命令可以把当前系统的网络连接状态分类汇总。
安装步骤:
(系统要求:Linux 2.6+ 内核,本文中的Linux操作系统为CentOS 5.3,另在RedHat AS4上也安装成功)
一、获取相关开源程序:
1、【适用CentOS操作系统】利用CentOS Linux系统自带的yum命令安装、升级所需的程序库(RedHat等其他Linux发行版可从安装光盘中找到这些程序库的RPM包,进行安装):
sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
(系统要求:Linux 2.6+ 内核,本文中的Linux操作系统为CentOS 5.3,另在RedHat AS4上也安装成功)
一、获取相关开源程序:
1、【适用CentOS操作系统】利用CentOS Linux系统自带的yum命令安装、升级所需的程序库(RedHat等其他Linux发行版可从安装光盘中找到这些程序库的RPM包,进行安装):
sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers