实战Linux CentOS7 安装LNMP环境架构过程之编译nginx

来源:互联网 发布:淘宝卖的电工证真的吗 编辑:程序博客网 时间:2024/06/06 05:23

首先 安装Development Tools工具包,这个工具包包括了GCC/GUN….等编译器和库,方便以后编译nginx,命令如下

yum groupinstall "Development Tools"

其中 groupinstall 是安装多个软件包

安装好后 开始安装nginx 打开官网http://www.nginx.org/ 选择Stable version 稳定版 复制下载链接之后 执行以下命令

wget http://nginx.org/download/nginx-1.10.2.tar.gz

我是先进入/home/jiaruo/Downloads/目录之后 在进行wget下载的,把nginx包下载到/home/jiaruo/Downloads/这个目录 wget是个下载工具 支持http https ftp 这三种协议下载
执行ls 命令 查看包是否下载完毕

[root@localhost Downloads]# lsnginx-1.10.2.tar.gz[root@localhost Downloads]# 

nginx-1.10.2.tar.gz就是包的名称,下面来解压包 ,命令如下

tar xvf nginx-1.10.2.tar.gz
解压命令自行百度,我也不太会,执行ls命令查看解压后的文件夹
[root@localhost Downloads]# lsnginx-1.10.2  nginx-1.10.2.tar.gz[root@localhost Downloads]# 

进入文件夹 并且查看文件

[root@localhost Downloads]# cd nginx-1.10.2[root@localhost nginx-1.10.2]# lsauto     CHANGES.ru  configure  html     man     srcCHANGES  conf        contrib    LICENSE  README[root@localhost nginx-1.10.2]# 

我们看到其中有configure这个文件,configure脚本配置工具就是基础之一,具体的自行百度,我们先来编译,命令如下

./configure --prefix=/usr/local/nginx
然后会滚动一大堆不想看的英文字母,我掐指一算,绝对会有error出来…..果真给我面子
./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using --without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using --with-pcre= option.
大概的意思就是 缺少PCRE模块 ,你可以禁止也可以安装,咋安装,不会 百度,的出来结果 去ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 这里下载,好吧 ,那我就下载,我们回到上级目录 就是/home/jiaruo/Downloads/目录 然后执行命令
  wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz

下载完毕之后ls 查看文件是否存在 如果不存在 请重换资源下载 如果还不轻,请拿起你的砖头砸电脑
我这里下载完毕 pcre-8.38.tar.gz 执行解压命令

tar xvf pcre-8.38.tar.gz 
执行ls命令可以看出多了个pcre开头的文件夹 我们进入文件夹内进行编译
./configure --prefix=/usr/local/pcre

编译完毕 执行 make && make install 命令,configure会在你的系统上测试存在的特性,make是编译的意思, make install是安装的意思,意思当make没出错的时候 就执行安装

make && make install
好了,安装完毕之后我们返回上一级 进入nginx的文件夹,然后继续编译,在上次测试的时候告诉我们了 缺少pcre模块 如果安装的话使用 –with-pcre=目录 进行安装,这个目录是指源码目录 不是安装目录,我在这个坑里待了2天,执行以下命令
./configure --prefix=/usr/local/nginx --with-pcre=/home/jiaruo/Downloads/pcre2-10.20

./configure –prefix=你要安装在哪里 –with-pcre=pcre解压出来的目录
完事之后 尼玛又报错

./configure: error: the HTTP gzip module requires the zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib= option.

缺少gzip模块,我在装一次 和pcre一样
找gzip的下载目录,找不到 然后百度得出结果http://www.zlib.net/zlib-1.2.8.tar.gz
继续回到下载文件存档的目录,下载完毕执行解压,还需要我重复么,重复一次吧

tar xvf zlib-1.2.8.tar.gz

解压后 会得到zlib-1.2.8 文件夹,进入 然后编译

./configure --prefix=/usr/local/zlib
编译完成 继续进入nginx文件夹 然后测试 苦逼啊
./configure --prefix=/usr/local/nginx \> --with-pcre=/home/jiaruo/Downloads/pcre2-10.20 \> --with-zlib=/home/jiaruo/Downloads/zlib-1.2.8

老天保佑,在出错我就不装了


Configuration summary  + using PCRE library: /home/jiaruo/Downloads/pcre2-10.20  + OpenSSL library is not used  + using builtin md5 code  + sha1 library is not found  + using zlib library: /home/jiaruo/Downloads/zlib-1.2.8  nginx path prefix: "/usr/local/nginx"  nginx binary file: "/usr/local/nginx/sbin/nginx"  nginx modules path: "/usr/local/nginx/modules"  nginx configuration prefix: "/usr/local/nginx/conf"  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"  nginx pid file: "/usr/local/nginx/logs/nginx.pid"  nginx error log file: "/usr/local/nginx/logs/error.log"  nginx http access log file: "/usr/local/nginx/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
………出先错误
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I /home/jiaruo/Downloads/pcre2-10.20 -I /home/jiaruo/Downloads/zlib-1.2.8 -I objs \        -o objs/src/core/nginx.o \        src/core/nginx.cIn file included from src/core/ngx_core.h:72,                 from src/core/nginx.c:9:src/core/ngx_regex.h:15:18: error: pcre.h: No such file or directoryIn file included from src/core/ngx_core.h:72,                 from src/core/nginx.c:9:src/core/ngx_regex.h:24: error: expected specifier-qualifier-list before ‘pcre’make[1]: *** [objs/src/core/nginx.o] Error 1make[1]: Leaving directory `/home/jiaruo/Downloads/nginx-1.10.2'make: *** [build] Error 2
然后请教了下冯立松大神,发现是之前pcre版本问题 之前装的是pcre2 已更正 然后 在重复pcre编译之后 在进到nginx 下面执行
./configure --prefix=/usr/local/nginx \    --with-pcre=/home/jiaruo/Downloads/pcre-8.38 \    --with-zlib=/home/jiaruo/Downloads/zlib-1.2.8

没错误 然后继续 编译 安装

make && make install
没发现错误,然后试试安装成功 进入目录试试
cd /usr/local/nginx/ 

顺利进来 ls一下 发现有个conf 顾名思义 里面放的都是配置文件夹里面有个nginx.conf 就是主配置文件
我们进入返回nginx根目录 进入sbin目录 发现有个nginx 执行

./nginx
没抱任何错误的话 说明启动成功 我们查看进程
[root@localhost sbin]# ./nginx [root@localhost sbin]# ps aux | grep nginxroot     56307  0.0  0.0  16208   632 ?        Ss   00:21   0:00 nginx: master process ./nginxnobody   56308  0.0  0.1  16628  1232 ?        S    00:21   0:00 nginx: worker processroot     56314  0.0  0.0 103252   840 pts/0    S+   00:22   0:00 grep nginx[root@localhost sbin]# 

看到nginx的master(控制进程) 和worker(服务进程)都在运行中,说明启动成功,
在外网访问ip,尼玛 怎么报错,怎么怎么,恩 防火墙,应该是这货搞得鬼
给我”沙特当” 命令如下

service iptables stop
看到什么玩意ok 说明关闭成功 再次 访问 恩 访问成功
QQ20161021-0.png
nginx安装完毕 撸代码去

0 0
原创粉丝点击