简述
在Ubuntu系统中离线安装Nginx及其依赖,你需要先下载所有必需的软件包,然后在没有网络连接的系统上进行安装。
准备环境
首先需要找一台安装相同版本的可连公网的 Ubuntu 系统,关键字
- 相同版本的操作系统,比如都是 Ubuntu 20.04
- 能上公网,访问百度,公有镜像仓库
- 可以通过 apt-get download 命令在线下载这些包到本地目录
确定依赖
Nginx的主要依赖通常包括:
- build-essential:提供编译所需的工具,如gcc、make等。
- libpcre3-dev:PCRE库的开发文件,用于正则表达式支持。
- zlib1g-dev:用于数据压缩功能的zlib库的开发文件。
- libssl-dev:OpenSSL库的开发文件,用于HTTPS支持。
下载依赖包
在有网络的环境中,使用apt命令下载这些依赖的.deb包,以及Nginx的源代码包。
- 更新包列表
apt update
- 清理本地下载的包文件
apt-get clean
- 下载依赖(注意实际版本号可能不同,请根据实际情况调整)
root@i-gfhsdueq:~# apt-get install --download-only build-essential libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev Reading package lists... Done Building dependency tree Reading state information... Done libpcre3 is already the newest version (2:8.39-12ubuntu0.1). The following additional packages will be installed: autoconf automake autotools-dev binutils binutils-common binutils-x86-64-linux-gnu cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-10-base gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6 libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libgcc-s1 libgomp1 libisl22 libitm1 liblsan0 libltdl-dev libmpc3 libpcre16-3 libpcre32-3 libpcrecpp0v5 libquadmath0 libssl1.1 libstdc++-9-dev libstdc++6 libtsan0 libubsan1 linux-libc-dev m4 make manpages-dev zlib1g Suggested packages: autoconf-archive gnu-standards autoconf-doc gettext binutils-doc cpp-doc gcc-9-locales debian-keyring g++-multilib g++-9-multilib gcc-9-doc gcc-multilib flex bison gdb gcc-doc gcc-9-multilib glibc-doc bzr libtool-doc libssl-doc libstdc++-9-doc gfortran | fortran95-compiler gcj-jdk m4-doc make-doc The following NEW packages will be installed: autoconf automake autotools-dev binutils binutils-common binutils-x86-64-linux-gnu build-essential cpp cpp-9 dpkg-dev fakeroot g++ g++-9 gcc gcc-9 gcc-9-base libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libcrypt-dev libctf-nobfd0 libctf0 libdpkg-perl libfakeroot libfile-fcntllock-perl libgcc-9-dev libgomp1 libisl22 libitm1 liblsan0 libltdl-dev libmpc3 libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libquadmath0 libssl-dev libstdc++-9-dev libtool libtsan0 libubsan1 linux-libc-dev m4 make manpages-dev zlib1g-dev The following packages will be upgraded: gcc-10-base libc6 libgcc-s1 libssl1.1 libstdc++6 openssl zlib1g 7 upgraded, 53 newly installed, 0 to remove and 190 not upgraded. Need to get 54.7 MB of archives. After this operation, 221 MB of additional disk space will be used. Do you want to continue? [Y/n] y
- 查看已下载的软件包
root@i-gfhsdueq:~# tree /var/cache/apt/archives/ /var/cache/apt/archives/ ├── autoconf_2.69-11.1_all.deb ├── automake_1%3a1.16.1-4ubuntu6_all.deb ├── autotools-dev_20180224.1_all.deb ├── binutils_2.34-6ubuntu1.9_amd64.deb ├── binutils-common_2.34-6ubuntu1.9_amd64.deb ├── binutils-x86-64-linux-gnu_2.34-6ubuntu1.9_amd64.deb ├── build-essential_12.8ubuntu1.1_amd64.deb ├── cpp_4%3a9.3.0-1ubuntu2_amd64.deb ├── cpp-9_9.4.0-1ubuntu1~20.04.2_amd64.deb ├── dpkg-dev_1.19.7ubuntu3.2_all.deb ├── fakeroot_1.24-1_amd64.deb ├── g++_4%3a9.3.0-1ubuntu2_amd64.deb ├── g++-9_9.4.0-1ubuntu1~20.04.2_amd64.deb ├── gcc-10-base_10.5.0-1ubuntu1~20.04_amd64.deb ├── gcc_4%3a9.3.0-1ubuntu2_amd64.deb ├── gcc-9_9.4.0-1ubuntu1~20.04.2_amd64.deb ├── gcc-9-base_9.4.0-1ubuntu1~20.04.2_amd64.deb ├── libalgorithm-diff-perl_1.19.03-2_all.deb ├── libalgorithm-diff-xs-perl_0.04-6_amd64.deb ├── libalgorithm-merge-perl_0.08-3_all.deb ├── libasan5_9.4.0-1ubuntu1~20.04.2_amd64.deb ├── libatomic1_10.5.0-1ubuntu1~20.04_amd64.deb ├── libbinutils_2.34-6ubuntu1.9_amd64.deb ├── libc6_2.31-0ubuntu9.16_amd64.deb ├── libc6-dev_2.31-0ubuntu9.16_amd64.deb ├── libcc1-0_10.5.0-1ubuntu1~20.04_amd64.deb ├── libc-dev-bin_2.31-0ubuntu9.16_amd64.deb ├── libcrypt-dev_1%3a4.4.10-10ubuntu4_amd64.deb ├── libctf0_2.34-6ubuntu1.9_amd64.deb ├── libctf-nobfd0_2.34-6ubuntu1.9_amd64.deb ├── libdpkg-perl_1.19.7ubuntu3.2_all.deb ├── libfakeroot_1.24-1_amd64.deb ├── libfile-fcntllock-perl_0.22-3build4_amd64.deb ├── libgcc-9-dev_9.4.0-1ubuntu1~20.04.2_amd64.deb ├── libgcc-s1_10.5.0-1ubuntu1~20.04_amd64.deb ├── libgomp1_10.5.0-1ubuntu1~20.04_amd64.deb ├── libisl22_0.22.1-1_amd64.deb ├── libitm1_10.5.0-1ubuntu1~20.04_amd64.deb ├── liblsan0_10.5.0-1ubuntu1~20.04_amd64.deb ├── libltdl-dev_2.4.6-14_amd64.deb ├── libmpc3_1.1.0-1_amd64.deb ├── libpcre16-3_2%3a8.39-12ubuntu0.1_amd64.deb ├── libpcre32-3_2%3a8.39-12ubuntu0.1_amd64.deb ├── libpcre3-dev_2%3a8.39-12ubuntu0.1_amd64.deb ├── libpcrecpp0v5_2%3a8.39-12ubuntu0.1_amd64.deb ├── libquadmath0_10.5.0-1ubuntu1~20.04_amd64.deb ├── libssl1.1_1.1.1f-1ubuntu2.22_amd64.deb ├── libssl-dev_1.1.1f-1ubuntu2.22_amd64.deb ├── libstdc++6_10.5.0-1ubuntu1~20.04_amd64.deb ├── libstdc++-9-dev_9.4.0-1ubuntu1~20.04.2_amd64.deb ├── libtool_2.4.6-14_all.deb ├── libtsan0_10.5.0-1ubuntu1~20.04_amd64.deb ├── libubsan1_10.5.0-1ubuntu1~20.04_amd64.deb ├── linux-libc-dev_5.4.0-182.202_amd64.deb ├── lock ├── m4_1.4.18-4_amd64.deb ├── make_4.2.1-1.2_amd64.deb ├── manpages-dev_5.05-1_all.deb ├── openssl_1.1.1f-1ubuntu2.22_amd64.deb ├── partial ├── zlib1g_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb └── zlib1g-dev_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb 1 directory, 61 files
下载Nginx源代码
- 从Nginx官网获取最新稳定版的下载链接
wget http://nginx.org/download/nginx-1.23.1.tar.gz
转移文件到离线系统
- 将所有下载的.deb文件及Nginx源代码包通过USB、网络共享或其他方式转移到目标离线系统。
tar czvf nginx.tar.gz nginx-1.23.1.tar.gz /var/cache/apt/archives
在离线系统安装依赖
root@i-gfhsdueq:/usr/local/src# cd var/cache/apt/archives/ root@i-gfhsdueq:/usr/local/src/var/cache/apt/archives# ls autoconf_2.69-11.1_all.deb libfakeroot_1.24-1_amd64.deb automake_1%3a1.16.1-4ubuntu6_all.deb libfile-fcntllock-perl_0.22-3build4_amd64.deb autotools-dev_20180224.1_all.deb libgcc-9-dev_9.4.0-1ubuntu1~20.04.2_amd64.deb binutils_2.34-6ubuntu1.9_amd64.deb libgcc-s1_10.5.0-1ubuntu1~20.04_amd64.deb binutils-common_2.34-6ubuntu1.9_amd64.deb libgomp1_10.5.0-1ubuntu1~20.04_amd64.deb binutils-x86-64-linux-gnu_2.34-6ubuntu1.9_amd64.deb libisl22_0.22.1-1_amd64.deb build-essential_12.8ubuntu1.1_amd64.deb libitm1_10.5.0-1ubuntu1~20.04_amd64.deb cpp_4%3a9.3.0-1ubuntu2_amd64.deb liblsan0_10.5.0-1ubuntu1~20.04_amd64.deb cpp-9_9.4.0-1ubuntu1~20.04.2_amd64.deb libltdl-dev_2.4.6-14_amd64.deb dpkg-dev_1.19.7ubuntu3.2_all.deb libmpc3_1.1.0-1_amd64.deb fakeroot_1.24-1_amd64.deb libpcre16-3_2%3a8.39-12ubuntu0.1_amd64.deb g++_4%3a9.3.0-1ubuntu2_amd64.deb libpcre32-3_2%3a8.39-12ubuntu0.1_amd64.deb g++-9_9.4.0-1ubuntu1~20.04.2_amd64.deb libpcre3-dev_2%3a8.39-12ubuntu0.1_amd64.deb gcc-10-base_10.5.0-1ubuntu1~20.04_amd64.deb libpcrecpp0v5_2%3a8.39-12ubuntu0.1_amd64.deb gcc_4%3a9.3.0-1ubuntu2_amd64.deb libquadmath0_10.5.0-1ubuntu1~20.04_amd64.deb gcc-9_9.4.0-1ubuntu1~20.04.2_amd64.deb libssl1.1_1.1.1f-1ubuntu2.22_amd64.deb gcc-9-base_9.4.0-1ubuntu1~20.04.2_amd64.deb libssl-dev_1.1.1f-1ubuntu2.22_amd64.deb libalgorithm-diff-perl_1.19.03-2_all.deb libstdc++6_10.5.0-1ubuntu1~20.04_amd64.deb libalgorithm-diff-xs-perl_0.04-6_amd64.deb libstdc++-9-dev_9.4.0-1ubuntu1~20.04.2_amd64.deb libalgorithm-merge-perl_0.08-3_all.deb libtool_2.4.6-14_all.deb libasan5_9.4.0-1ubuntu1~20.04.2_amd64.deb libtsan0_10.5.0-1ubuntu1~20.04_amd64.deb libatomic1_10.5.0-1ubuntu1~20.04_amd64.deb libubsan1_10.5.0-1ubuntu1~20.04_amd64.deb libbinutils_2.34-6ubuntu1.9_amd64.deb linux-libc-dev_5.4.0-182.202_amd64.deb libc6_2.31-0ubuntu9.16_amd64.deb lock libc6-dev_2.31-0ubuntu9.16_amd64.deb m4_1.4.18-4_amd64.deb libcc1-0_10.5.0-1ubuntu1~20.04_amd64.deb make_4.2.1-1.2_amd64.deb libc-dev-bin_2.31-0ubuntu9.16_amd64.deb manpages-dev_5.05-1_all.deb libcrypt-dev_1%3a4.4.10-10ubuntu4_amd64.deb openssl_1.1.1f-1ubuntu2.22_amd64.deb libctf0_2.34-6ubuntu1.9_amd64.deb partial libctf-nobfd0_2.34-6ubuntu1.9_amd64.deb zlib1g_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb libdpkg-perl_1.19.7ubuntu3.2_all.deb zlib1g-dev_1%3a1.2.11.dfsg-2ubuntu1.5_amd64.deb root@i-gfhsdueq:/usr/local/src/var/cache/apt/archives# dpkg -i *.deb
编译安装Nginx
useradd -s /sbin/nologin www -M cd /usr/local/src tar -xvf nginx-1.23.2.tar.gz cd /usr/local/src/nginx-1.23.2 ./configure --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-stream --prefix=/usr/local/nginx-1.23.2 make && make install ln -sfT /usr/local/nginx-1.23.2 /usr/local/nginx #添加环境变量 cat <<EOF >> /etc/profile ##### nginx export PATH=/usr/local/nginx/sbin:\$PATH EOF
继续阅读
评论