千家信息网

shell脚本源码安装nginx的过程是什么

发表于:2025-11-07 作者:千家信息网编辑
千家信息网最后更新 2025年11月07日,本篇内容主要讲解"shell脚本源码安装nginx的过程是什么",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"shell脚本源码安装nginx的过程是什么"
千家信息网最后更新 2025年11月07日shell脚本源码安装nginx的过程是什么

本篇内容主要讲解"shell脚本源码安装nginx的过程是什么",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"shell脚本源码安装nginx的过程是什么"吧!

SHELL概念

  1. SHELL是什么?SHELL是Linux内核跟用户之间沟通的桥梁;

  2. SHELL也是一个命令解释器,用户可以输入命令到SHELL,SHELL将命令传递给Linux内核,内核处理完毕,返回给SHELL,SHELL将返回的结果返给用户终端;

  3. SHELL是外壳,中间件,外壳有很多的种类,bash、csh、ksh、zsh等;

  4. SHELL和SHELL编程有什么关系?SHELL是命令解释器,用户和操作系统沟通桥梁,而SHELL编程基于SHELL解释器来实现具体的功能或者需求;

  5. SHELL命令、SHELL脚本、SHELL编程、SHELL之间解释?

SHELL编程用途

  • SHELL编程的目的将重复的工作变成自动化,可以理解为批处理;

  • SHELL主要是为了减轻人工的频繁的操作、提高运维工作效率,保证网站稳定、高效的运行;

  • 例如需要源码编译LNMP WEB架构,20台都需要编译怎么办?

如何开启Shell编程

  • 任何的编程语言,都是从Hello,world;

  • SHELL编程其实就是将SHELL命令写入到脚本文件中;

  • SHELL编程规范,脚本内容第一行必须以#!开头,其后接SHELL的种类,例如/bin/bash,/bin/sh等;

下面脚本看下shell脚本源码安装nginx的过程。

