码迷,mamicode.com
首页 > 其他好文 > 详细

centos7下编译安装nginx并实现日志轮替

时间:2017-07-20 22:10:46      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:centos7 nginx 编译安装 日志分割

centos7编译安装nginx:

  首先确保系统上存在编译安装使用的必要工具运行:

 # yum groupinstall "development tools" "server platform development"

    1 下载PCRE version 4.4 — 8.40 (ngx_http_rewrite_module模块需要)   

   # wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz

    2 下载zlib ( ngx_http_gzip_module模块需要)

   # wget https://zlib.net/zlib-1.2.11.tar.gz

    3 下载openssl (http_ssl_module模需要)

   # wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_0f.tar.gz

    3 下载nginx   

   # wget https://nginx.org/download/nginx-1.12.1.tar.gz


正式开工:

  1 解压PCRE

  # tar xzvf pcre-8.40.tar.gz -C /usr/local/src/

  2 解压zlib     

  # tar xzf zlib-1.2.11.tar.gz -C /usr/local/src/

  3 解压openssl

  # tar xzf OpenSSL_1_1_0f.tar.gz -C /usr/local/src/

  4 安装nginx

    添加nginx用户:

  # groupadd nginx
  # useradd -g nginx -s /sbin/nologin nginx

    创建nginx日志保存目录

  # mkdir /var/log/nginx

    解压安装包

  # tar xzf nginx-1.12.1.tar.gz
  # cd nginx-1.12.1
  # ./configure --prefix=/usr/local/nginx     --conf-path=/etc/nginx/nginx.conf     --pid-path=/var/log/nginx/run/nginx.pid     --error-log-path=/var/log/nginx/error.log     --http-log-path=/var/log/nginx/access.log     --user=nginx --group=nginx     --with-select_module     --with-poll_module     --with-http_ssl_module     --with-pcre=/usr/local/src/pcre-8.40     --with-zlib=/usr/local/src/zlib-1.2.11     --with-openssl=/usr/local/src/openssl-OpenSSL_1_1_0f
  # make && make install

    此时,nginx已经安装完成,可以去/usr/local/nginx/sbin/下,通过运行 ./nginx 命令来启动nginx

  5 配置NGINX systemd service (注意:根据自己配置,配置路径信息!)  

  #vim /lib/systemd/system/nginx.service
   [Unit]
   Description=The NGINX HTTP and reverse proxy server
   After=syslog.target network.target remote-fs.target nss-lookup.target
   [Service]
   Type=forking
   PIDFile=/var/log/nginx/run/nginx.pid
   ExecStartPre=/usr/local/nginx/sbin/nginx -t
   ExecStart=/usr/local/nginx/sbin/nginx
   ExecReload=/bin/kill -s HUP $MAINPID
   ExecStop=/bin/kill -s QUIT $MAINPID
   PrivateTmp=true
   [Install]
   WantedBy=multi-user.target

  此时

   启动nginx

  #systemctl start nginx

   查看状态

  # systemctl status nginx

   停止nginx

  # systemctl stop nginx

  6 编译安装的nginx不会做日志分割

   #vim logrotate.sh
     #!/bin/bash
     cd /var/log/nginx
     mv access.log access.log.$(date +%F)
     mv error.log error.log.$(date +%F)
     kill -USR1 $(cat /var/log/nginx/run/nginx.pid)
     sleep 1
     gzip access.log.$(date +%F)
     gzip error.log.$(date +%F)

    通过crontab实现定时日志轮替。


若以上内容,有什么问题,请指正。

谢谢!


参考链接 https://nginx.org/en/docs/configure.html

centos7下编译安装nginx并实现日志轮替

标签:centos7 nginx 编译安装 日志分割

原文地址:http://rogerwang.blog.51cto.com/5326353/1949424

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!