前言
nginx以高效的linux網(wǎng)絡(luò)模型,epoll,event作為網(wǎng)絡(luò)IO模型,kqueue,在高并發(fā)網(wǎng)站情況下,nginx能夠輕松支持5w+的并發(fā)流量,并且消耗的服務(wù)器內(nèi)存,cpu等資源,也是很低的,運(yùn)行起來(lái)非常穩(wěn)定。
一、編譯安裝nginx
在Linux系統(tǒng)中,軟件的安裝方式有兩種:
- 包管理安裝
- 編譯安裝
編譯安裝是指用戶(hù)自己下載軟件源代碼,然后自己編譯、配置、安裝的安裝方式。編譯安裝的優(yōu)點(diǎn)是可以自定義編譯選項(xiàng),可以實(shí)現(xiàn)對(duì)軟件的個(gè)性化定制,而缺點(diǎn)是安裝過(guò)程相對(duì)復(fù)雜,需要手動(dòng)編譯、配置、安裝,并且需要自己處理依賴(lài)關(guān)系。Nginx是一款高性能的Web服務(wù)器,可以作為反向代理服務(wù)器或負(fù)載均衡服務(wù)器使用。在Linux系統(tǒng)中,可以通過(guò)包管理器安裝Nginx,也可以使用編譯安裝的方式安裝Nginx。下面是關(guān)于編譯安裝Nginx的相關(guān)信息。
二、編譯安裝過(guò)程
1.操作系統(tǒng)的選擇,centos7
代碼如下:
[root@hmiking ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
[root@hmiking ~]# uname -a
Linux hmiking 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
1.1關(guān)閉防火墻、selinux
代碼如下:
[root@hmiking ~]# systemctl disable --now firewalld
[root@hmiking ~]# setenforce 0
setenforce: SELinux is disabled
[root@hmiking ~]# getenforce
Disabled
2.安裝編譯開(kāi)發(fā)環(huán)境
代碼如下:
[root@hmiking ~]# yum install -y gcc gcc-c++ autoconf automake make
2.1安裝nginx所需的一些第三方系統(tǒng)庫(kù)的支持
代碼如下:
[root@hmiking ~]# yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel wget httpd-tools vim -y
3.編譯安裝nginx
3.1下載nginx源代碼
代碼如下:
[root@hmiking ~]# wget http://nginx.org/download/nginx-1.17.10.tar.gz
3.2解壓縮nginx包,并進(jìn)入該目錄
代碼如下:
[root@hmiking ~]# tar xf nginx-1.17.10.tar.gz
[root@hmiking ~]# cd nginx-1.17.10
[root@hmiking nginx-1.17.10]# ll #查看目錄下有哪些內(nèi)容
total 760
drwxr-xr-x 6 mysql mysql 326 Mar 6 23:39 auto # 檢測(cè)系統(tǒng)模塊依賴(lài)信息
-rw-r--r-- 1 mysql mysql 302754 Apr 14 2020 CHANGES # 存放nginx的變化記錄日志
-rw-r--r-- 1 mysql mysql 462076 Apr 14 2020 CHANGES.ru
drwxr-xr-x 2 mysql mysql 168 Mar 6 23:39 conf # 存放nginx主配置文件的目錄
-rwxr-xr-x 1 mysql mysql 2502 Apr 14 2020 configure # 可執(zhí)行的腳本,用于編譯文件的定制腳本
drwxr-xr-x 4 mysql mysql 72 Mar 6 23:39 contrib # 提供了vim插件,讓配置文件顏色區(qū)分,更友好
drwxr-xr-x 2 mysql mysql 40 Mar 6 23:39 html # 存放了標(biāo)準(zhǔn)的html頁(yè)面文件
-rw-r--r-- 1 mysql mysql 1397 Apr 14 2020 LICENSE
drwxr-xr-x 2 mysql mysql 21 Mar 6 23:39 man
-rw-r--r-- 1 mysql mysql 49 Apr 14 2020 README
drwxr-xr-x 9 mysql mysql 91 Mar 6 23:39 src # 存放了nginx源代碼的目錄
3.3開(kāi)始編譯安裝
代碼如下:
# 進(jìn)入軟件源代碼目錄,執(zhí)行編譯腳本文件,如指定安裝路徑,以及開(kāi)啟額外功能等
[root@hmiking nginx-1.17.10]# mkdir /usr/local/nginx
[root@hmiking nginx-1.17.10]# ./configure --prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-threads \
--with-file-aio && make && make install
3.4查看安裝后的nginx目錄
代碼如下:
[root@hmiking nginx-1.17.10]# cd /usr/local/nginx/
[root@hmiking nginx]# ls
conf html logs sbin
# conf 存放nginx的配置文件,如 nginx.conf
# html 存放nginx的網(wǎng)頁(yè)根目錄文件,存放站點(diǎn)的靜態(tài)文件數(shù)據(jù)
# logs 存放nginx的各種日志目錄
# sbin 存放該軟件的可執(zhí)行命令
4.啟動(dòng)并訪問(wèn)nginx
4.1將 nginx 添加到全局變量中
代碼如下:
# 可以通過(guò)軟鏈接到/usr/local/sbin/ 目錄下
[root@hmiking nginx]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
# 此時(shí)可以快捷的使用nginx各種指令
nginx # 首次直接輸入nginx,表示啟動(dòng)該進(jìn)程
4.2檢查nginx的編譯安裝信息
代碼如下:
[root@hmiking nginx]# nginx -V
nginx version: nginx/1.17.10
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-threads --with-file-aio
4.3啟動(dòng)nginx
代碼如下:
# 啟動(dòng)nginx
[root@hmiking ~]# nginx
# 查看nginx進(jìn)程
[root@hmiking ~]# ps -ef | grep nginx | grep -v grep
root 27314 1 0 01:28 ? 00:00:00 nginx: master process nginx
nobody 27315 27314 0 01:28 ? 00:00:00 nginx: worker process
4.4通過(guò)命令行終端訪問(wèn)nginx
代碼如下:
[root@hmiking ~]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
4.5通過(guò)瀏覽器訪問(wèn)nginx
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-738415.html
總結(jié)
提示:本文僅供學(xué)習(xí)和參考,歡迎關(guān)注我的博客,以及我的博客網(wǎng)站。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-738415.html
到了這里,關(guān)于Centos7 編譯安裝Nginx的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!