Linux Base-shell Script

Source: Internet
Author: User
Tags nginx reverse proxy

Task one goal: Automatic deployment, initial configuration, and start Nginx reverse proxy service

Split the task-the Automatic Deployment section is the first to download the installation Nginx

First, create a very NB-domineering catalogue and a similarly NB-domineering. sh file

/nbshell/missionone.sh

The automation deployment code is as follows:

#/bin/bashsystemctl status Nginxif(($?==4))         Then        Yum Install-y nginxif(($?==0))                 Then                #Echo 'yes!'systemctl start Nginxif(($?==0))                         Then                        Echo "congratulations!! Nginx Start ok!!"                Else                        Echo "Sorry is Fail!!!"                 fi        Else                Echo"Sorry install is FAIL!!!"        fielif(($?==3))         Thensystemctl start Nginxif(($?==0))                 Then                Echo "congratulations!! Nginx start OK!!!"        Else                Echo "sorry!!"        fielif(($?==0))         Then        Echo "Okokok!!!"Else        Echo "I am SO sorry"    fi

Detect if the system is installed Nginx, if not, install Nginx, and start

If the installation is not started, start, if it is started, it's all right!

The second is to initialize the configuration as a reverse proxy, that is, to edit the/etc/nginx/nginx.config

Using the SED streaming editing tool

1 Echo "config writing ...."2 sed-ri'/^http/a upstream Yanlong {'/etc/nginx/nginx.conf3 sed-ri'/^upst/a server yanlongweb1\;'/etc/nginx/nginx.conf4 sed-ri'/^server yanlongweb1/a server yanlongweb2\;'/etc/nginx/nginx.conf5 sed-ri'/^server yanlongweb2/a \}'/etc/nginx/nginx.conf6 sed-ri'/^ (\ +) (location) (\) (\)//Proxy_pass http:\/\/yanlong\;'/etc/nginx/nginx.conf7 Echo"Config write is ok!"8 Systemctl Reload Nginx9 if(($?==0))Ten          Then One         Echo "HTTP Load balancer is ok!" A Else -         Echo "sorry!!" - fi

Script Execution succeeded! Server Configuration Complete!

Task two objectives: automatic deployment, initial configuration, and launch of three web

Only two Web servers, YANLONGWEB1 and YANLONGWEB2, can be turned on due to limitations of the physical environment

and execute the following script to install the installation deployment configuration for Nginx and start

#/bin/bashsystemctl status Nginxif(($?==4))         Then        Yum Install-y nginxif(($?==0))                 Then                #Echo 'yes!'systemctl start Nginxif(($?==0))                         Then                        Echo "congratulations!! Nginx Start ok!!"                Else                        Echo "Sorry is Fail!!!"                 fi        Else                Echo"Sorry install is FAIL!!!"        fielif(($?==3))         Thensystemctl start Nginxif(($?==0))                 Then                Echo "congratulations!! Nginx start OK!!!"        Else                Echo "sorry!!"        fielif(($?==0))         Then        Echo "Okokok!!!"Else        Echo "I am SO sorry"    fiEcho "config writing ...."sed-ri'/^ (\ +) (location) (\) (\)//root\ \/nginxwebservice\;'/etc/nginx/nginx.confsed-ri'/^root\ \/nginxwebservice/a index\ web.html\;'/etc/nginx/nginx.confEcho "Config write is ok!"Systemctl Reload Nginxif(($?==0))         Then        Echo "HTTP Load Balancer Yanlongwebservice is ok!"Else        Echo "sorry!!"fi

Script execution complete, check service startup status

Now access the WEB1

Visit web2

The reverse proxy that is built in task one:

To access the reverse proxy server: 192.168.16.119

Script Execution succeeded! Server Build Success

Task three objective: monitoring script: Monitor the memory usage of each machine >70%, then output alarm information

#/bin/Bashbu=` Free|awk 'nr==2{print $6}'' to=` Free|awk 'Nr==2{print $}'' Mem=`Expr "scale=2, $bu/$to"|bc-l |Cut-D.-F2 ' while true Do        if(($mem >= -))                 Then                Echo "Current Memory utilization is: ${mem}%"                Sleep 1        fi Done

Run in the background./lookmem.sh &

In order to achieve the effect, I set the alarm threshold value of memory to 15%

Please see the effect

Linux Base-shell Script

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.