Skip to content

Instantly share code, notes, and snippets.

@spidersea
spidersea / grep_awk_sed 多核利用
Created December 24, 2013 08:37
grep/awk/sed 多核利用
如何利用多核CPU来加速你的Linux命令 — awk, sed, bzip2, grep, wc等
你是否曾经有过要计算一个非常大的数据(几百GB)的需求?或在里面搜索,或其它操作——一些无法并行的操作。数据专家们,我是在对你们说。你可能有一个4核或更多核的CPU,但我们合适的工具,例如 grep, bzip2, wc, awk, sed等等,都是单线程的,只能使用一个CPU内核。
借用卡通人物Cartman的话,“如何我能使用这些内核”?
要想让Linux命令使用所有的CPU内核,我们需要用到GNU Parallel命令,它让我们所有的CPU内核在单机内做神奇的map-reduce操作,当然,这还要借助很少用到的–pipes 参数(也叫做–spreadstdin)。这样,你的负载就会平均分配到各CPU上,真的。
BZIP2
1. 压缩参数
curl --compressed -I " http://xx.x.x.x./xxx/"
##nginx 添加jason压缩
gzip_types text/plain application/x-javascript text/css text/xml application/xml application/xml+rss text/javascript image/x-icon image/x-ms-bmp image/g application/json
##tomcat 添加jason压缩
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="application/json,application/xml,text/html,text/xml"
一、下载并编译mod_rpaf模块到apache
二、启动将以下配置添加到httpd.conf
LoadModule rpaf_module modules/mod_rpaf-2.0.so
RPAFenable On
RPAFsethostname On
RPAFproxy_ips 10.130.x.x 10.130.x.x 10.130.x.x 10.130.x.x 10.130.x.x 10.130.x.x ###前端IP
RPAFheader NS-Client-IP
三、重启apache,查看apache日志
RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} !^\/page1\/
RewriteCond %{REQUEST_URI} !^\/page2\/
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} \/page1\/ [OR]
RewriteCond %{REQUEST_URI} \/page2\/
@spidersea
spidersea / Linux shell脚本 while命令解决 ssh登陆单行问题
Created December 24, 2013 08:35
Linux shell脚本 while命令解决 ssh登陆单行问题
#!/bin/bash
cat list |while read line
do
echo ===============$line
TARGE_IP=`echo $line|awk '{print $3}'`
TARGE_PORT=`echo $line|awk '{print $4}'`
ssh -p $TARGE_PORT $TARGE_IP "ps axu|grep webserver" < /dev/null
#!/bin/bash
iptables_ip(){
FILE=$1
egrep -iv "Baiduspider|bingbot|360Spider|JianKongBao|Ezooms|msnbot|Safari|AhrefsBot|Firefox|TurnitinBot|bot|AppleWebKit" $FILE|awk '{print $1}' |sort -n|uniq -c|sort -nr|awk '{if ($1>50) print $1" "$2}' >.tmp_ip
if [ -s .tmp_ip ]
then
while read line
do