1. 情景再現
今天在學習Nginx的時候Windows安裝的好好的,也可以正常啟動了,但是Centos安裝的時候出現了一些錯誤,記錄一下
2. 安裝步驟
1. tar包安裝
-
下載
Nginx安裝包,下載地址# 或者使用wget命令 wget http://nginx.org/download/nginx-1.18.0.tar.gz -
將壓縮包上傳到服務器root根目錄
scp nginx.tar.gz root@ip: -
解壓壓縮包
tar -zxvf nginx.tar.gz -
編譯nginx
cd nginx ./configure make make install # 查看是否安裝成功 whereis nginx # 啟動nginx cd /usr/local/nginx/sbin ./nginx
2. yum安裝
-
配置 yum 源
# 配置 rpm源,如果出現 Unknow host error,請參考 第四章 Vmware中的錯誤 rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm # 或者手動創建一個組態檔 #進入 yum 安裝源檔案目錄 cd /etc/yum.repo.d #切換到yum安裝源檔案目錄 vim nginx.repo #創建一個安裝包源 # 粘貼下列內容進去 [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key # 按 esc 退出編輯模式 :wq! 保存退出 :wq! -
安裝nginx
yum -y install nginx
3. 阿里云問題描述
- PCRE 缺失
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=option.
解決辦法:安裝 PCRE
yum -y install pcre-devel
- HTTP缺失
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
–without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
–with-http_ssl_module --with-openssl=options.
解決辦法:安裝openssl
yum -y install openssl openssl-devel
- 執行上述兩個命令時可能會出現下面的錯誤
error: rpmdb: BDB0113 Thread/process 3330/139891423307584 failed: BDB1507 Thread died in Berkeley DB library
error: db5 error(-30973) from dbenv->failchk: BDB0087 DB_RUNRECOVERY: Fatal error, run database recovery
error: cannot open Packages index using db5 - (-30973)
error: cannot open Packages database in /var/lib/rpm
解決辦法:洗掉db,重新構建rpm
# 進入rpm目錄
cd /var/lib/rpm
# 查看rpm目錄
ls
# 洗掉所有的 db檔案 小心別執行成 rm -rf /
# 可以參考 https://blog.csdn.net/geek64581/article/details/101095854 這個博客使用 mv命令代替 rm 命令
rm -rf __db*
# 重新構建 rpm
rpm --rebuliddb
# 構建完成之后重新執行即可
4. Vmware 安裝問題描述
安裝前需要確保系統有 gcc pcre-devel zlib-devel openssl-devel
- 提示沒有C compiler
checking for OS
- Linux 3.10.0-514.el7.x86_64 x86_64
checking for C compiler … not found./configure: error: C compiler cc is not found
錯誤原因:沒有安裝gcc
yum -y install gcc
- 找不到yum鏡像
“Could not resolve host: mirrors.njupt.edu.cn; Unknown error”
解決辦法
# 編輯 resolv.conf檔案
vim /etc/resolv.conf
# 添加內容
nameserver 8.8.8.8
nameserver 8.8.4.4
# 重啟network 或者重啟linux
service network restart
# 或者
shutdown -r now
- 沒有安裝zlib
/configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=option.
yum -y install zlib-devel
5. 訪問nginx
# 啟動Nginx
cd /usr/local/niginx/sbin
./nginx
# 如果沒有體質列印就是啟動成功了,也可以使用ps命令查看
ps -ef|grep nginx
打開瀏覽器查看頁面
localhost:80或者localhost,因為http默認的埠是80

如果使用的是Vmware訪問不了的話,有兩種解決辦法
-
關閉防火墻
#停止防火墻 systemctl stop firewalld.service # 禁止防火墻開機啟動 systemctl disable firewalld.service -
安裝iptables防火墻
# 安裝iptables yum install iptables-services # 修改組態檔 vim /etc/sysconfig/iptables # 按i進入編輯模式找到下列內容 -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #在該行下面添加 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT # 或者直接找到22那一行按yyp復制一行,改為80即可 # 想復制多行需要 yynp dd是洗掉當前行 yy3p就是復制三行 #按 esc退出編輯模式 :wq保存退出 :wq! #最后重啟防火墻使配置生效 systemctl restart iptables.service #設定防火墻開機啟動 systemctl enable iptables.service
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/292678.html
標籤:其他
上一篇:交換機和路由器有什么區別
下一篇:如何卸載用yum安裝的軟體
