全网最细且手把手一起学CentOS8.0源码编译安装LNMP环境之nginx源码安装(一)

作者: 温新

分类: 【Linux】

阅读: 4085

时间: 2019-10-07 13:17:00

<span style="background-color: rgb(255, 255, 255); color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Arial, Helvetica, sans-serif; font-size: 15px;">

【序言】 今天来更新一下最新的安装情况。与一位技术大哥进行了一次交流,学习到不少,也解答了心中遗留的不少疑惑。下面就来分享一下,关于Linux下安装软件不成功的原因,绝大多数都是因为缺少依赖所导致的。这些天来,重复搭建LAMP、LNMP的次数不少,经过与这位技术大哥的交流之后,确实是这样,缺少依赖所导致无法安装成功。

我之前一直使用的是VMware14,每一次编译mysql8就是一个非常痛苦的事情,编译安装一次mysql8的时间至少是大于4小时甚至更长时间。或许是一些强迫症的原因,对于太多系统缺少明确的管理,我卸载了VMware14,安装了VMware15,使用了VMware15之后,关于mysql8的问题全都没有了,编译也是非常的正常。好了,下面不废话了,直接更新文章。为了确保你也能安装成功,请看清环境。

一、准备工作

【环境要求】
VMware15.5.0
CentOS8.0

1.1)安装方便操作的软件

yum -y install lrzsz
yum -y install vim
yum -y install wget

1.2)准备源码包

所有源码包放置/usr/local/src/目录下

nginx-1.17.4.tar.gz

1.3、CentOs8.0关闭防火墙

systemctl stop firewalld.service                     关闭防火墙          
systemctl disable firewalld.service                  关闭防火墙开机自启
systemctl status firewalld.service                   查看防火墙状态

二、源码安装nginx1.17.4

2.1、安装依赖包

yum -y install apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype-devel gcc gcc-c++ gd gd-devel gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* make openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet wget zlib-devel ncurses-devel libtirpc-devel gtk* ntpstat na* bison*

2.2、创建用户

groupadd www
useradd -g www www -M -s /sbin/nologin

2.3、安装nginx

cd /usr/local/src
tar -zxvf nginx-1.17.4.tar.gz 
cd nginx-1.17.4

./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-pcre \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_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_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-stream_ssl_module

make & make install

/usr/local/nginx/sbin/nginx             启动
/usr/local/nginx/sbin/nginx -s stop     停止
/usr/local/nginx/sbin/nginx -s reload   重启

2.4、设置开机重启

cd /usr/lib/systemd/system
vim nginx.service

路径启动(不用管这个,当忘记快捷启动了再来看这个)
/usr/local/nginx/sbin/nginx             启动
/usr/local/nginx/sbin/nginx -s stop     停止
/usr/local/nginx/sbin/nginx -s reload   重启

在nginx.service文件中添加如下内容

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit

[Install]
WantedBy=multi-user.target

保存退出

:wq

设置开机自启

systemctl enable nginx.service

这两个命令留意下
systemctl disable  nginx.service        #禁止开机自启
systemctl s-enable nginx.service        #查询是否为开机自己服务

快速启动ningx命令

 systemctl start  nginx.service         #启动
 systemctl stop   nginx.service         #停止
 systemctl reload nginx.service         #重启
 systemctl status nginx.service         #查看服务状态

2.5、配置虚拟主机

系统根目录下创建WWW目录(注意WWW是大写)

mkdir /WWW

备份nginx.conf文件

cd /usr/local/nginx/conf
cp ./nginx.conf ./nginx.conf.bak

修改nginx.conf配置文件

cd /usr/local/nginx/conf
vim nginx.conf

2.5.1)修改项目根目录

root html 修改为 /WWW  

2.5.2)修改404页面

删除 #error_page  404              /404.html; 前面的 # 号

2.5.3)配置记住端口访问的虚拟主机
server {
listen 8081;
root /WWW/demo01;
index index.html;

location / {
    }
}

重启服务
systemctl restart nginx.service 

访问
192.168.5.148:8081

^_^到这里nginx就安装完成了

<span style="background-color: rgb(255, 255, 255); color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Arial, Helvetica, sans-serif; font-size: 15px;">文章更新时间 2019年10月26日

<span style="background-color: rgb(255, 255, 255); color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Arial, Helvetica, sans-serif; font-size: 15px;">

<span style="background-color: rgb(255, 255, 255); color: rgb(51, 51, 51); font-family: "Microsoft YaHei", Arial, Helvetica, sans-serif; font-size: 15px;">我是夕阳何处寻,期能和优秀的你一起同行!

夕阳何处寻

2019年10月7

请登录后再评论