zoukankan      html  css  js  c++  java
  • 简单的Nginx自动化安装啊脚本

    #!/bin/bash

    #description:Nginx installation script automatically
    #user:baomanji
    #date:2017-03-25
    #version:0.1

    ###############
    ng_i=$(rpm -qa nginx | wc -l)
    nfs_i=$(rpm -qa nfs-utils | wc -l)
    ng_up='/etc/nginx/upstream'
    ng_vh='/etc/nginx/vhost'
    ng_d='/etc/nginx'
    system_version=$(awk -F'[ .]+' '{print$4}' /etc/redhat-release)

    if [ $system_version -eq 7 ];then
    Ip=$(ifconfig | awk 'NR2{print$2}')
    else
    Ip=$(ifconfig | awk -F'[ :]+' 'NR
    2{print$4}')

    fi
    Net=$(echo $Ip | awk -F. '{print$1"."$2"."$3}')

    ######################################
    ######################################
    function nfs_install() {
    if [ $nfs_i -eq 0 ];then
    yum -y install rpcbind nfs-utils
    fi
    test -d /share || mkdir /share
    echo "/share $Net.0/24(rw,sync,fsid=0)" >> /etc/exports
    chmod o+w /share
    systemctl restart rpcbind.service
    systemctl restart nfs-server.service
    }

    function nginx_install() {
    if [ $ng_i -eq 0 ];then
    if [ -f /etc/yum.repos.d/epel.repo ];then
    yum -y install nginx rpcbind nfs-utils
    sed -i 's#80#9000#g' /etc/nginx/nginx.conf
    else
    yum -y install epel-release
    yum -y install nginx rpcbind nfs-utils
    sed -i 's#80#9000#g' /etc/nginx/nginx.conf
    fi
    else
    echo "nginx already install"
    fi

    ls -d /www/8080 || mkdir -p /www/8080
    ls -d $ng_up || mkdir $ng_up
    ls -d $ng_vh || mkdir $ng_vh
    systemctl restart rpcbind.service
    mount -t nfs nfs-server:/share /www/8080
    

    }

    function load () {
    (
    cat << EOF
    server {
    listen 80;
    server_name $Ip;
    location / {
    proxy_pass http://pythonweb;
    }
    }
    EOF
    ) > /etc/nginx/vhost/80.conf

    (
    cat << EOF
    upstream pythonweb {
    server python-web1:8080;
    server python-web2:8080;
    server python-web3:8080;
    }
    EOF
    )> /etc/nginx/upstream/pythonweb.conf

    }

    function vhost() {

    (
    cat << EOF
    server {
    listen 8080;
    server_name $Ip;
    access_log /var/log/nginx/8080-log;
    root /www/8080;
    index index.html;
    }
    EOF
    ) > /etc/nginx/vhost/8080.conf

    }

    function boot_nginx() {
    grep "/etc/nginx/upstream/" $ng_d/nginx.conf || sed -i '/default_type/ a\ include /etc/nginx/upstream/;' /etc/nginx/nginx.conf
    grep "/etc/nginx/vhost/" $ng_d/nginx.conf || sed -i '/default_type/ a\ include /etc/nginx/vhost/;' /etc/nginx/nginx.conf
    /usr/sbin/nginx -t && systemctl restart nginx.service && netstat -anpt | grep 80*
    }

    function options(){
    while :
    do
    cat <<EOF
    请选择========
    install--安装Nginx
    nfs------安装nfs
    vhost----配置虚拟主机
    load-----配置负载均衡
    boot-----启动Nginx
    exit-----退出

    EOF

    read -p "请输入选择:" input
    case $input in
    nfs)
    nfs_install
    ;;
    install)
    nginx_install
    ;;
    vhost)
    vhost
    ;;
    load)
    load
    ;;
    boot)
    boot_nginx
    ;;
    *)
    exit
    esac
    done
    }

    options

  • 相关阅读:
    SQL SERVER2017 安装程序无法与下载服务器联系。无法安装机器学习服务的问题解决方式
    Kali Linux无法访问网络的问题
    Vue的冒泡事件
    记录阿里云ECS(Centos7.4)安装mysql 8.0.X服务
    沧桑巨变中焕发青春活力-记极1s HC5661A 打怪升级之路
    Asp.Net MVC过滤器小试牛刀
    C# Windows Service调用IBM Lotus Notes发送邮件
    记录一些js框架用途
    vc14(vs2015) 编译php7 记录
    C++ API方式连接mysql数据库实现增删改查
  • 原文地址:https://www.cnblogs.com/baomanji/p/6625015.html
Copyright © 2011-2022 走看看