常用命令

tcpdump 获取80 端口 http请求内容

tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -n -s 0 -A

strace 获取某进程发出的请求

strace -p 10095 -q -f  -s 10000 -e trace=network

查找与替换

查找当前目录 log 文件 中含有 关键字的 文件
find -name '*.py'| xargs grep 'webssh'
find /opt/  -name '*.py'| xargs grep 'webssh'
find /opt/  -name 'chunk-1a9da4da.c92e4ead.js'| xargs grep 'webssh'
替换
find -name '*.py' | xargs perl -pi -e 's|abc|efg|g'
find /opt/  -name '*.py' | xargs perl -pi -e 's|abc|efg|g'
find /opt/  -name 'chunk-1a9da4da.c92e4ead.js' | xargs perl -pi -e 's|abc|efg|g'

正则

查找不包含某个字符串
^((?!abc).)*$

循环删除某目录下文件和文件夹

find /tmp -name "sync*" -exec rm -rf {} \; 2>/dev/null

curl

循环请求并打印耗时
curl -w "%{time_total}" -o /dev/null -s -L    'http://10.244.100.220:8089/aaa/bbb' -X POST -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0' -H 'Accept: application/json' -H 'Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2' -H 'Accept-Encoding: gzip, deflate' -H 'Content-Type: application/json;charset=utf-8'   -H Token: fwrLZKLNJ8EO3gNDEUuL5g-OKk3kw' -H 'SystemCode: YHHDCCDR'    -H 'Connection: keep-alive'   --data '{ "userId":"111", "userName":"222" }'

nginx

日志
http{
  log_format apm '[$time_local]\tclient=$remote_addr\t'
               'request="$request"\t request_length=$request_length\t'
               'http_referer="$http_referer"\t'
               'bytes_sent=$bytes_sent\t'
               'body_bytes_sent=$body_bytes_sent\t'               
               'upstream_addr=$upstream_addr\t'
               'upstream_status=$upstream_status\t'
               'document_root="$document_root"\t'
               'fastcgi_script_name="$fastcgi_script_name"\t'
               'request_filename="$request_filename"\t'
               'request_time=$request_time\t'
               'upstream_response_time=$upstream_response_time\t'
               'upstream_connect_time=$upstream_connect_time\t'
               'upstream_header_time=$upstream_header_time\t'
                #'user_agent="$http_user_agent"\t'
                #'cookie="$http_cookie"\t'
                #'request_body="$request_body"\t'
                ;
    access_log  /opt/logs/nginx/access.log  apm;
}
nginx location 匹配
第一种:加"/"
location  /wddd/ {
    proxy_pass  http://127.0.0.1:8080/;
}
测试结果,请求被代理跳转到:http://127.0.0.1:8080/index.html
第二种: 不加"/"
location  /wddd/ {        
    proxy_pass http://127.0.0.1:8080;
}
测试结果,请求被代理跳转到:http://127.0.0.1:8080/wddd/index.html
第三种: 增加目录加"/"
location  /wddd/ {        
    proxy_pass http://127.0.0.1:8080/sun/;
}
测试结果,请求被代理跳转到:http://127.0.0.1:8080/sun/index.html
第四种:增加目录不加"/"
location  /wddd/ {
    proxy_pass http://127.0.0.1:8080/sun;
}
测试结果,请求被代理跳转到:http://127.0.0.1:8080/sunindex.html
总结
location目录后加"/",只能匹配目录,不加“/”不仅可以匹配目录还对目录进行模糊匹配。
而proxy_pass无论加不加“/”,代理跳转地址都直接拼接。 

firewall-cmd 端口管理

1. 开放/删除端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --remove-port=80/tcp --permanent
2. 查询某个/全部端口
firewall-cmd --query-port=80/tcp
firewall-cmd --list-port
3. 重启防火墙
firewall-cmd --reload
4. 开启/关闭防火墙
systemctl start firewalld.service
systemctl stop firewalld.service
5. 加入/禁止开机启动
systemctl enable firewalld.service
systemctl disable firewalld.service
posted @ 2022-04-20 09:18  mysgk  阅读(48)  评论(0编辑  收藏  举报