美文网首页
nginx的编译安装

nginx的编译安装

作者: 任总 | 来源:发表于2018-07-25 00:57 被阅读9次
  • 前言:编译安装分为两种:源码包编译安装和src的rpm包安装,由于源码编译安装依赖问题和需要辅助模块较多,所以在实际应用中尽量使用src的rpm安装方法。

一、编译安装:

前提:开发环境,包括nginx编译要启用的功能依赖到的开发库;

[root@vs-110 ~]# yum groupinstall "Development Tools" "Server Platform Development"#安装编译需要的包组
[root@vs-110 ~]# yum -y pcre-devel openssl-devel#安装模块

编译过程:

[root@vs-110 ~]# wget http://nginx.org/download/nginx-1.10.3.tar.gz #下载nginx源码

[root@vs-110 ~]# tar xf nginx-1.10.3.tar.gz

[root@vs-110 ~]# cd nginx-1.10.3

[root@vs-110 nginx-1.10.3 ~]# ./configure –help 查询支持信息

[root@vs-110 nginx-1.10.3 ~]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-threads --with-file-aio#预编译

[root@vs-110 nginx-1.10.3 ~]# make&& make install#编译并安装

编译错误解决方法:https://blog.csdn.net/counsellor/article/details/60758096

  • epel仓库中的Nginx的configure脚本参数
# ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

Epel仓库中的Nginx的unlt file:(启动配置文件)

[root@vs-110 ~]# cat /usr/lib/systemd/system/nginx.service

[Unit]

Description=The nginx HTTP and reverse proxy server描述

After=network.target remote-fs.target nss-lookup.target启动那些才行

[Service]

Type=forking

PIDFile=/run/nginx.pid

# Nginx will fail to start if /run/nginx.pid already exists but has the wrong

# SELinux context. This might happen when running `nginx -t` from the cmdline.

# https://bugzilla.redhat.com/show_bug.cgi?id=1268621

ExecStartPre=/usr/bin/rm -f /run/nginx.pid

ExecStartPre=/usr/sbin/nginx -t

ExecStart=/usr/sbin/nginx

ExecReload=/bin/kill -s HUP $MAINPID主控进程

KillSignal=SIGQUIT

TimeoutStopSec=5

KillMode=process

PrivateTmp=true

[Install]

WantedBy=multi-user.target

(https://www.nginx.com/resources/wiki/modules/) Nginx第三方模块下载地址

二、SRC格式的Rpm的源码包安装

[root@vs-110 ~]# wget[http://nginx.org/packages/centos/7/SRPMS/nginx-1.12.1-1.el7.ngx.src.rpm](http://nginx.org/packages/centos/7/SRPMS/nginx-1.12.1-1.el7.ngx.src.rpm) #下载src格式的源码包

[root@vs-110 ~]# useradd builder #添加builder用户
 [root@vs-110 ~]# yum install  rpmdevtools  tree #安装rpm工具
[root@vs-110 ~]# rpmdev-setuptree #生成目录

[root@vs-110 ~]# ls

Rpmbuild #会多出来一个rpmbuild用户目录
[root@vs-110 ~]# tree rpmbuild/

rpmbuild/

├── SOURCES

│?? ├── COPYRIGHT

│?? ├── logrotate

│?? ├── nginx-1.12.1.tar.gz

│?? ├── nginx.check-reload.sh

│?? ├── nginx.conf

│?? ├── nginx-debug.service

│?? ├── nginx-debug.sysconf

│?? ├── nginx.init.in

│?? ├── nginx.service

│?? ├── nginx.suse.logrotate

│?? ├── nginx.sysconf

│?? ├── nginx.upgrade.sh

│?? └── nginx.vh.default.conf

└── SPECS

└── nginx.spec

2 directories, 14 files

[root@vs-110 ~]# cd rpmbuild/SPECS

[root@vs-110 SPECS]# ls

nginx.spec

[root@vs-110 SPECS]# vim nginx.spec #编辑安装配置文件
编辑配置文件

模块不用的就删掉例如with mail

[root@vs-110 SPECS]# rpmbuild –bb nginx.spec #编译成rpm包

[root@vs-110 ~]# tree rpmbuild/
生成的可安装的rpm包
[root@vs-110 ~]# cd rpmbuild/RPMS/x86_64/

[root@vs-110 x86_64]# yum -y install nginx-1.12.1-1.el7.centos.ngx.x86_64.rpm#安装

相关文章

网友评论

      本文标题:nginx的编译安装

      本文链接:https://www.haomeiwen.com/subject/pheumftx.html