OpenResty 部署配置和日志切割
发布于: 2020 年 05 月 17 日
OpenResty以前都是手动编译安装,现在官方出的yum源的包编译的很好,就不用再手动编译了,直接用。
安装独立仓库
#centosyum install -y yum-utilsyum-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.confuser 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/bashsource /etc/profilelogs_path=/usr/local/openresty/nginx/logspid_file=${logs_path}/nginx.pidyear=$(date +"%Y")month=$(date +"%m")day=$(date +"%d")#echo $year#echo $month#echo $daynowdir=${logs_path}/${year}/${month}mkdir -p $nowdircd $logs_pathfor 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 $nowdirif [ $? -eq 0 ];then for j in `ls *.log` do tar zcvf $j.tar.gz $j && rm -f $j donefi
新增计划任务
chmod +x /usr/local/bin/cut_nginx_logcrontab -l0 0 * * * /usr/local/bin/cut_nginx_log
划线
评论
复制
发布于: 2020 年 05 月 17 日阅读数: 103
版权声明: 本文为 InfoQ 作者【wong】的原创文章。
原文链接:【http://xie.infoq.cn/article/7c5c662c3cd08522af5f1f48e】。
本文遵守【CC-BY 4.0】协议,转载请保留原文出处及本版权声明。
wong
关注
人生充满黑色幽默 2017.10.24 加入
一名工程师
评论