OpenResty 部署配置和日志切割

用户头像
wong
关注
发布于: 2020 年 05 月 17 日

OpenResty以前都是手动编译安装,现在官方出的yum源的包编译的很好,就不用再手动编译了,直接用。

安装独立仓库

#centos
yum install -y yum-utils
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo



安装OpenResty

yum install -y openresty



OpenResty配置

#默认部署路径 /usr/local/openresty
#配置文件路径 /usr/local/openresty/nginx/conf
#nginx.conf
user nginx;
worker_processes auto;
error_log logs/error.log;
pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" "$request_time" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$upstream_response_time"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
server_tokens off;
gzip on;
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_vary on;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_redirect off;
proxy_connect_timeout 300;
proxy_read_timeout 300;
proxy_send_timeout 300;
proxy_buffer_size 16k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 128k;
keepalive_timeout 65;
include vhost/*.conf;
#include deny.conf;
}



在nginx/conf/vhost文件夹下写具体的代理配置文件

启动停止

# 检查配置
/etc/init.d/openresty configtest
# 启动
/etc/init.d/openresty start
# 停止
/etc/init.d/openresty stop



日志切割脚本



#!/bin/bash
source /etc/profile
logs_path=/usr/local/openresty/nginx/logs
pid_file=${logs_path}/nginx.pid
year=$(date +"%Y")
month=$(date +"%m")
day=$(date +"%d")
#echo $year
#echo $month
#echo $day
nowdir=${logs_path}/${year}/${month}
mkdir -p $nowdir
cd $logs_path
for i in `ls *.log`
do
#echo $i
#echo "---"
#echo $year/$month/${year}${month}${day}_${i}
mv $i $year/$month/${year}${month}${day}_${i}
#echo "---"
done
#echo `cat ${pid_file}`
kill -USR1 `cat ${pid_file}`
cd $nowdir
if [ $? -eq 0 ];then
for j in `ls *.log`
do
tar zcvf $j.tar.gz $j && rm -f $j
done
fi



新增计划任务

chmod +x /usr/local/bin/cut_nginx_log
crontab -l
0 0 * * * /usr/local/bin/cut_nginx_log



发布于: 2020 年 05 月 17 日 阅读数: 47
用户头像

wong

关注

人生充满黑色幽默 2017.10.24 加入

一名工程师

评论

发布
暂无评论
OpenResty部署配置和日志切割