In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Log segmentation
1. Excessive log files in the enterprise server will cause the following problems:
1. Querying too large log files is very inconvenient for development and operation and maintenance, especially when overtime workers are very tired.
Log files from a long time ago are almost worthless, but manual cleaning is too cumbersome.
At this time, there is a need for a solution to automatically do log segmentation, the divided log is not only "clean", but also easy to achieve regular log cleaning.
Experiment
II. Compile and install Nginx service
1. Obtain the source code package on Windows remotely and mount it to Linux
[root@localhost] # smbclient-L / / 192.168.235.1Enter SAMBA\ root's password: Sharename Type Comment- LNMP Disk [root@localhost ~] # mkdir / abc [root@localhost ~] # mount.cifs / / 192.168.235.1/LNMP / abcPassword for root@//192.168.235.1/LNMP: [root @ localhost ~] # ls / abcDiscuz_X3.4_SC_UTF8.zip nginx-1.12.0.tar.gz php-7.1.10.tar.bz2mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.20.tar.gz
2. Decompress the package
[root@localhost ~] # cd / abc [root@localhost abc] # tar zxvf nginx-1.12.0.tar.gz-C / opt [root@localhost abc] # ls / optnginx-1.12.0 rh
3. Install the compiler package
[root@localhost abc] # cd / opt [root@localhost opt] # yum install-y\ > gcc\ / / C language > gcc-c++\ / / C++ language > pcre-devel\ / / pcre language tool > zlib-devel / / compressed function Library
4. Create program users and configure Nginx service-related components
[root@localhost opt] # useradd-M-s / sbin/nologin nginx// Creator user nginx And limit its non-login terminal [root@localhost opt] # cd nginx-1.12.0/ [root@localhost nginx-1.12.0] #. / configure\ / configure nginx >-- prefix=//usr/local/nginx\ / / specify installation path >-- user=nginx\ / / specify user name >-- group=nginx\ / / specify the group to which the user belongs >-- with- Http_stub_status_module// installation status Statistics Module
5. Compilation and installation
[root@localhost nginx-1.12.0] # make & & make install
6. Optimize the Nginx service startup script and establish command soft links
[root@localhost nginx-1.12.0] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ create nginx service command soft link to system command [root@localhost nginx-1.12.0] # systemctl stop firewalld.service / / turn off firewall [root@localhost nginx-1.12.0] # setenforce 0bat / turn off enhanced security function [root@localhost nginx-1.12.0] # nginx/ / input Nginx enables the service [root@localhost nginx-1.12.0] # netstat-ntap | grep 80 / / View port 80 of the service Shows that tcp 0 0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 01. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. master * LISTEN 7520/nginx:
7. Systemctl manages nginx scripts
[root@localhost ~] # vim / lib/systemd/system/nginx.service # # create a profile [Unit] Description=nginx # # describe After=network.target # # describe the service type [Service] Type=forking # # background running form PIDFile=/usr/local/nginx/logs/nginx.pid # # PID file location ExecStart=/usr/local/nginx/sbin/nginx # # start the service ExecReload=/usr/bin/kill-s HUP $MAINPID # # configure ExecStop=/usr/bin/kill-s QUIT $MAINPID # # according to PID overload to terminate the process PrivateTmp= true [install] WantedBy=multi-user.target [root@localhost ~] # chmod according to PID 754 / lib/systemd/system/nginx.service # # set execution permission [root@localhost ~] # systemctl stop nginx.service # # close nginx [root@localhost ~] # systemctl start nginx.service # # enable
8. Write a log segmentation script
[root@localhost nginx-1.12.0] # vim fenge.shengeqqqbinbinanybashroom Filenameza fengge.sh # # description information dong$ (date-d "- 1 day"+% Y%m%d") # # shows the time of the day before the system and generates a date string For example, "2019.11.11" logs_path= "/ var/log/nginx" # # pid_path= "/ usr/local/nginx/logs/nginx.pid" # # Nginx process number file [- d $logs_path] | | mkdir-p $logs_path # # determine whether there is a log partition storage path. If it does not exist, create the path mv / usr/local/nginx/logs/access.log ${logs_path} / test.com-access.log-$d## to generate the access log from the original path to the created path, and generate a log file named kill-USR1 $(cat $log) # # to end the previous process number It is used to generate a new process number find $logs_path-mtime + 30 | xargs rm-rf # # look for files under the path 30 days ago (excluding 30 days) and delete them Xargs is used to use the processing result of the previous command as the parameter of the command after the pipe symbol [root@localhost nginx-1.12.0] # chmod + x fenge.sh # # to grant the script execution permission [root@localhost nginx-1.12.0] #. / fenge.sh [root@localhost nginx-1.12.0] # ls / var/log/nginxtest.com-access.log-20191112 # # View the log partition file generated under the specified path [root@localhost nginx-1.12.0] # ls / usr/local/nginx/logsaccess.log error.log nginx.pid # # View the Nginx log directory It can be seen that another access.log log is automatically generated. This method greatly strengthens the management of enterprise server logs. Improve the efficiency!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.