广告
返回顶部
首页 > 资讯 > 操作系统 >shell脚本源码安装nginx的详细过程
  • 677
分享到

shell脚本源码安装nginx的详细过程

shell脚本安装nginxshell安装nginx 2022-06-04 23:06:13 677人浏览 八月长安
摘要

shell概念 SHELL是什么?SHELL是linux内核跟用户之间沟通的桥梁; SHELL也是一个命令解释器,用户可以输入命令到SHELL,SHELL将命令传递给Linux内核,内核处理完毕,返回给

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/bash
version=nginx-1.20.1.tar.gz
name=nginx-1.20.1
install_dir=/usr/local
log=/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/null
if [ $? -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
#下载nginx
cd /usr/src/
wget   Http://nginx.org/download/$version
#解压
tar xf $version 
mv $name nginx
cd 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.log

make && make install
#配置环境变量
echo "export PATH=$install_dir/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
source /etc/profile.d/nginx.sh

#创建服务文件
cat > /usr/lib/systemd/system/nginx.service <<EOF

[Unit]
Description=nginx
After=network.target
   
[Service]
Type=forking
ExecStart=$install_dir/nginx/sbin/nginx
ExecReload=$install_dir/nginx/sbin/nginx -s reload
ExecStop=$install_dir/nginx/sbin/nginx -s quit
PrivateTmp= true
   
[Install]
WantedBy=multi-user.target 

EOF
#开机自启
systemctl enable --now nginx

//测试
[root@localhost ~]# ./nginx.sh 
已加载插件:fastestmirror
Loading 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 已安装并且是最新版本
无须任何处理
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Marked 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_64
checking 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/Makefile
make[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.c
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/ngx_log.o \
        src/core/ngx_log.c
test -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 -antl
State       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                                                            :::*              

shell脚本源码安装nginx的详细过程

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


//配置文件脚本里已经写好,这里直接读取就可以
[root@localhost ~]# source /etc/profile.d/nginx.sh
[root@localhost ~]# which nginx
/usr/local/nginx/sbin/nginx
[root@localhost ~]# nginx -V
nginx version: nginx/1.20.1
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 --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的文章就介绍到这了,更多相关shell脚本安装nginx内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

--结束END--

本文标题: shell脚本源码安装nginx的详细过程

本文链接: https://www.lsjlt.com/news/21407.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • shell脚本源码安装nginx的详细过程
    SHELL概念 SHELL是什么?SHELL是linux内核跟用户之间沟通的桥梁; SHELL也是一个命令解释器,用户可以输入命令到SHELL,SHELL将命令传递给Linux内核,内核处理完毕,返回给...
    99+
    2022-06-04
    shell脚本安装nginx shell安装nginx
  • shell脚本源码安装nginx的过程是什么
    本篇内容主要讲解“shell脚本源码安装nginx的过程是什么”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“shell脚本源码安装nginx的过程是什么”吧!SHELL概念SHELL是什么?SH...
    99+
    2023-06-25
  • 源码安装apache脚本部署过程详解
    目录源码安装apache脚本部署源码安装apache脚本部署 [root@localhost ~]# ls anaconda-ks.cfg httpd.tar.xz [root@localhost ~]# tar xf...
    99+
    2022-09-22
  • Linux中PHP的源码安装shell脚本
    #!/bin/bash#安装PHPrpm -e php php-cli php-ldap php-common php-mysql --nodepsyum -y install zlib-devel lib...
    99+
    2022-10-18
  • Linux下MySQL5.6.12源码安装的详细过程
    本篇内容主要讲解“Linux下MySQL5.6.12源码安装的详细过程”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux下MySQL5.6.12源码安装的详细过程”吧!安装前的有关描述必备...
    99+
    2023-06-01
  • shell脚本多实例部署nginx的详细教程
    1. 创建一个目录,用来存放脚本和安装包 [root@localhost nginx]# tree . ├── install.sh └── packages └── nginx-1.20.1.tar.gz ...
    99+
    2022-06-04
    shell脚本部署nginx shell部署nginx
  • Nginx源码编译安装过程记录
    rpm包安装比较简单,这里不做说明。 对于大多数开源软件,如果找不到安装包,可以使用源码安装方式,源码安装虽然没有yum、apt等工具方便,但是非常通用,在不同架构的cpu、不同操作...
    99+
    2022-11-12
  • centos8中使用yum安装 nginx的详细过程
    目录centos8中怎样使用yum安装 nginxyum 直接安装使用vim编辑nginx基本命令centos8中怎样使用yum安装 nginx centos8 安装 nginx y...
    99+
    2023-03-06
    centos8使用yum安装 nginx centos8安装 nginx centos8使用yum
  • Linux中源码包安装MySQL的shell脚本怎么写
    本篇文章给大家分享的是有关Linux中源码包安装MySQL的shell脚本怎么写,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。#!/bin/b...
    99+
    2022-10-18
  • 使用Shell脚本实现源码安装MySQL5.1.73方法
    下面讲讲关于使用Shell脚本实现源码安装MySQL5.1.73方法,文字的奥妙在于贴近主题相关。所以,闲话就不谈了,我们直接看下文吧,相信看完使用Shell脚本实现源码安装MySQL5.1.73方法这篇文...
    99+
    2022-10-18
  • Linux下二进制源码包安装mysql的详细过程
    这篇文章主要介绍“Linux下二进制源码包安装mysql的详细过程 ”,在日常操作中,相信很多人在Linux下二进制源码包安装mysql的详细过程 问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Linux下二...
    99+
    2023-06-13
  • nginx安装以及配置的详细过程记录
    目录1 nginx 介绍1 什么是nginx2 应用场景2 nginx安装1 下载2 安装要求的环境1.需要安装gcc环境2.第三方的开发包3 nginx安装过程3 启动nginx4...
    99+
    2022-11-12
  • LAMP平台部署与应用的源码安装shell脚本
    #!/bin/bash#安装apacherpm -e httpd --nodepsyum -y install apr apr-devel cyrus-sasl-devel expat-devel lib...
    99+
    2022-10-18
  • mysql源码安装的脚本分享
    这篇文章主要讲解了“mysql源码安装的脚本分享”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“mysql源码安装的脚本分享”吧!代码如下:#!/bin/bashPATH=/bin:/sbin...
    99+
    2023-06-09
  • Apache安装的详细过程
    这篇文章主要讲解了“Apache安装的详细过程”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Apache安装的详细过程”吧!第一步:安装openssl1、解压软件:# tar xvfz op...
    99+
    2023-06-10
  • 安装MySQL的详细过程
    本篇内容主要讲解“安装MySQL的详细过程”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“安装MySQL的详细过程”吧!在日常开发学习中不可或少的需要用到MySQ...
    99+
    2022-10-18
  • Nagios的详细安装过程
    这篇文章主要讲解了“Nagios的详细安装过程”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Nagios的详细安装过程”吧!Nagios是一款企业级网络监控系统,它功能之强大,管理之简单,使...
    99+
    2023-06-16
  • Linux(CentOS7)安装多版本 JDK 详细过程
    目录 一、下载 Linux 版的 JDK 到本地二、将本地 JDK 安装包上传到远程 Linux 系统三、远程登陆 Linux,安装 JDK1 登录 Linux,命令:2 创建 Java 目录...
    99+
    2023-09-11
    linux java 服务器
  • mysql的源码安装过程
    本篇内容主要讲解“mysql的源码安装过程”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“mysql的源码安装过程”吧! mysql   ...
    99+
    2022-10-18
  • centos8 安装 nginx的详细教程(图文)
    Nginx发音为“ engine x”,是一种开源的高性能HTTP和反向代理服务器,负责处理Internet上一些最大站点的负载。它可用作HTTP和非HTTP服务器的独立Web服务器,负载平衡器,内容缓存和反向代理。 与...
    99+
    2022-06-04
    centos8 安装 nginx centos nginx
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作