思路:nginx启动后会有nginx.pid文件在指定位置下,通过判断该文件是否存在。决定nginx是否已经启动。#!/bin/bash#this is my first try to test write a shell to control nginx daemon#History 2015-08-04 masterliuPATH=/usr/bin/:/usr/local/bin:/bin:/usr/sbin:/usr/local/sbin:/sbin:~/binexport PATH#this file could be configured in nginx.confPIDfile=/usr/local/nginx/logs/nginx.pidNginxd=/usr/local/nginx/sbin/ngi...
#!/bin/sh
#####################################################
# Name: create_nginx_conf.sh
# Version: V1.0
# Author: 运维菜鸟
# Description: 创建nginx相关配置文件
# Create Date: 2017-07-04
# Email:
######################################################env.sh文件内容格式:10.10.2.6=basics-price-service;#function_n...
环境及规划[root@nginx-node01 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
ID主机名ip系统配置软件版本操作系统01nginx-node01192.168.56.1041C 1G1.16.0稳定版CentOS 7.6.1810编译依赖检查gcc编译环境pcre & pcre-devzlib & zlib-devopenssl & openssl-dev[root@nginx-node01 nginx]# cat checkinstall.sh
#!/bin/bash
#auto install packages nginx required function checkInstall(){echo "Che...
1、简介 有时候nginx发布了新BUG或者添加了新的功能时,想要更新的时候服务又不能中断,这时候就要用到nginx的平滑升级了。该脚本同样适用于添加新扩展,添加新扩展的时候只需要把更新的版本修改为当前版本,更新的时候把需要添加的扩展加上去即可。我这里nginx安装目录为/usr/local/nginx当前系统,阿里云ECS CentOS 7 64位2、查看nginx版本与编译信息/usr/local/nginx/sbin/nginx -V注:这里的扩展要记录下来(重要),等下升...
#!/bin/bash
#$$表示当前shell的pid号,需要过滤掉(防止当前shell脚本名字包含nginx的字符)
ps -ef|grep nginx|grep -vE "grep|$$" >/dev/null
#直接通过$?获取上一句shell执行的状态
if [ $? -eq 0 ];thenecho"Nginx is running"elsesystemctl start nginxecho"Nginx is down,Starting..."fi 原文:https://www.cnblogs.com/bretzhao/p/11826464.html
Linux下添加shell脚本使得nginx日志每天定时切割压缩一 简介对于nginx的日志文件,特别是access日志,如果我们不做任何处理的话,最后这个文件将会变得非常庞大这时,无论是出现异常时查日志,还是使用“GoAccess”等工具对日志进行分析都将会变得非常麻烦。因此,每天定时对nginx日志进行切割压缩就非常有必要了二 实现我的实现思路是每天晚上接近12点时定时执行脚本。其脚本内容就是将当前的nginx日志先按照当天日期进行重命名接...
1、把IP数量直接输出显示:cat access_log_2011_06_26.log |awk ‘{print $1}’|uniq -c|wc -l2、把IP数量输出到文本显示:cat access_log_2011_06_26.log |awk ‘{print $1}’|uniq -c|wc -l > ip.txt总结:如果单个访问日志大小超过2G,用这个命令查看时很占系统资源,系统负载会上升;所以在服务器高负载时不要查看,最好在低负载时间段查看。上面截图是公司其中一台广告服务器的一天ip访问量,这个访问量其实还包括了搜索引擎的...
#!/bin/bashlogs_path="/opt/nginx/logs/"pid_path="/opt/nginx/logs/nginx.pid"mv ${logs_path}access.log ${logs_path}access_$(date -d "yesterday" +"%Y%m%d").logkill -USR1 `cat ${pid_path}`crontab -e00 00 * * * sh /opt/shell/cutnginx.sh该脚本不能执行可能原因:脚本没有X权限在非root用户下调用时需要密码,放到root用户下即可本文出自 “dba天空” 博客,请务必保留此出处http://9425473.blog.51cto.com/9415473/166...
默认nginx只会生成一个访问日志,在每天的积累下,日志文件会变的非常大,如果需要做一下日志的分析,无论是使用脚本分析,还是把日志下载本地分析,都不太方便。每天分割Nginx的访问日志,有利于分析日志。一:新建脚本文件vim cut_nginx_log.sh
#!/bin/bash#nginx access log segmentation shell script#www.webyang.net#日志目录log_dir="/usr/local/nginx/logs/"cd $log_dirtime=`date +%Y%m%d --date="-1 day"`#nginx启动目录...
python脚本log_format main ‘$remote_addr – $remote_user [$time_iso8601] “$request” ‘‘$status $body_bytes_sent “$http_referer” ‘‘”$http_user_agent” “$http_x_forwarded_for” ‘‘ “$upstream_addr” “$upstream_status” “$request_time"`;cat website.access.log| awk ‘{print $(NF)}’ | awk -F “\”” ‘{print $2′}>a.txtpaste -d ” ” website.access.log a.txt > b.txtcat b.txt |awk ‘($NF>...
"""2 Django settings for searchlog project.3 4 Generated by ‘django-admin startproject‘ using Django 1.8.7.5 6 For more information on this file, see7 https://docs.djangoproject.com/en/1.8/topics/settings/8 9 For the full list of settings and their values, see10 https://docs.djangoproject.com/en/1.8/ref/settings/11 """12 13 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)1...
统计访问最多的ip1. tail -n 10000 xxaccess_log | cut -d " " -f 1 |sort|uniq -c|sort -rn|head -10 |more2.tail -n 10000 xx-access_log | awk ‘{print $1}‘|sort|uniq -c|sort -rn|head -10 | more统计访问最多的urltail -n 10000 xx-access_log |awk ‘{print $7}‘| sort|uniq -c| sort -rn| head -10 | more指定ip统计访问最多的urltail -n 1000 xx-access_log | grep ‘00.00.00.00’|awk ‘{print $7}‘| sort|uniq -c...
公司给出一个需求,指定时间内,统计请求driver.upload.position(司机位置上报接口)中,来源是华为push(come_from=huawei_push)的数量,要求是按天统计。
看一下url格式,url中,method参数就是所请求的接口地址api10 100.116.219.186 | - | 17/May/2019:02:00:17 +0800 | GET /rest?app_ver=5.1.2.0&appkey=30000001&come_from=huawei_push&from=internal&gps_timestamp=1558029615&gps_type=baidu&latitude=1.0&log_time=201...
nginx-log-rotate.sh:
#!/bin/bash#---------------------------------------------# Comment:Used for rotating nginx log file.# Author: alin# Date: 09/27/2018# Version: 1.0#---------------------------------------------
LOG_FILE="*.log"LOG_DIR=/data/log/nginxLOG_SIZE=100CURR_TIME=$(date +%Y%m%d%H%M)
for log in `ls $LOG_DIR/$LOG_FILE`do total_size=`stat -c %s $log` size=$(($total_size/1024/1024)) ...
shell进行Nginx日志分析日志格式log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'' $host "$request_uri" $status'' "$http_referer" "$http_user_agent"';日志条目95.213.177.126 - - [07/Jul/2019:13:17:30 +0800] "POST http://check.proxyradar.com/azenv.php?auth=156247664979&a=PSCN&i=2018476175&p=80 HTTP/1.1" 404 27 "http://best-proxies.ru/" "Mozilla/4.0 (compatible; MSIE 8.0; Wi...