菜鸟运维笔记:小记编译安装Nginx所遇到的坑
2014-11-10 09:08
453 查看
目录(?)[+]
不管是CentOS,或是Debian/Ubuntu,甚至是Windows。Nginx都有已编译好的安装包可用。通常只需要在终端上潇洒地输入
官网已经出现了1.7了。不过我还是选择了目前稳定的1.6版本。打开你的终端,我们开始吧:
进入刚才解压的目录下。你会发现,没有其他软件的源码中所包含的INSTALL文件(该文件通常用于指导如何正确编译源码),有一个README,来我们
文档在这个网站上。。。
不过不用管他了,看到目录下绿色的configure文件在,那么我们直接上手吧。
然后,你可能会收到一个错误,提示你缺少PCRE。不过,如果你之前已经在这台主机上成功安装了Apache的话,那么现在是不会报错的,因为Apache也是需要PCRE的。(我的是新搞的华为云的主机,几乎裸机)
PCRE是什么呢?简单说来,就是一个Perl的库。那么我们接下来来编译pcre的源码。哈哈。
到官网去看,当前(截至2014/11/09)最新版本是8.36。
接下来,同样是用
貌似没出错,接着
是我没装libtool么,
你应该是
然后我们再重新
继续
来我
接着,我们再进入pcre的目录下面,去configure。加上一个选项。
注意选项后面应该是,你自己的zlib目录的路径。You Know?
此时,应该不报错了,我们来一路高歌猛进,继续敲两个命令,——————>
好了,没错误安装pcre完毕。深呼一口气,恩,费力不少啊,不过终于安装上了,好吧,教程结束。
咦?慢着,我们的教程不是教你安装pcre的啊。我们是Nginx安装教程啊。那好吧,继续。
在pcre安装完毕之后,再次进入nginx的目录下面,去
轻轻敲下四个字母
滚屏完毕,继续敲
前文之中,我们已经安装好了Nginx,现在我们去开启它。因为刚才nginx源码目录下,我们在configure的时候,没有使用选项
我们可以
在安装目录下的sbin子目录中有Nginx的可执行文件。不过,很不幸,我的机器上,又报错了:
提示缺少libpcre.so.1,但是我们刚才明明装了pcre啊。原来是Nginx默认在/lib64/目录下(我是64位机器,32位应该是搜索/lib/),搜索该库文件。显然,我们自己编译的pcre,它的这个库文件不在这个位置。来我们
好吧,在/usr/local/lib/下面。我们来建立以符号链接吧。
然后,这次应该真得可以了。。。开启nginx:
好了,打完收工。
前言
不管是CentOS,或是Debian/Ubuntu,甚至是Windows。Nginx都有已编译好的安装包可用。通常只需要在终端上潇洒地输入apt-get install ...或是
yum install ..就可以了。但是对于我这个
源码编译狂来说,那样一键安装,显然无法满足我心理需求。
获取Nginx源码
下载
官网已经出现了1.7了。不过我还是选择了目前稳定的1.6版本。打开你的终端,我们开始吧:<code class="hljs nginx" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-title" style="color: rgb(249, 38, 114); margin-top: 0px !important;">wget</span> <span class="hljs-url">http://nginx.org/download/nginx-1.6.2.tar.gz</span> </code>
解压
<code class="hljs nginx" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-title" style="color: rgb(249, 38, 114); margin-top: 0px !important;">tar</span> xvf nginx-<span class="hljs-number" style="color: rgb(174, 129, 255);">1</span>.<span class="hljs-number" style="color: rgb(174, 129, 255);">6</span>.<span class="hljs-number" style="color: rgb(174, 129, 255);">2</span>.tar.gz </code>
编译
进入刚才解压的目录下。你会发现,没有其他软件的源码中所包含的INSTALL文件(该文件通常用于指导如何正确编译源码),有一个README,来我们cat一下。!坑爹啊,里面只有一句话!
<code class="hljs cs" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;">Documentation <span class="hljs-keyword" style="color: rgb(249, 38, 114); margin-top: 0px !important;">is</span> available at http:<span class="hljs-comment" style="color: rgb(117, 113, 94);">//nginx.org</span> </code>
文档在这个网站上。。。
不过不用管他了,看到目录下绿色的configure文件在,那么我们直接上手吧。
configure
<code style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0px; color: inherit; background-color: transparent; margin-top: 0px !important;">./configure </code>
然后,你可能会收到一个错误,提示你缺少PCRE。不过,如果你之前已经在这台主机上成功安装了Apache的话,那么现在是不会报错的,因为Apache也是需要PCRE的。(我的是新搞的华为云的主机,几乎裸机)
安装PCRE
PCRE是什么呢?简单说来,就是一个Perl的库。那么我们接下来来编译pcre的源码。哈哈。到官网去看,当前(截至2014/11/09)最新版本是8.36。
<code class="hljs ruby" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;">wget <span class="hljs-symbol" style="color: rgb(249, 38, 114); margin-top: 0px !important;">ftp:</span>/<span class="hljs-regexp" style="color: rgb(174, 129, 255);">/ftp.csx.cam.ac.uk/pub</span><span class="hljs-regexp" style="color: rgb(174, 129, 255);">/software/programming</span><span class="hljs-regexp" style="color: rgb(174, 129, 255);">/pcre/pcre</span>-<span class="hljs-number" style="color: rgb(174, 129, 255);">8.36</span>.tar.gz </code>
-DH***E_CONFIG_H
接下来,同样是用tar xvf解压。解压出一个pcre的目录,我们
cd进去。不由分说,直接
./configure。
貌似没出错,接着
make,貌似也没出问题,继续
make install。咦,有错误!
<code class="hljs http" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-attribute" style="color: rgb(249, 38, 114); margin-top: 0px !important;">libtool</span>: <span class="hljs-string" style="color: rgb(230, 219, 116);">compile: unrecognized option `-DH***E_CONFIG_H' </span> </code>
是我没装libtool么,
yum install一下。不对啊,装了啊。后来百度发现是缺少了g++编译器。对哦,我现在是裸机。这个我就不自己编译了(快跑题了),敲命令安装:
<code class="hljs nginx" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-comment" style="color: rgb(117, 113, 94); margin-top: 0px !important;">#CentOS下面</span> <span class="hljs-title" style="color: rgb(249, 38, 114);">yum</span> install gcc-c++ <span class="hljs-comment" style="color: rgb(117, 113, 94);">#Ubuntu下面</span> apt-get install g++ </code>
你应该是
root身份,我就不多说了。此时会默认安装一些依赖软件,比如autoconf。
zlib
然后我们再重新./configure一下吧,瓦擦嘞,有问题(装完g++,configure都报错了。。),提示缺少zlib。好吧,继续百度,进官网。复制链接,然后继续
wget。
<code class="hljs nginx" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-title" style="color: rgb(249, 38, 114); margin-top: 0px !important;">wget</span> <span class="hljs-url">http://zlib.net/zlib-1.2.8.tar.gz</span> </code>
继续
tar xvfo(╯□╰)o解压出一个目录。我这里目录名是zlib-1.2.8。请注意我所有wget的文件都在同一层目录下面,解压路径也是同一层。
来我
ls -F一下:
<code style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0px; color: inherit; background-color: transparent; margin-top: 0px !important;">nginx-1.6.2/ pcre-8.36/ zlib-1.2.8/ nginx-1.6.2.tar.gz pcre-8.36.tar.gz zlib-1.2.8.tar.gz </code>
接着,我们再进入pcre的目录下面,去configure。加上一个选项。
<code class="hljs sql" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;">./configure <span class="hljs-comment" style="color: rgb(117, 113, 94); margin-top: 0px !important;">--with-zlib=../zlib-1.2.8</span> </code>
注意选项后面应该是,你自己的zlib目录的路径。You Know?
此时,应该不报错了,我们来一路高歌猛进,继续敲两个命令,——————>
make——————>
make install。
好了,没错误安装pcre完毕。深呼一口气,恩,费力不少啊,不过终于安装上了,好吧,教程结束。
咦?慢着,我们的教程不是教你安装pcre的啊。我们是Nginx安装教程啊。那好吧,继续。
make
在pcre安装完毕之后,再次进入nginx的目录下面,去./configure应该不会报错了。
轻轻敲下四个字母
make。接着观看滚屏。
make install
滚屏完毕,继续敲make install。然后继续看滚屏。。
开启Nginx
前文之中,我们已经安装好了Nginx,现在我们去开启它。因为刚才nginx源码目录下,我们在configure的时候,没有使用选项--prefix(该选项用来指定nginx的安装位置),所以它默认安装到了/usr/local/nginx/目录中。
我们可以
cd进去,也可以不进去。下面开启它:
<code class="hljs perl" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;">/usr/<span class="hljs-keyword" style="color: rgb(249, 38, 114); margin-top: 0px !important;">local</span>/nginx/sbin/nginx </code>
在安装目录下的sbin子目录中有Nginx的可执行文件。不过,很不幸,我的机器上,又报错了:
<code class="hljs perl" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;"> error <span class="hljs-keyword" style="color: rgb(249, 38, 114); margin-top: 0px !important;">while</span> loading shared libraries: libpcre.so.<span class="hljs-number" style="color: rgb(174, 129, 255);">1</span>: cannot <span class="hljs-keyword" style="color: rgb(249, 38, 114);">open</span> shared object file: No such file <span class="hljs-keyword" style="color: rgb(249, 38, 114);">or</span> directory </code>
提示缺少libpcre.so.1,但是我们刚才明明装了pcre啊。原来是Nginx默认在/lib64/目录下(我是64位机器,32位应该是搜索/lib/),搜索该库文件。显然,我们自己编译的pcre,它的这个库文件不在这个位置。来我们
find / -name 'libpcre.so.1'一下,找找看:
<code class="hljs perl" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;">/usr/<span class="hljs-keyword" style="color: rgb(249, 38, 114); margin-top: 0px !important;">local</span>/lib/libpcre.so.<span class="hljs-number" style="color: rgb(174, 129, 255);">1</span> </code>
好吧,在/usr/local/lib/下面。我们来建立以符号链接吧。
<code class="hljs nginx" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-title" style="color: rgb(249, 38, 114); margin-top: 0px !important;">ln</span> -s /usr/local/lib/libpcre.so.<span class="hljs-number" style="color: rgb(174, 129, 255);">1</span> /lib64/libpcre.so.<span class="hljs-number" style="color: rgb(174, 129, 255);">1</span> </code>
然后,这次应该真得可以了。。。开启nginx:
/usr/local/nginx/sbin/nginx。没报错,那我们来检测一下,看谁在监听80端口。
<code class="hljs nginx" style="font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; padding: 0.5em; color: rgb(248, 248, 242); display: block; background-color: rgb(35, 36, 31); margin-top: 0px !important; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-title" style="color: rgb(249, 38, 114); margin-top: 0px !important;">netstat</span> -lpn|grep :<span class="hljs-number" style="color: rgb(174, 129, 255);">80</span> tcp <span class="hljs-number" style="color: rgb(174, 129, 255);">0</span> <span class="hljs-number" style="color: rgb(174, 129, 255);">0</span> <span class="hljs-number" style="color: rgb(174, 129, 255);">0.0.0.0:80</span> <span class="hljs-number" style="color: rgb(174, 129, 255);">0.0.0.0</span>:* LISTEN <span class="hljs-number" style="color: rgb(174, 129, 255);">28126</span>/nginx </code>
好了,打完收工。
相关文章推荐
- 菜鸟运维笔记:小记编译安装Nginx所遇到的坑
- 菜鸟运维笔记:小记编译安装Nginx所遇到的坑
- 菜鸟学Linux 第059篇笔记 编译安装MySQL,PHP 压力测试
- 菜鸟运维笔记:安装与配置Apache服务器
- nginx 学习笔记(一)nginx 编译安装
- nginx学习笔记之一:nginx介绍及其编译安装
- CentOS7 编译安装 Nginx (实测 笔记 Centos 7.0 + nginx1.6)
- 【nginx运维基础(1)】Nginx的编译安装与使用
- nginx 学习笔记(一)nginx 编译安装
- 菜鸟运维笔记:安装MySQL,PHP及phpMyAdmin
- 菜鸟运维笔记:安装与配置Apacheserver
- Nginx运维笔记1 - 安装与配置
- Nginx笔记一:Nginx简介、安装、编译优化、启动、平滑升级
- nginx 学习笔记(一)nginx 编译安装
- nginx 学习笔记(一)nginx 编译安装
- Dlib机器学习笔记1 -- Windows下的编译安装调试(超详细,菜鸟也成功)
- Ubuntu 14 编译安装 PHP 5.4.45 + Nginx 1.4.7 + MySQL 5.6.26 笔记
- Centos7 编译安装 Nginx PHP Mariadb Memcached 扩展 ZendOpcache扩展 (实测 笔记 Centos 7.0 + Mariadb 10.1.9 + Nginx 1.9.9 + PHP 7.0.2)
- centos 6.5下编译安装、配置高性能服务器Nginx(安装笔记)
- nginx 学习笔记(一)nginx 编译安装