本文讲一下nginx 1.6.0的源码安装, 遇到一个bug, 开启openssl支持时, 因为make文件的问题, 导致make错误, 后面会有如何避免这个错误的方法, 需要修改nginx代码中openssl的conf文件.
编译环境 :
CentOS 6.x x64
依赖包大部分通过yum安装(除了google performance a tools,pcre和zlib, zlib通过nginx配置的makefile来安装).
安装依赖包.
安装google performance analysis tools的依赖包
# yum install -y libunwind-devel libunwind
安装google performance analysis tools
# wget https://googledrive.com/host/0B6NtGsLhIcf7MWxMMF9JdTN3UVk/gperftools-2.2.1.tar.gz
# tar -zxvf gperftools-2.2.1.tar.gz
# cd gperftools-2.2.1
# ./configure --prefix=/opt/gperftools-2.2.1
# make
# make install
# vi /etc/profile
export PATH=/opt/gperftools-2.2.1/bin:$PATH
export MANPATH=/opt/gperftools-2.2.1/share/man:$MANPATH
# vi /etc/ld.so.conf
/opt/gperftools-2.2.1/lib
# ldconfig
[root@db-172-16-3-150 ~]# ldconfig -p|grep gper
libtcmalloc_minimal_debug.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_minimal_debug.so.4
libtcmalloc_minimal_debug.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_minimal_debug.so
libtcmalloc_minimal.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_minimal.so.4
libtcmalloc_minimal.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_minimal.so
libtcmalloc_debug.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_debug.so.4
libtcmalloc_debug.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_debug.so
libtcmalloc_and_profiler.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_and_profiler.so.4
libtcmalloc_and_profiler.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc_and_profiler.so
libtcmalloc.so.4 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc.so.4
libtcmalloc.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libtcmalloc.so
libprofiler.so.0 (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libprofiler.so.0
libprofiler.so (libc6,x86-64) => /opt/gperftools-2.2.1/lib/libprofiler.so
手工安装的软件记得全部加到/etc/profile和/etc/ld.so.conf
安装nginx的依赖包, 其他依赖包系统已经安装了, 如果你编译时遇到缺少的lib库, 补上即可.
# yum install -y geoip-devel geoip libatomic_ops libatomic_ops-devel openssl openssl-devel gd gd-devel
查看openssl 相关的so文件, 因为nginx编译安装时加载openssl库有BUG, 需要修改编译文件.
[root@db-172-16-3-150 nginx-1.6.0]# rpm -ql openssl-devel|grep libssl
/usr/lib64/libssl.so
下载zlib源码
# cd /opt/soft_bak
# wget http://zlib.net/zlib-1.2.8.tar.gz
# tar -zxvf zlib-1.2.8.tar.gz
下载pcre源码.
# cd /opt/soft_bak
# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpcre%2Ffiles%2Fpcre%2F8.35%2F&ts=1405687477&use_mirror=jaist
# unzip pcre-8.35.zip
下载nginx最后的稳定版本.
# wget http://nginx.org/download/nginx-1.6.0.tar.gz
# tar -zxvf nginx-1.6.0.tar.gz
# cd nginx-1.6.0
有个BUG, 必须先修改编译文件, 如果不修改会有BUG, 导致无法安装.
# vi auto/lib/openssl/conf
*)
have=NGX_OPENSSL . auto/have
have=NGX_SSL . auto/have
CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
改成
*)
have=NGX_OPENSSL . auto/have
have=NGX_SSL . auto/have
CORE_INCS="$CORE_INCS /usr/include/openssl"
CORE_DEPS="$CORE_DEPS $CORE_INCS/ssl.h"
CORE_LIBS="$CORE_LIBS /usr/lib64/libssl.so"
CORE_LIBS="$CORE_LIBS /usr/lib64/libcrypto.so"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
另, pcre 编译项定制.
cd nginx-1.6.0
vi auto/lib/pcre/conf
if [ $PCRE_JIT = YES ]; then
have=NGX_HAVE_PCRE_JIT . auto/have
PCRE_CONF_OPT="$PCRE_CONF_OPT --enable-jit --enable-unicode-properties --enable-utf --enable-pcre16 --enable-pcre32"
fi
并不是使用with-pcre-opt
./configure --help
library sources DIR指源码目录, 例如, 需要pcre下载的源码.
--with-pcre=DIR set path to PCRE library sources
--with-pcre-opt=OPTIONS set additional build options for PCRE
指编译pcre的CFLAGS可选项.
[root@db-172-16-3-150 nginx-1.6.0]# grep -r with-pcre-opt *
auto/options: --with-pcre-opt=*) PCRE_OPT="$value" ;;
auto/options: --with-pcre-opt=OPTIONS set additional build options for PCRE
[root@db-172-16-3-150 nginx-1.6.0]# grep -r PCRE_OPT *
auto/lib/pcre/make: && CC="\$(CC)" CFLAGS="$PCRE_OPT" \\
安装所有的模块, 全部静态连接到sbin/nginx.
# ./configure --prefix=/opt/nginx1.6.0 --without-select_module --without-poll_module --with-file-aio --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-google_perftools_module --with-cpp_test_module --with-pcre=/opt/soft_bak/pcre-8.35 --with-pcre-jit --with-md5-asm --with-sha1-asm --with-zlib=/opt/soft_bak/zlib-1.2.8 --with-libatomic --with-openssl=/usr/lib64 --with-cc-opt=-I/opt/gperftools-2.2.1/include --with-ld-opt=-L/opt/gperftools-2.2.1/lib
Configuration summary
+ using PCRE library: /opt/soft_bak/pcre-8.35
+ using OpenSSL library: /usr/lib64
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using zlib library: /opt/soft_bak/zlib-1.2.8
+ using system libatomic_ops library
nginx path prefix: "/opt/nginx1.6.0"
nginx binary file: "/opt/nginx1.6.0/sbin/nginx"
nginx configuration prefix: "/opt/nginx1.6.0/conf"
nginx configuration file: "/opt/nginx1.6.0/conf/nginx.conf"
nginx pid file: "/opt/nginx1.6.0/logs/nginx.pid"
nginx error log file: "/opt/nginx1.6.0/logs/error.log"
nginx http access log file: "/opt/nginx1.6.0/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
# make
# make install
[root@db-172-16-3-150 conf]# cd /opt/nginx1.6.0
[root@db-172-16-3-150 nginx1.6.0]# ll
total 16
drwxr-xr-x 2 root root 4096 Jul 18 15:48 conf
drwxr-xr-x 2 root root 4096 Jul 18 15:48 html
drwxr-xr-x 2 root root 4096 Jul 18 15:48 logs
drwxr-xr-x 2 root root 4096 Jul 18 15:48 sbin
[root@db-172-16-3-150 nginx1.6.0]# cd conf/
[root@db-172-16-3-150 conf]# ll
total 60
-rw-r--r-- 1 root root 1034 Jul 18 15:48 fastcgi.conf
-rw-r--r-- 1 root root 1034 Jul 18 15:48 fastcgi.conf.default
-rw-r--r-- 1 root root 964 Jul 18 15:48 fastcgi_params
-rw-r--r-- 1 root root 964 Jul 18 15:48 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Jul 18 15:48 koi-utf
-rw-r--r-- 1 root root 2223 Jul 18 15:48 koi-win
-rw-r--r-- 1 root root 3957 Jul 18 15:48 mime.types
-rw-r--r-- 1 root root 3957 Jul 18 15:48 mime.types.default
-rw-r--r-- 1 root root 2656 Jul 18 15:48 nginx.conf
-rw-r--r-- 1 root root 2656 Jul 18 15:48 nginx.conf.default
-rw-r--r-- 1 root root 596 Jul 18 15:48 scgi_params
-rw-r--r-- 1 root root 596 Jul 18 15:48 scgi_params.default
-rw-r--r-- 1 root root 623 Jul 18 15:48 uwsgi_params
-rw-r--r-- 1 root root 623 Jul 18 15:48 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Jul 18 15:48 win-utf
# vi /etc/profile
export PATH=/opt/nginx1.6.0/sbin:/opt/gperftools-2.2.1/bin:$PATH
[root@db-172-16-3-150 ~]# which nginx
/opt/nginx1.6.0/sbin/nginx
[其他]
1. 使用自编译的perl.
http://www.perl.org/get.html#unix_like
# wget http://www.cpan.org/src/5.0/perl-5.20.0.tar.gz
# tar -xzf perl-5.20.0.tar.gz
# cd perl-5.20.0
# ./Configure --help
Usage: Configure [-dehrsEKOSV] [-f config.sh] [-D symbol] [-D symbol=value]
[-U symbol] [-U symbol=] [-A command:symbol...]
-d : use defaults for all answers.
-e : go on without questioning past the production of config.sh.
-f : specify an alternate default configuration file.
-h : print this help message and exit (with an error status).
-r : reuse C symbols value if possible (skips costly nm extraction).
-s : silent mode, only echoes questions and essential information.
-D : define symbol to have some value:
-D symbol symbol gets the value 'define'
-D symbol=value symbol gets the value 'value'
common used examples (see INSTALL for more info):
-Duse64bitint use 64bit integers
-Duse64bitall use 64bit integers and pointers
-Dusethreads use thread support
-Dinc_version_list=none do not include older perl trees in @INC
-DEBUGGING=none DEBUGGING options
-Dcc=gcc choose your compiler
-Dprefix=/opt/perl5 choose your destination
-E : stop at the end of questions, after having produced config.sh.
-K : do not use unless you know what you are doing.
-O : let -D and -U override definitions from loaded configuration file.
-S : perform variable substitutions on all .SH files (can mix with -f)
-U : undefine symbol:
-U symbol symbol gets the value 'undef'
-U symbol= symbol gets completely empty
e.g.: -Uversiononly
-A : manipulate symbol after the platform specific hints have been applied:
-A append:symbol=value append value to symbol
-A symbol=value like append:, but with a separating space
-A define:symbol=value define symbol to have value
-A clear:symbol define symbol to be ''
-A define:symbol define symbol to be 'define'
-A eval:symbol=value define symbol to be eval of value
-A prepend:symbol=value prepend value to symbol
-A undef:symbol define symbol to be 'undef'
-A undef:symbol= define symbol to be ''
e.g.: -A prepend:libswanted='cl pthread '
-A ccflags=-DSOME_MACRO
-V : print version number and exit (with a zero status).
# ./Configure -des -Dprefix=/opt/perl5.20.0
# make && make test
# make install
# vi /etc/profile
export PATH=/opt/perl5.20.0/bin:/opt/pcre-8.35/bin:$PATH
export MANPATH=/opt/perl5.20.0/man:/opt/pcre-8.35/share/man:$MANPATH
[root@dba ~]# which perl
/opt/perl5.20.0/bin/perl
配置项.
./configure --prefix=/opt/nginx1.6.0 --without-select_module --without-poll_module --with-file-aio --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-google_perftools_module --with-cpp_test_module --with-pcre=/opt/soft_bak/pcre-8.35 --with-pcre-jit --with-md5-asm --with-sha1-asm --with-zlib=/opt/soft_bak/zlib-1.2.8 --with-libatomic --with-openssl=/usr/lib64 --with-cc-opt=-I/opt/gperftools-2.2.1/include --with-ld-opt=-L/opt/gperftools-2.2.1/lib --with-perl=/opt/perl5.20.0/bin/perl
2. 如果要添加外部的模块, 编译时使用选项 :
--add-module=PATH enable an external module
3. 不建议使用--with-select_module和--with-poll_module.
在系统不支持更好的方法如kqueue, epool, rtsig或/dev/poll时会自动enable.
--with-select_module
--without-select_module — enables or disables building a module that allows the server to work with the select() method. This module is built automatically if the platform does not appear to support more appropriate methods such as kqueue, epoll, rtsig, or /dev/poll.
--with-poll_module
--without-poll_module — enables or disables building a module that allows the server to work with the poll() method. This module is built automatically if the platform does not appear to support more appropriate methods such as kqueue, epoll, rtsig, or /dev/poll.
--with-rtsig_module enable rtsig module
Linux下有效的方法是epoll.
epoll — efficient method used on Linux 2.6+.
参见
http://nginx.org/en/docs/events.html
[参考]1. http://nginx.org/en/download.html
2. http://nginx.org/en/docs/configure.html
3. http://nginx.org/en/docs/events.html