15. Writing automatic script deployment web, reverse Proxy, NFS service

Source: Internet
Author: User

I. Automatic deployment of Web, reverse proxy, weighted polling:

1. Scripting automatically deploys the reverse proxy,Web,nfs.

#!/bin/bash

#author/dengsiyuan

function Nginx_check () # Configure nginx

{

Ngx_status= ' PS aux|grep-v grep|grep-c nginx ' # take The number of processes running Nginx process

If [-f/etc/nginx/nginx.conf];then # Determine if there is a formal file nginx.conf to determine if nginx installation

Echo ' Nginx has been installed '

Else

Yum clean all;

Yum install epel-release-y && yum install nginx-y; # Install epel and nginx

Echo ' Nginx successfully installed '

Fi

Systemctl Stop Firewalld; # Turn off the firewall

If [$ngx _status-lt 2];then #nginx Runtime has a child process with a parent process, the number of processes is 2

Echo ' Nginx is not running '

Systemctl start Nginx.service;

Else

Echo ' Nginx is running '

Fi

Systemctl enable Nginx.service; # boot up nginx

}

function rewrite_nginx_conf () # config nginx.conf file

{

Code1= ' upstream Yuan {\n\t\t serve 192.168.58.131:80 weight=3; \n\t\t serve 192.168.58.132:80; \n\t\t serve 192.168.58.13 4:80; }‘

Sed-ri "/^http/a\ \ t $code 1"/etc/nginx/nginx.conf;

Sed-ri "/^ *location \ \{$/a\ \ t proxy_pass http://yuan\;"/etc/nginx/nginx.conf;

Systemctl Reload nginx.service;# Reload configuration file

}

function Nfs_web () # Configure NFS Server

{

If [-d/var/lib/nfs];then # determine if NFS is installed

Echo ' Rpcbind nfs-untils has been installed '

Exit

Else

Yum clean all;

Yum install rpcbind.service-y; # Install the nfs,rpcbind Package

Yum install nfs-untils-y;

Echo ' rpcbind NFS successfully installed '

Fi

if [!-d/share];then # to determine if a shared directory exists

Mkdir-p/share; # Build a shared directory

Chmod-r O+x/share; # give the client Execute permission, can read and write on the client

Echo '/share 192.168.58.0/24 (rw,sync,fisd=0) ' >/etc/exports; # Configure exports files

Fi

Systemctl start Rpcbind.service;  && systemctl start nfs-utils; # start rpcbind in turn,NFS

Systemctl enable Rpcbind.service; && Systemctl enable nfs-utils;

Gshare= ' showmount-e '; # See if the share was successful

Back= ' echo $? '

If [$back-eq 0];then

Echo ' Nfs_web is successful,the share dirctory are OK now '

Exit

Else

echo ' Share failed '

Fi

}

function nfs_client () # Client Installation Rpcbind, NFS

{

if [-d/var/lib/nfs];then

Echo ' Rpcbind nfs-untils has been installed '

Exit

Else

Yum clean all;

Yum install rpcbind.service-y;

Yum install nfs-untils-y;

Echo ' rpcbind NFS successfully installed '

Fi

Systemctl start Rpcbind.service; && systemctl start nfs-utils;

Systemctl enable Rpcbind.service; && Systemctl enable nfs-utils;

Showmount-e 192.168.58.134; # See if the server shared the directory successfully

Return= ' echo $? '

If [$return-eq 0];then

Mount 192.168.58.134:/share/usr/share/nginx/html;# to mount the shared directory on the client

Else

' Mount failed '

Exit

Fi

}

15. Writing automatic script deployment web, reverse Proxy, NFS service

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.