Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Log Segmentation optimized by Nginx

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Nginx optimized Log Segmentation installation configuration Nginx

Mount the remote source package locally

Mount.cifs / / 192.168.100.10/LNMP-C7 / mnt / / Mount to / mnt directory

Decompress the source code package to / opt directory

[root@localhost ~] # cd / abc / / switch to the mount point directory [root@localhost abc] # lsDiscuz_X3.4_SC_UTF8.zip nginx-1.12.2.tar.gzmysql-boost-5.7.20.tar.gz php-7.1.10.tar.gz [root@localhost abc] # tar zxvf nginx-1.12.2.tar.gz -C / opt/ / decompress the Nginx source code package to [root@localhost abc] # cd / opt/ under / opt and switch to [root@localhost opt] # lsnginx-1.12.2 rh under the decompressed directory

Install the environment package required for compilation

[root@localhost opt] # yum-y install\ gcc\ / / c language gcc-c++\ / / C++ language pcre-devel\ / / pcre language tool zlib-devel / / function library for data compression

Create a user named nginx and compile Nginx

[root@localhost opt] # useradd-M-s / sbin/nologin nginx / / Creator user Limit its [root@localhost opt] # cd nginx-1.12.2/ switch to [root@localhost nginx-1.12.2] # / configure\ / / configure nginx >-- prefix=/usr/local/nginx\ / / installation path under the nginx directory >-- user=nginx\ / / user name >-- group=nginx\ / / user group >-- with-http_stub_status_module / / access status statistics module

Compile and install

[root@localhost nginx-1.12.0] # make & & make install / / compilation and installation

Make Nginx management script, easy to manage and use

[root@localhost nginx] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ create a soft connection [root@nginx nginx-1. 12.2] # vim / etc/init.d/nginx / / Edit startup script #! / bin/bash# chkconfig:-99 2 starting description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" PIDF= "/ usr/local/nginx/logs/nginx.pid" case "$1" in start) $PROG ; stop) kill-s QUIT $(cat $PIDF);; restart) $0 stop $0 start;; reload) kill-s HUP $(cat $PIDF) *) echo "Usage: $0 {start | stop | restart | reload}" exit 1 esac exit 0 [root@nginx nginx-1.12.2] # chmod + x / etc/init.d/nginx / / give script execution permission [root@nginx nginx-1.12.2] # chkconfig-- add nginx / / add to service Manager [root@nginx nginx-] 1.12.2] # yum install elinks-y / / [root@nginx nginx-1.12.2] # service nginx start / / start the Nginx service [root@nginx nginx-1.12.2] # netstat-ntap | grep 80tcp 00 0.0.0.0 service nginx start 80 0.0.0.0 service nginx start * LISTEN 42028 / nginx: master [root@nginx nginx-1.12.2] # systemctl stop firewalld.service / / turn off the firewall [root@nginx nginx-1.12.2] # setenforce 0 / / turn off enhanced security features [root@nginx nginx-1.12.2] # elinks http://192.168.131.133/ Write a script for log segmentation [root@localhost ~] # vim fenge.sh / / write a script file #! / bin/bash#Filename:fenge.shd=$ (date-d "- 1 day"+% Y%m%d") / / display the time one day ago logs_path= "/ var/log/nginx" / / the path to split the log pid_path= "/ usr/local/nginx/logs/nginx.pid" / / pid [- d $logs_path] | | mkdir-p $logs_path / / create a directory mv / usr/local/nginx/logs/access.log ${logs if there is no directory _ path} / test.com-access.log-$d// the original log file is generated to the new path kill-USR1 $(cat $pid_path) / / ends the regeneration of the new pid file find $logs_path-mtime + 30 | xargs rm-rf / / deletes the log file from 30 days ago [root@localhost ~] # chmod + x fenge.sh / / gives execution permission [root@localhost ~ ] #. / fenge.sh / / execute script file

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report