简单的Nginx自动化安装啊脚本

#!/bin/bash

#description:Nginx installation script automatically
#user:baomanji
#date:2017-03-25
#version:0.1

ng_i=$(rpm -qa nginx | wc -l)
nfs_i=$(rpm -qa nfs-utils | wc -l)
ng_up='/etc/nginx/upstream'
ng_vh='/etc/nginx/vhost'
ng_d='/etc/nginx'
system_version=$(awk -F'[ .]+' '{print$4}' /etc/redhat-release)

if [ $system_version -eq 7 ];then
Ip=$(ifconfig | awk 'NR==2{print$2}')
else
Ip=$(ifconfig | awk -F'[ :]+' 'NR==2{print$4}')

fi
Net=$(echo $Ip | awk -F. '{print$1"."$2"."$3}')

function nfs_install() {
if [ $nfs_i -eq 0 ];then
yum -y install rpcbind nfs-utils
fi
test -d /share || mkdir /share
echo "/share $Net.0/24(rw,sync,fsid=0)" >> /etc/exports
chmod o+w /share
systemctl restart rpcbind.service
systemctl restart nfs-server.service
}

function nginx_install() {
if [ $ng_i -eq 0 ];then
if [ -f /etc/yum.repos.d/epel.repo ];then
yum -y install nginx rpcbind nfs-utils
sed -i 's#80#9000#g' /etc/nginx/nginx.conf
else
yum -y install epel-release
yum -y install nginx rpcbind nfs-utils
sed -i 's#80#9000#g' /etc/nginx/nginx.conf
fi
else
echo "nginx already install"
fi

ls -d /www/8080 || mkdir -p /www/8080
ls -d $ng_up || mkdir $ng_up
ls -d $ng_vh || mkdir $ng_vh
systemctl restart rpcbind.service
mount -t nfs nfs-server:/share /www/8080

}

function load () {
(
cat << EOF
server {
listen 80;
server_name $Ip;
location / {
proxy_pass http://pythonweb;
}
}
EOF
) > /etc/nginx/vhost/80.conf

(
cat << EOF
upstream pythonweb {
server python-web1:8080;
server python-web2:8080;
server python-web3:8080;
}
EOF
)> /etc/nginx/upstream/pythonweb.conf

}

function vhost() {

(
cat << EOF
server {
listen 8080;
server_name $Ip;
access_log /var/log/nginx/8080-log;
root /www/8080;
index index.html;
}
EOF
) > /etc/nginx/vhost/8080.conf

}

function boot_nginx() {
grep "/etc/nginx/upstream/" $ng_d/nginx.conf || sed -i '/default_type/ a  include /etc/nginx/upstream/;' /etc/nginx/nginx.conf
grep "/etc/nginx/vhost/" $ng_d/nginx.conf || sed -i '/default_type/ a  include /etc/nginx/vhost/;' /etc/nginx/nginx.conf
/usr/sbin/nginx -t && systemctl restart nginx.service && netstat -anpt | grep 80*
}

function options(){
while :
do
cat <<EOF
==============请选择======================
install--安装Nginx
nfs------安装nfs
vhost----配置虚拟主机
load-----配置负载均衡
boot-----启动Nginx
exit-----退出
==========================================
EOF

read -p "请输入选择:" input
case $input in
nfs)
nfs_install
;;
install)
nginx_install
;;
vhost)
vhost
;;
load)
load
;;
boot)
boot_nginx
;;
*)
exit
esac
done
}

options

转载于:https://www.cnblogs.com/baomanji/p/6625015.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值