温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-06-24 19:49:45 来源:网络 阅读:1126 作者:菜鸟点滴 栏目:建站服务器

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI