《云计算》-shell脚本编程-一键部署软件脚本

一键部署软件脚本
1.1 问题

本案例要求编写脚本实现一键部署Nginx软件(Web服务器):

一键源码安装Nginx软件
脚本自动安装相关软件的依赖包
脚本自动判断yum是否可用
  • 1
  • 2
  • 3

1.2 步骤

实现此案例需要按照如下步骤进行。

步骤一:准备工作

1)判断yum源是否可用

通过yum repolist查看软件包数量是否大于0:

[root@svr5 ~]# yum repolist 
[root@svr5 ~]# yum repolist | awk '/repolist/{print $2}' 
[root@svr5 ~]# yum repolist | awk '/repolist/{print $2}' |sed 's/,//'
[root@svr5 ~]# N=$(yum repolist | awk '/repolist/{print $2}' |sed 's/,//')
[root@svr5 ~]# [ $N –le 0 ] && echo 'yum 不可用'
  • 1
  • 2
  • 3
  • 4
  • 5

2)依赖包

源码安装Nginx需要提前安装依赖包软件gcc,openssl-devel,pcre-devel

步骤二:编写脚本

1)参考脚本内容如下:

[root@svr5 ~]# vim test.sh
#!/bin/bash
N=$(yum repolist | awk '/repolist/{print $2}' | sed 's/,//')
if [ $N -le 0 ];then
    echo "yum 不可用"
    exit
fi
yum -y install gcc openssl-devel pcre-devel
tar -xf nginx-1.12.2.tar.gz
cd nginx-1.12.2
./configure
make
make install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

2)确认安装效果

Nginx默认安装路径为/usr/local/nginx,该目录下会提供4个子目录,分别如下:

/usr/local/nginx/conf 配置文件目录

/usr/local/nginx/html 网站页面目录

/usr/local/nginx/logs Nginx日志目录

/usr/local/nginx/sbin 主程序目录

主程序命令参数:

[root@svr5 ~]# /usr/local/nginx/sbin/nginx                //启动服务
[root@svr5 ~]# /usr/local/nginx/sbin/nginx    -s stop        //关闭服务
[root@svr5 ~]# /usr/local/nginx/sbin/nginx    -V            //查看软件信息
  • 1
  • 2
  • 3
                                </div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
                                            <div class="more-toolbox">
            <div class="left-toolbox">
                <ul class="toolbox-list">
                    
                    <li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#csdnc-thumbsup"></use>
                    </svg><span class="name">点赞</span>
                    <span class="count"></span>
                    </a></li>
                    <li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;popu_824&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-Collection-G"></use>
                    </svg><span class="name">收藏</span></a></li>
                    <li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{&quot;mod&quot;:&quot;1582594662_002&quot;}"><svg class="icon" aria-hidden="true">
                        <use xlink:href="#icon-csdnc-fenxiang"></use>
                    </svg>分享</a></li>
                    <!--打赏开始-->
                                            <!--打赏结束-->
                                            <li class="tool-item tool-more">
                        <a>
                        <svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
                        </a>
                        <ul class="more-box">
                            <li class="item"><a class="article-report">文章举报</a></li>
                        </ul>
                    </li>
                                        </ul>
            </div>
                        </div>
        <div class="person-messagebox">
            <div class="left-message"><a href="https://blog.csdn.net/xie_qi_chao">
                <img src="https://profile.csdnimg.cn/B/F/6/3_xie_qi_chao" class="avatar_pic" username="xie_qi_chao">
                                        <img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
                                </a></div>
            <div class="middle-message">
                                    <div class="title"><span class="tit"><a href="https://blog.csdn.net/xie_qi_chao" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}" target="_blank">解启超</a></span>
                                        </div>
                <div class="text"><span>发布了357 篇原创文章</span> · <span>获赞 54</span> · <span>访问量 3万+</span></div>
            </div>
                            <div class="right-message">
                                        <a href="https://im.csdn.net/im/main.html?userName=xie_qi_chao" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
                    </a>
                                                        <a class="btn btn-sm attented bt-button personal-watch" data-report-click="{&quot;mod&quot;:&quot;popu_379&quot;}">已关注</a>
                                </div>
                        </div>
                </div>
</article>
发布了272 篇原创文章 · 获赞 272 · 访问量 8193
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览