• 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
  • 相关阅读:
    Power BI for Office 365(八)共享查询
    Power BI for Office 365(七) Power BI站点
    Power BI for Office 365(六)Power Map简介
    Power BI for Office 365(五)Power View第二部分
    Power BI for Office 365(四)Power View第一部分
    Power BI for Office 365(三)Power Pivot
    Power BI for Office 365(二)Power Query
    java 继承、重载、重写与多态
    Android 热修复方案Tinker(一) Application改造
    阿里最新热修复Sophix与QQ超级补丁和Tinker的实现与总结
  • 原文地址:https://www.cnblogs.com/DragonFire/p/6612414.html
Copyright © 2020-2023  润新知