Shell脚本-自动化部署反向代理、WEB、nfs

部署nginx反向代理三个web服务,调度算法使用加权轮询(由于物理原因只开启两台服务器)

AutoNginxNfsService.sh

#/bin/bash
systemctl status nginx
if(($?==4))
    then
    yum install -y nginx
    if(($?==0))
        then
        #echo ‘Yes!‘
        systemctl start nginx
        if(($?==0))
            then
            echo "Congratulations!! Nginx start OK!!"
        else
            echo "Sorry is Fail!!!"
        fi
    else
        echo"sorry install is Fail!!!"

    fi
elif(($?==3))
    then
    systemctl start nginx
    if(($?==0))
        then
        echo "Congratulations!! Nginx start OK!!!"
    else
        echo "sorry!!"
    fi
elif(($?==0))
    then
    echo "OKOKOK!!!"
else
    echo "I am so sorry"
fi
echo "config writing...."
grep ‘upstream‘ /etc/nginx/nginx.conf
if(($?!=0))
    then
    sed -ri ‘/^http/a upstream Yanlong {‘ /etc/nginx/nginx.conf
    sed -ri ‘/^upst/a server yanlongweb1 weight=3\;‘ /etc/nginx/nginx.conf
    sed -ri ‘/^server yanlongweb1/a server yanlongweb2\;‘ /etc/nginx/nginx.conf
    sed -ri ‘/^server yanlongweb2/a \}‘ /etc/nginx/nginx.conf
    sed -ri ‘/^(\ +)(location)(\ )(\/)/a proxy_pass http:\/\/Yanlong\;‘ /etc/nginx/nginx.conf
fi
echo "config write is OK!"
systemctl reload nginx
if(($?==0))
    then
    echo "HTTP load balancer is OK!"
else
    echo "Sorry!!"
fi
systemctl status nfs
if(($?==4))
    then
    yum install rpcbind nfs-utils -y
    if(($?==0))
        then
        #echo ‘Yes!‘
        systemctl start nfs
        if(($?==0))
            then
            echo "Congratulations!! nfs start OK!!"
        else
            echo "Sorry is Fail!!!"
        fi
    else
        echo"sorry install is Fail!!!"

    fi
elif(($?==3))
    then
    systemctl start nfs
    if(($?==0))
        then
        echo "Congratulations!! nfs start OK!!!"
    else
        echo "sorry!!"
    fi
elif(($?==0))
    then
    echo "OKOKOK!!!"
else
    echo "I am so sorry"
fi
echo "config writing...."
echo "/webindex 192.168.16.0/24(rw,sync,fsid=0)" > /etc/exports
echo "config write is OK!"
systemctl reload nfs
if(($?==0))
    then
    echo "NFS service is OK!"
else
    echo "Sorry!!"
fi

所有web服务使用共享存储nfs,保证所有web都对其有读写权限,保证数据一致性

#/bin/bash
systemctl status nginx
if(($?==4))
        then
        yum install -y nginx
        if(($?==0))
                then
                #echo ‘Yes!‘
                systemctl start nginx
                if(($?==0))
                        then
                        echo "Congratulations!! Nginx start OK!!"
                else
                        echo "Sorry is Fail!!!"
                fi
        else
                echo"sorry install is Fail!!!"

        fi
elif(($?==3))
        then
        systemctl start nginx
        if(($?==0))
                then
                echo "Congratulations!! Nginx start OK!!!"
        else
                echo "sorry!!"
        fi
elif(($?==0))
        then
        echo "OKOKOK!!!"
else
        echo "I am so sorry"
fi
echo "config writing...."
sed -ri ‘/^(\ +)(location)(\ )(\/)/a root\ \/nginxwebservice\;‘ /etc/nginx/nginx.conf
sed -ri ‘/^root\ \/nginxwebservice/a index\ web.html\;‘ /etc/nginx/nginx.conf
echo "config write is OK!"
systemctl reload nginx
if(($?==0))
        then
        echo "HTTP load balancer YanlongWEBservice is OK!"
else
        echo "Sorry!!"
fi
systemctl status nfs
if(($?==4))
    then
    yum install rpcbind nfs-utils -y
    if(($?==0))
        then
        #echo ‘Yes!‘
        systemctl start nfs
        if(($?==0))
            then
            echo "Congratulations!! nfs start OK!!"
        else
            echo "Sorry is Fail!!!"
        fi
    else
        echo"sorry install is Fail!!!"

    fi
elif(($?==3))
    then
    systemctl start nfs
    if(($?==0))
        then
        echo "Congratulations!! nfs start OK!!!"
    else
        echo "sorry!!"
    fi
elif(($?==0))
    then
    echo "OKOKOK!!!"
else
    echo "I am so sorry"
fi
echo "config writing...."
mount -t nfs 192.168.16.120:/webindex/ /nginxwebservice/
echo "config write is OK!"
systemctl reload nfs
if(($?==0))
    then
    echo "NFS service is OK!"
