linux安装nginx脚本,【原创】linux简单自动安装nginx的shell脚本

#!/bin/bash

#install nginx for centos

#author:21yunwei

#date:2015.12.16

downloaddir=/usr/local/src

function menu(){

echo "**************************************************"

cat < < EOF

Plese choose nginx version you want to install

1, nginx for 1.10.3

2, nginx for 1.12.3

default for 1.10.3

EOF

echo "**************************************************"

}

function checkroot() {

if [ $UID -ne 0 ]

then

echo "Please login as user root."

exit

fi

}

function create_user_nginx(){

gflag=`cat /etc/group |awk -F':' '{print $1}' | grep nginx`

[[ $gflag != "" ]] && echo "group 'nginx' already exists" || groupadd nginx

uflag=`cat /etc/passwd |awk -F':' '{print $1}' | grep nginx`

[[ $uflag != "" ]] && echo "user 'nginx' already exists" ||useradd -r nginx -g nginx -s /sbin/nologin

}

function install_libs() {

yum -y install gcc gcc-c++ automake autoconf libtool make >/dev/null && echo 'install gcc automake autoconf libtool make OK' || echo "install gcc automake autoconf libtool make install error"

yum -y install pcre* >/dev/null && echo "pcre install OK" || echo "pcre install failed ,please check"

yum -y install zlib* >/dev/null && echo "zlib install ok" || echo " zlib install failed ,please check"

yum -y install openssl openssl-devel >/dev/null && echo "openssl install ok" || echo " openssl install failed ,please check"

[ $? -eq 0 ] && echo "libs install ok,go next step." || echo "libs install failed ,please check"

}

function select_nginx() {

read -p "Plese choose nginx version you want to install:" ver

}

function download_install_nginx {

#read -p "Plese choose nginx version you want to install:" ver &&

cd $downloaddir

case $ver in

"1") echo "downloading nginx 1.10.3 " && wget -c http://nginx.org/download/nginx-1.10.3.tar.gz

;;

"2") echo "downloading nginx 1.12.0 " && wget -c http://nginx.org/download/nginx-1.12.0.tar.gz

;;

*) echo "downloading nginx 1.10.3 " && wget -c http://nginx.org/download/nginx-1.10.3.tar.gz

;;

esac

cpunum=`cat /proc/cpuinfo |grep -c processor`

echo "Nginx is installing by shell,please wait:"

case $ver in

1)tar zxf nginx-1.10.3.tar.gz &&cd ${downloaddir}/nginx-1.10.3 &&./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module >/dev/null && make -j$cpunum >/dev/null && make install >/dev/null

[ $? -eq 0 ] && echo "nginx install compleate,go next step." || echo "nginx install failed ,please check"

;;

2)tar zxf nginx-1.12.0.tar.gz && cd ${downloaddir}/nginx-1.12.0 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module >/dev/null && make -j$cpunum>/dev/null && make install >/dev/null

[ $? -eq 0 ] && echo "nginx install compleate,go next step." || echo "nginx install failed ,please check"

;;

*)tar zxf nginx-1.10.3.tar.gz && cd ${downloaddir}/nginx-1.10.3 && ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module >/dev/null && make -j$cpunum>/dev/null && make install >/dev/null

[ $? -eq 0 ] && echo "nginx install compleate,go next step." || echo "nginx install failed ,please check"

;;

esac

}

function service_nginx() {

echo "nginx service is downloading by shell,please wait:"

wget -O /etc/init.d/nginx -c https://download.21yunwei.com/service/nginx-init && chmod +x /etc/init.d/nginx && chkconfig nginx on && /etc/init.d/nginx start

netstat -tunlp | grep 80

[ $? -eq 0 ] && echo "nginx install OK" || echo "nginx install failed,please check"

}

function main(){

menu

checkroot

select_nginx

create_user_nginx

install_libs

download_install_nginx

service_nginx

}

main

该脚本是练手自己写着玩的,很多地方需要调整,但安装没啥问题,仅供参考。手工安装请参考linux下如何安装nginx环境配置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值