常用快捷命令

查看日志中根据毫秒时间戳截取5分钟内日志

cat access.log| awk -F " " '{if($(NF-1)<=1658409900000 &&  $(NF-1)>1658409600000 ){print $0} }'

查看某一时间段出现的网站次数

sed -n '/31\/Sep\/2020:22:38:00/','/31\/Sep\/2020:22:45:01/p' access.log |awk '{print $(NF-4)}'| sort | uniq -c | sort -nr -k1 | head -n 10

 查看某时间段日志

sed -n '/24\/Aug\/2020:10:15:00/','/24\/Aug\/2020:10:15:01/p' access.log

 查找一天内相对应目录修改过的文件

find /application/nginx/conf -mtime -1

 netstat查看连接数

netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a,S[a]}'

 查看访问前十的IP

awk '{print $1}' access.log | sort | uniq -c | sort -nr -k1 | head -n 10

 统计IP访问量(独立ip访问数量)

awk '{print $1}' access.log | sort -n | uniq | wc -l

 查看访问最频的页面(TOP100)

awk '{print $6}' access.log | sort |uniq -c | sort -rn | head -n 20

 统计蜘蛛抓取次数

grep 'Baiduspider' access.log |wc -l

 统计蜘蛛抓取404的次数

grep 'Baiduspider' access.log |grep '404' | wc -l

 响应大于10秒的URL

awk '{if ($12 > 10){print $7}}' access.log|sort|uniq -c|sort -rn |head -5

 统计状态码信息

awk '{print $8}' access.log | sort | uniq -c | sort -nr | head -10

 Nginx日志统计出现最多的前十网址

cat access.log | awk '{print $(NF-4)}'| sort | uniq -c | sort -nr -k1 | head -n 10

 系统查看已删除空间却没有释放的进程

lsof -n |grep deleted

 grep精准匹配字段追加到文件中

cat access.log | grep '\<www.xxx.ccoo.cn\>' | grep '\<500\>' >> file.txt

若出现mysql数据库服务,占用大量无效磁盘空间

备注:遇到的场景是删除了mysql的表,但是是在shell上执行rm表的文件,而不是通过drop table之类的命令去删除表的,于是mysql会一直占用这些表文件的句柄,最后造成磁盘空间100%,这种情况下,也不用重启mysql,只要进入mysql客户端执行flush tables就行了

 宝塔常用命令

https://www.bt.cn/btcode.html 宝塔命令大全

 Mysqldump备份单个库

mysqldump -uUsername -h xx.xx.xx.xx -P9996 DBname t_name --set-gtid-purged=off -p >t_name.sql(表名)

Mysqldump还原

mysql -uroot -p tptradetest </root/tptrade.sql

 mysql给root开启远程访问权限

grant all privileges on *.* to root@'%' identified by 'xxxx';

 php安装mysql扩展:https://www.cnblogs.com/gzyx1988/p/5637929.html

 php安装redis扩展:https://www.runoob.com/redis/redis-php.html

 apache:https://www.linuxidc.com/Linux/2016-12/137875.htm https://www.jianshu.com/p/1e287a2face9

 jdk环境变量:(注意路径和版本)

export JAVA_HOME=/usr/local/jdk1.8.0_60
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

 清华大学公开源:https://mirrors.tuna.tsinghua.edu.cn/

 公开系统:http://www.udeepin.com/6/1990/index.html

 优化mysql表:

optimize table 表名;

 linux安装宝塔命令:

yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

 快速查找命令:

locate

若执行报错: yum install mlocate -y &&	updatedb

MongoDB: remove() 方法并不会真正释放空间,需要执行db.repairDatabase()来回收磁盘空间。

 宝塔面板lamp转lnmp静伪码

if (!-d $request_filename){
set $rule_0 1$rule_0;
}
if (!-f $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/(.*)$ /index.php/$1 last;
}

 找出占用CPU最高的10个进程

ps aux | sort -k3nr | head -n 10

 或查看占用内存最高的10个进程

ps aux | sort -k4nr | head -n 10

 公安备案网址

http://www.beian.gov.cn/portal/index.do

 Linux 分配/home的磁盘空间给根目录

https://www.cnblogs.com/rogear/p/9939429.html

 Nginx日志格式:

log_format myFormat '$remote_addr $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'$http_user_agent $http_x_forwarded_for $http_host $request_time $upstream_response_time $upstream_addr $upstream_status';

 Apache日志格式:

LogFormat "%a %{X-FORWARDED-FOR}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined2

 工信部IPC查询

https://beian.miit.gov.cn/#/Integrated/recordQuery

  

posted @ 2020-08-24 15:08  Armored-forces  阅读(189)  评论(0)    收藏  举报