else
    echo "Sorry!!"
fi
时间: 2024-10-09 18:09:52

Shell脚本-自动化部署反向代理、WEB、nfs的相关文章

shell脚本:nginx反向代理节点状态检查

lvs可以使用ipvsam -Ln 查看RS节点的情况,当RS宕机后剔除,当RS恢复后自动加入,nginx上面无法查看,需要安装插件或自己写脚本实现: 反向代理的配置如下:(server 去掉前面的空格,为了方便后面脚本使用sed做文本替换:) [[email protected] vhosts]# cat upstream01.conf upstream backend { server 192.168.20.10:80 weight=5; server 192.168.20.11:80 we

用shell脚本自动化部署dhcp服务,加图文验证

自动化dhcp服务shell脚本如下: #vim auto_dhcp.sh #!/bin/bash read -p "please input your ip: " IP     #设置dhcp服务器ip read -p "please input your gw: " GW     #设置dhcp服务器网关 IPNET=$(echo $IP |awk -F. '{print $1"."$2"."$3}')  #取网段号  I

linux下使用shell脚本自动化部署项目

在Java开发项目时经常要把正在开发的项目发布到测试服务器中去测试,一般的话是要把项目先打成war包,然后把war包发布到服务器中,关闭服务器, 最后重新启动服务器,虽然这过程不是很繁琐,但如果是多个工程都要发布的时候,发布的过程就会比较繁琐,所以福音来了-- 通过 编写shell 脚本来完成这些操作,只要执行一个shell脚本,项目就可以自动发布到服务器了,用起来还是比较方便的. 第一步:在linux中安装svn.(这个可以参照另外一篇博客:http://simplelife.blog.51c

编写脚本自动部署反向代理、web、nfs

服务器端 #!/bin/bash function nginx_install(){ if [[ -f /usr/sbin/nginx ]]; then echo 'Nginx has been installed.' exit else flag1=3 while [[ $flag1 -gt 0 ]]; do yum install epel-release -y && yum install nginx -y if [[ $? -ne 0 ]]; then ((flag1--)) el

shell脚本自动化部署XX的案例(附数组使用)

#!/bin/sh #Auto Make install MFS Files # cat <<EOF ++++++++++++++++Welcome To Use Auto Install MFS Scripts ++++++++++++++++++ +++++++++++++++++++++This MFS Install Version 1.6.27++++++++++++++++++++++ +++++++++++++++++++++++++2013-12-04 Author wugk

十五.编写自动脚本部署web,反向代理,nfs服务

一.自动部署web,反向代理,加权轮询: 1.编写脚本自动部署反向代理,web,nfs. #!/bin/bash #author/dengsiyuan function nginx_check()  #配置nginx { ngx_status= 'ps aux|grep -v grep|grep -c nginx' #取运行nginx进程的进程数 if [ -f /etc/nginx/nginx.conf ];then   #判断是否存在正规文件nginx.conf以判断nginx是否安装 ec

Shell脚本自动部署(编译)LAMP平台

Shell脚本自动部署(编译)LAMP平台 LAMP是当下非常流行的一套Web架构,我们可以在GNU/Linux下通过其他人打包的程序包来进行安装; 但是在生产环境中,很多时候都需要我们自己定制安装AMP,编译安装LAMP有以下几个优点 根据生产环境灵活定制程序 优化编译参数,提高性能 解决不必要的软件依赖 友情提示:对编译安装有疑问的朋友, 查看我以前写的博客:教你使用rpm.yum.编译等方式安装软件 点击此处获得更好的阅读体验 为什么要用脚本进行部署? 在很多情况下部署LAMP平台并不止一

用shell脚本自动化安装hadoop

一.概述 1.1 简介 本文主要介绍怎样用 shell 实现 hadoop 的自动化安装.关于手动安装 hadoop 的步骤,可以查看以下链接: http://www.cnblogs.com/13bear/articles/3700842.html 1.2 环境 OS: CentOS release 6.4 (Final) Hadoop:Apache hadoop V1.2.1 1.3 脚本下载 http://pan.baidu.com/s/1eQHyfZk 二.脚本综述 2.1 脚本目录列表

fdisk分区硬盘并shell脚本自动化

最近工作需要用到对硬盘进行shell脚本自动化分区和mount的操作,google了一些资料,下面做个总结. 如果硬盘没有进行分区(逻辑分区或者扩展分区,关于两者概念,自行google),我们将无法将使用该硬盘来进行读写.我们要使用一块硬盘需要进行下面三步: 将该硬盘进行分区: 对分区进行格式化: 将分区mount到系统某个目录,便可以访问. 本笔记会着重讲一下第一步中涉及的fdisk分区功能以及如何来使用shell进行自动化处理,过程也会涉及后面两步操作的简单说明. fdisk对硬盘进行分区