ubuntu 20.04 离线安装nginx
无头学姐异闻录 2024-07-27 09:07:02 阅读 50
ubuntu 20.04 离线安装nginx
准备工作有网机器上的流程gcc/g++离线安装包获取nginx编译相关安装包获取打包上传
无网机器上的流程gcc/g++安装make安装pcre安装zlib安装openssl安装nginx安装nginx启动与验证
参考链接
准备工作
一台有网的ubuntu机器,可使用apt-get获取离线安装包或者任意有网的Windows机器,访问http://archive.ubuntu.com/ubuntu/pool/main,搜索下载对应版本的包无网的机器具备内网ssh访问权限或硬件数据传输条件
有网机器上的流程
gcc/g++离线安装包获取
由于gcc/g++本身依赖的包目录较为复杂,需要编写shell脚本,递归下载依赖包以及依赖包的依赖包,设置了三层递归,基本可以满足所有依赖搜索的需求
<code>#!/bin/bash
logfile=/home/perrin/Desktop/log
ret=""code>
function getDepends()
{
echo "fileName is" $1>>$logfile
# use tr to del < >
ret=`apt-cache depends $1|grep Depends |cut -d: -f2 |tr -d "<>"`
echo $ret|tee -a $logfile
}
# 需要获取其所依赖包的包
libs="gcc" # 或者用$1,从命令行输入库名字code>
# download libs dependen. deep in 3
i=0
while [ $i -lt 3 ] ;
do
let i++
echo $i
# download libs
newlist=" "code>
for j in $libs
do
added="$(getDepends $j)"code>
newlist="$newlist $added"code>
apt install $added --reinstall -d -y
done
libs=$newlist
done
使用以上脚本,递归下载gcc、g++所需的依赖包,下载的包将保存在以下路径:
/var/cache/apt/archives
nginx编译相关安装包获取
下载make离线安装包
apt-get install make -d
下载pcre-8.45.tar.gz 地址:https://netix.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.tar.gz
下载zlib-1.3.1.tar.gz 地址:https://www.zlib.net/zlib-1.3.1.tar.gz
下载openssl-1.1.1t.tar.gz 地址:https://objects.githubusercontent.com/github-production-release-asset-2e65be/7634677/d7446444-0f18-4771-85f3-2083574c7934?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVCODYLSA53PQK4ZA%2F20240508%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240508T122709Z&X-Amz-Expires=300&X-Amz-Signature=6d227e78c33fb8c3725d9e01e7daf662b204b46db65ce0b3dc0b17923f77d67f&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=7634677&response-content-disposition=attachment%3B%20filename%3Dopenssl-1.1.1t.tar.gz&response-content-type=application%2Foctet-stream
下载nginx-release-1.20.1.tar.gz 地址:https://codeload.github.com/nginx/nginx/tar.gz/refs/tags/release-1.20.1
打包上传
打包成如下目录传输到无网的机器上,目录如下:
无网机器上的流程
gcc/g++安装
使用以下命令查询gcc/g++安装依赖,确定安装顺序
<code>apt-cache depends gcc
得到以下输出:
root@master:/home/hadoop/app# apt-cache depends gcc
gcc
Depends: cpp
Depends: gcc-9
Conflicts: gcc-doc
|Recommends: libc6-dev
Recommends: <libc-dev>
libc6-dev
Suggests: gcc-multilib
Suggests: make
make-guile
Suggests: manpages-dev
Suggests: autoconf
Suggests: automake
Suggests: libtool
Suggests: flex
Suggests: bison
Suggests: gdb
Suggests: gcc-doc
其中,Depends后列出的包是必须的依赖包,继续使用以下命令查询依赖的依赖包:
apt-cache depends cpp
apt-cache depends gcc-9
apt-cache depends cpp-9
得到如下结果:
root@master:/home/hadoop/app# apt-cache depends cpp
cpp
Depends: cpp-9
Conflicts: cpp-doc
Suggests: cpp-doc
root@master:/home/hadoop/app# apt-cache depends gcc-9
gcc-9
Depends: cpp-9
Depends: gcc-9-base
Depends: libcc1-0
Depends: binutils
Depends: libgcc-9-dev
Depends: libc6
Depends: libgcc-s1
Depends: libgmp10
Depends: libisl22
Depends: libmpc3
Depends: libmpfr6
Depends: libstdc++6
Depends: zlib1g
Recommends: libc6-dev
Suggests: gcc-9-multilib
Suggests: gcc-9-doc
Suggests: gcc-9-locales
Replaces: cpp-9
root@master:/home/hadoop/app# apt-cache depends cpp-9
cpp-9
Depends: gcc-9-base
Depends: libc6
Depends: libgmp10
Depends: libisl22
Depends: libmpc3
Depends: libmpfr6
Depends: zlib1g
Breaks: <hardening-wrapper>
Breaks: libmagics++-dev
Suggests: gcc-9-locales
以此类推,可以确定初步的安装顺序,以上流程以gcc为例,g++相关依赖的安装顺序的确定流程与之类似。从而形成以下安装顺序脚本,cd到安装包所在路径后运行脚本即可执行安装流程:
dpkg -i binutils-common_2.34-6ubuntu1.9_amd64.deb
dpkg -i libquadmath0_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i binutils-x86-64-linux-gnu_2.34-6ubuntu1.9_amd64.deb
dpkg -i libgomp1_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i libc-dev-bin_2.31-0ubuntu9.15_amd64.deb
dpkg -i libstdc++-9-dev_9.4.0-1ubuntu1~20.04.2_amd64.deb
dpkg -i libasan5_9.4.0-1ubuntu1~20.04.2_amd64.deb
dpkg -i libcrypt1_1%3a4.4.10-10ubuntu4_amd64.deb
dpkg -i libitm1_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i libtsan0_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i libatomic1_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i libctf0_2.34-6ubuntu1.9_amd64.deb
dpkg -i liblsan0_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i libubsan1_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i libbinutils_2.34-6ubuntu1.9_amd64.deb
dpkg -i gcc-9-base_9.4.0-1ubuntu1~20.04.2_amd64.deb
dpkg -i libcc1-0_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i binutils_2.34-6ubuntu1.9_amd64.deb
dpkg -i libgcc-9-dev_9.4.0-1ubuntu1~20.04.2_amd64.deb
dpkg -i libc6_2.31-0ubuntu9.15_amd64.deb
dpkg -i libc6-dev_2.31-0ubuntu9.15_amd64.deb
dpkg -i libgcc-s1_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i libgmp10_2%3a6.2.0+dfsg-4ubuntu0.1_amd64.deb
dpkg -i libisl22_0.22.1-1_amd64.deb
dpkg -i libmpc3_1.1.0-1_amd64.deb
dpkg -i libmpfr6_4.0.2-1_amd64.deb
dpkg -i libstdc++6_10.5.0-1ubuntu1~20.04_amd64.deb
dpkg -i zlib1g_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb
dpkg -i cpp-9_9.4.0-1ubuntu1~20.04.2_amd64.deb
dpkg -i cpp_4%3a9.3.0-1ubuntu2_amd64.deb
dpkg -i gcc-9_9.4.0-1ubuntu1~20.04.2_amd64.deb
dpkg -i gcc_4%3a9.3.0-1ubuntu2_amd64.deb
dpkg -i g++-9_9.4.0-1ubuntu1~20.04.2_amd64.deb
dpkg -i g++_4%3a9.3.0-1ubuntu2_amd64.deb
注意:使用初步的顺序安装仍有可能出现报错,报错信息一般为:
dpkg: dependency problems prevent configuration of libstdc++-9-dev:amd64:
libstdc++-9-dev:amd64 depends on gcc-9-base (= 9.4.0-1ubuntu1~20.04.2); however:
Version of gcc-9-base:amd64 on system is 9.3.0-10ubuntu2.
libstdc++-9-dev:amd64 depends on libgcc-9-dev (= 9.4.0-1ubuntu1~20.04.2); however:
Version of libgcc-9-dev:amd64 on system is 9.3.0-10ubuntu2.
libstdc++-9-dev:amd64 depends on libc6-dev (>= 2.13-0ubuntu6); however:
Package libc6-dev:amd64 is not configured yet.
需要根据报错信息对脚本中的安装顺序进行调整,例如,在上述报错信息中提示,libstdc+±9-dev安装顺序应在gcc-9-base、libgcc-9-dev、libc6-dev之后。
安装完成之后,可使用以下命令查看是否安装成功,若安装成功应提示gcc和g++的版本信息:
root@master:/home/hadoop/app# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-9QDOt0/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnucode>
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
root@master:/home/hadoop/app# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-9QDOt0/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnucode>
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
make安装
make安装较为简单,在切换到安装包所在目录后,输入以下命令进行安装:
dpkg -i make_4.2.1-1.2_amd64.deb
pcre安装
首先将pcre解压
tar -zxvf pcre-8.45.tar.gz
解压后开始安装
cd pcre-8.45
./configure
make
make install
zlib安装
首先将zlib解压
tar -zxvf zlib-1.3.1.tar.gz
解压后开始安装
cd zlib-1.3.1
./configure
make
make install
openssl安装
首先将zlib解压
tar -zxvf openssl-1.1.1t.tar.gz
解压后开始安装
cd openssl-1.1.1t
./config
make
make install
nginx安装
首先将nginx解压
tar -zxvf nginx-1.20.1.tar.gz
解压后开始安装
cd nginx-1.20.1
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/home/hadoop/app/openssl-1.1.1t --with-pcre=/home/hadoop/app/pcre-8.45 --with-zlib=/home/hadoop/app/zlib-1.3.1
make
make install
nginx启动与验证
cd /usr/local/nginx
./sbin/nginx -c ./conf/nginx.conf
验证nginx配置文件是否正确
./sbin/nginx -t
显示如下输出则配置正确
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
输入ip:80,验证能否正常访问
成功!
参考链接
https://blog.csdn.net/dyeln/article/details/119451007https://blog.csdn.net/weixin_43872895/article/details/130428778https://blog.csdn.net/junbujianwpl/article/details/52811153https://zhuanlan.zhihu.com/p/466440088https://blog.csdn.net/wu10188/article/details/124970453
声明
本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。