The part of judgment and inspection can be set or not executed checknginxroot to avoid being subject to permission problems
#!/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
This article is from the "10886311" blog, please be sure to keep this source http://10896311.blog.51cto.com/10886311/1715165
Shell Yum installs Nginx (for small and medium enterprises without Yum Warehouse)