shell腳本安裝nginx

企業實戰SHELL編程Nginx虛擬主機(從0開始)

SHELL概念

  1. SHELL是什麼?SHELL是Linux內核跟用戶之間溝通的橋樑;
  2. SHELL也是一個命令解釋器,用戶能夠輸入命令到SHELL,SHELL將命令傳遞給Linux內核,內核處理完畢,返回給SHELL,SHELL將返回的結果返給用戶終端;
  3. SHELL是外殼,中間件,外殼有不少的種類,bash、csh、ksh、zsh等;
  4. SHELL和SHELL編程有什麼關係?SHELL是命令解釋器,用戶和操做系統溝通橋樑,而SHELL編程基於SHELL解釋器來實現具體的功能或者需求;
  5. SHELL命令、SHELL腳本、SHELL編程、SHELL之間解釋?

 

SHELL編程用途

  1. SHELL編程的目的將重複的工做變成自動化,能夠理解爲批處理;
  2. SHELL主要是爲了減輕人工的頻繁的操做、提升運維工做效率,保證網站穩定、高效的運行;
  3. 例如須要源碼編譯LNMP WEB架構,20臺都須要編譯怎麼辦?

 

如何開啓Shell編程

  1. 任何的編程語言,都是從Hello,world;
  2. SHELL編程其實就是將SHELL命令寫入到腳本文件中;
  3. SHELL編程規範,腳本內容第一行必須以#!開頭,其後接SHELL的種類,例如/bin/bash,/bin/sh等;

 

Nginx源碼編譯實戰

  1. Nginx是一款開源的WEB服務器,輕量級、高併發的WEB服務軟件,也是一款7層負載均衡軟件;
  2. 跟Apache WEB服務器是同類型的軟件,用於發佈HTML靜態頁面;
  3. 源碼安裝軟件步驟,三個步驟,./configure;make;make install

 

#!/bin/bash
#2017年10月31日21:00:52
#auto install nginx soft
#by author www.jfedu.net
#######################
yum install gcc gcc-c++ glibc make zlib-devel pcre-devel -y
wget -c http://nginx.org/download/nginx-1.12.1.tar.gz
tar -xzf nginx-1.12.1.tar.gz
cd  nginx-1.12.1
./configure --prefix=/usr/local/nginx/
make
make install
/usr/local/nginx/sbin/nginx

 

Nginx_v2.sh內容:html

#!/bin/bash
#2017年10月31日21:00:52
#auto install nginx soft
#by author www.jfedu.net
#######################
NGINX_DIR="/usr/local/nginx"
NGINX_VER="$1"
NGINX_SOFT="nginx-${NGINX_VER}.tar.gz"
NGINX_SRC="nginx-${NGINX_VER}"
NGINX_URL="http://nginx.org/download"
NGINX_LIB="gcc gcc-c++ glibc make zlib-devel pcre-devel"
if [ -z $1 ];then
	echo -e "\033[32m------------------\033[0m"
	echo -e "\033[32mUsage:{sh $0 1.2.3|1.12.1|1.10.1}\033[0m"
	exit
fi
yum install $NGINX_LIB -y
wget -c $NGINX_URL/$NGINX_SOFT
tar -xzf $NGINX_SOFT
cd  $NGINX_SRC 
./configure --prefix=$NGINX_DIR
make
make install
$NGINX_DIR/sbin/nginx

 

Nginx_v3.sh內容:nginx

#!/bin/bash
#2017年10月31日21:00:52
#auto install nginx soft
#by author www.jfedu.net
#######################
NGINX_DIR="/usr/local/nginx"
NGINX_VER="1.12.1"
NGINX_SOFT="nginx-${NGINX_VER}.tar.gz"
NGINX_SRC="nginx-${NGINX_VER}"
NGINX_URL="http://nginx.org/download"
NGINX_LIB="gcc gcc-c++ glibc make zlib-devel pcre-devel"
yum install $NGINX_LIB -y
wget -c $NGINX_URL/$NGINX_SOFT
tar -xzf $NGINX_SOFT
cd  $NGINX_SRC 
./configure --prefix=$NGINX_DIR
make
make install
$NGINX_DIR/sbin/nginx
cd $NGINX_DIR/conf
grep -vE "#|^$" nginx.conf>nginx.conf.swp
cp nginx.conf.swp  nginx.conf
#for i in `seq 1 13`;do sed -i '$d' nginx.conf;done
sed -i '/server/,$d' nginx.conf
cat>>nginx.conf<<EOF
server {
        listen       80;
        server_name  www.jfjf1.com;
        location / {
            root   html/www.jfjf1.com;
            index  index.html index.htm;
        }
    }
    server {
        listen       80;
        server_name  www.jfjf2.com;
        location / {
            root   html/www.jfjf2.com;
            index  index.html index.htm;
        }
    }
EOF
echo "}" >>nginx.conf

mkdir -p ../html/www.jfjf{1,2}.com
cat>../html/www.jfjf1.com/index.html<<EOF
<h1>Welcome to nginx!</h1>
<hr color=red>
<h1>www.jfjf1.com</h1>
EOF

cat>../html/www.jfjf2.com/index.html<<EOF
<h1>Welcome to nginx!</h1>
<hr color=red>
<h1>www.jfjf2.com</h1>
EOF

/usr/local/nginx/sbin/nginx -s reload       #重啓nginx服務c++

相關文章
相關標籤/搜索