[root@localhost ~]# vim nginx.sh [root@localhost ~]# cat nginx.sh #!/bin/bashversion=nginx-1.20.1.tar.gzname=nginx-1.20.1install_dir=/usr/locallog=/var/log/nginx#解决依赖关系yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel wget gd-devel gcc gcc-c++yum -y groups mark install 'Development Tools'#创建用户id nginx &>/dev/nullif [ $? -ne 0 ];then          useradd -s /sbin/nologin nginx fi#创建日志存放目录if [ ! -d $log ];then         mkdir -p /var/log/nginx    chown -R nginx.nginx /var/log/nginx fi#下载nginxcd /usr/src/wget   http://nginx.org/download/$version#解压tar xf $version mv $name nginxcd nginx/ && ./configure \--prefix=$install_dir/nginx \--user=nginx \--group=nginx \--with-debug \--with-http_ssl_module \--with-http_realip_module \--with-http_image_filter_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_stub_status_module \--http-log-path=$log/access.log \--error-log-path=$log/error.logmake && make install#配置环境变量echo "export PATH=$install_dir/nginx/sbin:\$PATH" > /etc/profile.d/nginx.shsource /etc/profile.d/nginx.sh#创建服务文件cat > /usr/lib/systemd/system/nginx.service <
//测试[root@localhost ~]# ./nginx.sh 已加载插件:fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本软件包 pcre-8.32-17.el7.x86_64 已安装并且是最新版本软件包 pcre-devel-8.32-17.el7.x86_64 已安装并且是最新版本软件包 zlib-1.2.7-19.el7_9.x86_64 已安装并且是最新版本软件包 zlib-devel-1.2.7-19.el7_9.x86_64 已安装并且是最新版本软件包 1:openssl-1.0.2k-22.el7_9.x86_64 已安装并且是最新版本软件包 1:openssl-devel-1.0.2k-22.el7_9.x86_64 已安装并且是最新版本软件包 wget-1.14-18.el7_6.1.x86_64 已安装并且是最新版本软件包 gd-devel-2.0.35-27.el7_9.x86_64 已安装并且是最新版本软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本软件包 gcc-c++-4.8.5-44.el7.x86_64 已安装并且是最新版本无须任何处理已加载插件:fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.comMarked install: Development Tools--2021-10-25 12:15:53--  http://nginx.org/download/nginx-1.20.1.tar.gz正在解析主机 nginx.org (nginx.org)... 52.58.199.22, 3.125.197.172, 2a05:d014:edb:5702::6, ...正在连接 nginx.org (nginx.org)|52.58.199.22|:80... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:1061461 (1.0M) [application/octet-stream]正在保存至: "nginx-1.20.1.tar.gz.1"100%[===================================================================================================================>] 1,061,461    670KB/s 用时 1.5s   2021-10-25 12:15:55 (670 KB/s) - 已保存 "nginx-1.20.1.tar.gz.1" [1061461/1061461])checking for OS + Linux 3.10.0-862.el7.x86_64 x86_64checking for C compiler ... found + using GNU C compiler + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 省略....nginx http uwsgi temporary files: "uwsgi_temp"  nginx http scgi temporary files: "scgi_temp"make -f objs/Makefilemake[1]: 进入目录"/usr/local/nginx"cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \        -o objs/src/core/nginx.o \        src/core/nginx.ccc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \        -o objs/src/core/ngx_log.o \        src/core/ngx_log.ctest -f '/usr/local/nginx/conf/nginx.conf' \        || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'test -d '/usr/local/nginx/logs' \        || mkdir -p '/usr/local/nginx/logs'test -d '/var/log/nginx' \        || mkdir -p '/var/log/nginx'test -d '/usr/local/nginx/html' \        || cp -R html '/usr/local/nginx'test -d '/var/log/nginx' \        || mkdir -p '/var/log/nginx'make[1]: 离开目录"/usr/src/nginx"Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.[root@localhost ~]# systemctl start nginx[root@localhost ~]# systemctl stop firewalld[root@localhost ~]# ss -antlState       Recv-Q Send-Q                                 Local Address:Port                                                Peer Address:Port              LISTEN      0      128                                                *:80                                                             *:*                  LISTEN      0      128                                                *:22                                                             *:*                  LISTEN      0      100                                        127.0.0.1:25                                                             *:*                  LISTEN      0      128                                               :::22                                                            :::*                  LISTEN      0      100                                              ::1:25                                                            :::*

经过测试,想要直接使用nginx命令 需要在终端手动读取配置

//配置文件脚本里已经写好,这里直接读取就可以[root@localhost ~]# source /etc/profile.d/nginx.sh[root@localhost ~]# which nginx/usr/local/nginx/sbin/nginx[root@localhost ~]# nginx -Vnginx version: nginx/1.20.1built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) built with OpenSSL 1.0.2k-fips  26 Jan 2017TLS SNI support enabledconfigure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log

或者用source nginx.sh执行脚本

[root@localhost ~]# source nginx.sh //这种方式不需要手动读取环境变量

到此,相信大家对"shell脚本源码安装nginx的过程是什么"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

版本 软件 软件包 脚本 编程 命令 源码 用户 过程 正在 解释 内容 内核 文件 目录 解释器 配置 之间 变量 外壳 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 闵行区项目数据库服务价格查询 美团骑手用什么软件开发票 各大软件开发票 山东企业软件开发出厂价格 杭州银行软件开发招聘信息 潍坊mrp管理软件开发 传奇服务器一个月要多少流量 我的世界如何在服务器弄32k网易版 服务器端php环境 个人图片管理 服务器 数据库有什么问题可以问老师 更新数据库的sql 吉林通信软件开发五星服务 中国联通网络技术岗面试问什么 网吧网络安全法 我的世界网易版服务器崩溃怎么办 页游连不上服务器 服务器基础软件开发 每次开机都弹出服务器管理 2019网络安全宣传周启动 vba 数据库安全 外模式是数据库的全局逻辑结构 哈密新华互联网科技行情 天津浪潮服务器续保维修 数据库与函数依赖关系 99se数据库已达最大值 vb窗体应用和数据库修改 等保网络安全管理机构 网络安全知识倡议书 数据库安全网关市场前景
0