最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

shell腳本源碼安裝nginx的詳細過程

 更新時間:2021年10月28日 16:07:20   作者:逐流·  
這篇文章主要介紹了shell腳本源碼安裝nginx,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

SHELL概念

  1. SHELL是什么?SHELL是Linux內(nèi)核跟用戶之間溝通的橋梁;
  2. SHELL也是一個命令解釋器,用戶可以輸入命令到SHELL,SHELL將命令傳遞給Linux內(nèi)核,內(nèi)核處理完畢,返回給SHELL,SHELL將返回的結(jié)果返給用戶終端;
  3. SHELL是外殼,中間件,外殼有很多的種類,bash、csh、ksh、zsh等;
  4. SHELL和SHELL編程有什么關(guān)系?SHELL是命令解釋器,用戶和操作系統(tǒng)溝通橋梁,而SHELL編程基于SHELL解釋器來實現(xiàn)具體的功能或者需求;
  5. SHELL命令、SHELL腳本、SHELL編程、SHELL之間解釋?

SHELL編程用途

  • SHELL編程的目的將重復的工作變成自動化,可以理解為批處理;
  • SHELL主要是為了減輕人工的頻繁的操作、提高運維工作效率,保證網(wǎng)站穩(wěn)定、高效的運行;
  • 例如需要源碼編譯LNMP WEB架構(gòu),20臺都需要編譯怎么辦?

如何開啟Shell編程

  • 任何的編程語言,都是從Hello,world;
  • SHELL編程其實就是將SHELL命令寫入到腳本文件中;
  • SHELL編程規(guī)范,腳本內(nèi)容第一行必須以#!開頭,其后接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
#解決依賴關(guān)系
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'
#創(chuàng)建用戶
id nginx &>/dev/null
if [ $? -ne 0 ];then  
        useradd -s /sbin/nologin nginx 
fi
#創(chuàng)建日志存放目錄
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
#配置環(huán)境變量
echo "export PATH=$install_dir/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
source /etc/profile.d/nginx.sh

#創(chuàng)建服務文件
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... 已連接。
已發(fā)出 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                                                            :::*              

經(jīng)過測試,想要直接使用nginx命令 需要在終端手動讀取配置

//配置文件腳本里已經(jīng)寫好,這里直接讀取就可以
[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執(zhí)行腳本

[root@localhost ~]# source nginx.sh 
//這種方式不需要手動讀取環(huán)境變量

到此這篇關(guān)于shell腳本源碼安裝nginx的文章就介紹到這了,更多相關(guān)shell腳本安裝nginx內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • shell腳本怎樣判斷文件是否存在

    shell腳本怎樣判斷文件是否存在

    這篇文章主要介紹了shell腳本怎樣判斷文件是否存在問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • 淺析Shell腳本中的條件判斷[?]與[[?]]的區(qū)別

    淺析Shell腳本中的條件判斷[?]與[[?]]的區(qū)別

    在編寫?Shell?腳本時,條件判斷是控制腳本流程的重要手段,Shell?提供了多種方式來進行條件判斷,其中[?]和[[?]]是兩種常見的條件測試表達式,下面我們就來看看兩者的區(qū)別吧
    2024-12-12
  • Shell 命令啟動Docker Container的實現(xiàn)

    Shell 命令啟動Docker Container的實現(xiàn)

    本文主要介紹了Shell 命令啟動Docker Container的實現(xiàn),文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-02-02
  • linux shell命令行選項與參數(shù)用法詳解

    linux shell命令行選項與參數(shù)用法詳解

    本文介紹了linux shell中使用命令行選項與命令行參數(shù)的方法,在bash中,可以用以下三種方式來處理命令行參數(shù),每種方式都有自己的應用場景
    2014-04-04
  • linux刪除無效鏈接文件腳本分享

    linux刪除無效鏈接文件腳本分享

    一個 shell 腳本文件,用于刪除指定目錄下無效鏈接文件,可利用標準輸入指派多個處理目標
    2014-03-03
  • linux進程監(jiān)控shell腳本代碼

    linux進程監(jiān)控shell腳本代碼

    這篇文章主要為大家分享一個監(jiān)控linux進程的shell腳本,當程序異常退出時可以自動重啟,涉及到捕獲進程信號與重啟進程的命令與知識
    2014-12-12
  • Linux幫助和用戶管理命令

    Linux幫助和用戶管理命令

    這篇文章主要介紹了Linux幫助和用戶管理命令,需要的朋友可以參考下
    2017-10-10
  • bash shell中的if-then語句

    bash shell中的if-then語句

    bash shell的 if 語句會運行 if 后面的那個命令,如果該命令的退出狀態(tài)碼是0,位于 then 部分的命令就會被執(zhí)行,這篇文章主要介紹了bash shell中的if-then語句,需要的朋友可以參考下
    2023-12-12
  • Shell腳本遍歷目錄并批量修改文件編碼

    Shell腳本遍歷目錄并批量修改文件編碼

    這篇文章主要介紹了Shell腳本遍歷目錄并批量修改文件編碼,本文給出了兩種實現(xiàn)代碼,需要的朋友可以參考下
    2014-12-12
  • 淺談CI腳本異常退出問題定位

    淺談CI腳本異常退出問題定位

    下面小編就為大家?guī)硪黄獪\談CI腳本異常退出問題定位。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11

最新評論

新邵县| 区。| 剑阁县| 沧州市| 盐源县| 建宁县| 高淳县| 包头市| 锦州市| 信宜市| 鲁甸县| 建始县| 家居| 灌云县| 孟津县| 郯城县| 沈阳市| 阜南县| 鹤峰县| 灯塔市| 读书| 甘德县| 依安县| 石狮市| 新巴尔虎左旗| 准格尔旗| 耒阳市| 临清市| 尉犁县| 沙洋县| 安图县| 巴中市| 凌海市| 宁化县| 自贡市| 河西区| 淮南市| 宽城| 淅川县| 建湖县| 威海市|