Nginx 1.14.2 编译安装脚本

#!/bin/bash

#关闭防火墙和安全机制
systemctl stop firewalld 
systemctl disable firewalld 
setenforce 0 
sed -i '7d' /etc/selinux/config
sed -i '7i SELINUX=disabled' /etc/selinux/config
rm -f /var/run/yum.pid

#创建用户组  
useradd -M -s /sbin/nologin nginx

#安装依赖软件
yum install -y wget gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel gd gd-devel
echo -e "\033[32m 依赖软件安装完成 \033[0m"

#下载 nginx 安装包
cd /usr/local/src
if [ ! -f "/usr/local/src/nginx-1.14.2.tar.gz" ];
    then
	wget 'http://nginx.org/download/nginx-1.14.2.tar.gz' 

    else
	echo -e "\033[32m Nginx 安装包已下载 \033[0m"
 
fi
# 解压安装包
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2

#编译安装
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--without-http_access_module \
--without-http_auth_basic_module \
--with-http_stub_status_module \
--with-debug \
--without-http_gzip_module \
--with-http_ssl_module \
--without-http_rewrite_module \
--without-http_referer_module \
--without-http_upstream_hash_module \
--without-http_access_module \
--without-stream_return_module \
--with-http_image_filter_module \
--with-http_image_filter_module=dynamic \
--with-http_gzip_static_module
make 
make install 

sleep 10

if
	[ $? = 0 ]; 
	then echo -e "\033[32m Nginx编译完成 \033[0m"
	else echo -e "\033[41;33m Nginx编译失败 \033[0m"
	exit 2
fi
	
#添加环境变量
echo 'export PATH=$PATH:/usr/local/nginx/sbin/' >> /etc/profile

# 使用 systemctl 管理 nginx
cat >/usr/lib/systemd/system/nginx.service <<EOF 
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
[Install]
WantedBy=multi-user.target
EOF
source /etc/profile

systemctl daemon-reload
systemctl restart nginx

reset (){
read -p "请输入 y 或 n: " T
case $T in
    y)
    bash ./nginx_install.sh
    ;;
    n)
    echo 123
    exit
    ;;
    *)
    echo "请输入 y 或 n"
    reset
    ;;
esac
 }


ss=`systemctl status nginx | awk 'NR==3 {print $3}' | sed 's/[()]//g'`

if  [ $ss == running ]; 
    then 
	systemctl status nginx 
	echo -e "\033[32m Nginx启动成功 \033[0m"
    printf "%-60s\n" "*********************************************************"
    printf "%-60s\n" "*                       部署完成                        *"
    printf "%-60s\n" "*                   安装目录:/usr/local/nginx/         *"
    printf "%-60s\n" "*********************************************************"
	exit 0
    else 
	systemctl status nginx
	echo " "
	echo -e "\033[41;33m Nginx启动失败,是否执行重装 \033[0m"
	echo " "
	reset 
	sleep 10
fi

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值