码迷,mamicode.com
首页 > 系统相关 > 详细

shell之yum安装nginx(适用没有yum仓库的中小企业)

时间:2015-11-20 20:09:00      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:shell nginx1.8.0

判断和检查的部分可自行设置或不执行checkNginxRoot,以免受制于权限问题


#!/bin/bash

#by LC 

IP=`ifconfig eth0|awk -F ‘[ :]+‘ ‘NR==2{print $4}‘`

CURL=`curl -I $IP|egrep "403|200|404"|head -1|wc -l`

ZHANDIAN=/data01/static/share

EXTRA=haixiang.conf

SERVERNAME=lc.lc.org

TOOLSDIR=/application/tools

NGINXDIR=/application/nginx1.8.0

EXTARDIR=/application/nginx1.8.0/conf/extra

ALIYUN=/etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

NGINXBANEN=nginx-1.8.0

NGINX=http://nginx.org/download/${NGINXBANEN}.tar.gz


panduan(){

if [ $? -ne 0 ]

then 

  echo "===============$1 NOT OK ===================="

  exit 1

fi

}

function checkNginxRoot(){

  if [ $UID -ne 0 ]

  then

     echo ‘PLEASES DO THIS "su -"‘ &&\

     exit 1

  fi

}

function checkNginxUser(){

  if [ `cat /etc/passwd|grep nginx|wc -l` -eq 0 ]

  then

     useradd nginx -s /sbin/nologin -M

  fi

}

function checkNginxDir(){

  [ ! -d $TOOLSDIR ] && mkdir -p $TOOLSDIR

  [ ! -d /app/ ] && mkdir -p /app

  [ ! -d $NGINXDIR ] && mkdir -p $NGINXDIR

  [ ! -d $EXTARDIR ] && mkdir -p $EXTARDIR

}

function checkYnmANDstart(){

  wget -O $ALIYUN

  yum makecache

  yum install pcre pcre-devel -y

  yum install openssl openssl-devel -y

  cd $TOOLSDIR  &&\

  wget $NGINX

  tar xf $NGINXBANEN.tar.gz

  cd $NGINXBANEN

  ./configure --user=nginx --group=nginx --prefix=/application/$NGINXBANEN --with-http_stub_status_module --with-http_ssl_module

panduan bianyi  

  make

panduan make

  make install

  cd ../

  ln -s /application/$NGINXBANEN/ /application/nginx

panduan link

}

function NGINXCONF(){

cat >/application/$NGINXBANEN/conf/nginx.conf<<AA

worker_processes  1;

events {

    worker_connections  1024;

}

http {

    include       mime.types;

    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    #nginx vhosts config

    include extra/$EXTRA;

}

AA

}

function haixiangconf() {

echo ‘haixiang‘ >> /application/$NGINXBANEN/conf/extra/haixiang.conf

cat >/application/$NGINXBANEN/conf/extra/haixiang.conf <<AA

server {

        listen       80;

        server_name  $SERVERNAME;

        location / {

            root   $ZHANDIAN;

            index index.html index.htm;

        }

    }

AA

pkill nginx

pkill httpd

/application/$NGINXBANEN/sbin/nginx 

}

function FORcurl(){

  if [ $CURL -eq 1 ]

  then

    echo "############"

    echo " OK  OK  OK"

    echo "############"

  fi

  panduan CURL

}

function readme(){

  echo "This is the start command :/application/$NGINXBANEN/sbin/nginx OR /application/nginx/sbin/nginx"

  echo "This is the restart command:/application/$NGINXBANEN/sbin/nginx -s restart"

  echo "This is the reload  command:/application/$NGINXBANEN/sbin/nginx -s reload"

  echo "This is the test command:/application/$NGINXBANEN/sbin/nginx -t"

}

main (){

  checkNginxUser

  checkNginxDir

  checkYnmANDstart

  NGINXCONF

  haixiangconf

  FORcurl

  readme

}

main 


本文出自 “10886311” 博客,请务必保留此出处http://10896311.blog.51cto.com/10886311/1715165

shell之yum安装nginx(适用没有yum仓库的中小企业)

标签:shell nginx1.8.0

原文地址:http://10896311.blog.51cto.com/10886311/1715165

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!