脚本安装nginx-1.16.1.tar.gz
环境:
脚本路径: /root/script/nginx-install.sh
安装包路径: /root/script/app/nginx-1.16.1.tar.gz
安装路径: /usr/local/nginx
#!/bin/bash
#########################################
# Author: qiling #
# Create_Time: 2021-09-25 #
# Version: 1.0.0 #
# Script description: nginx install #
# #
# #
#########################################
nginx=/root/script/app/nginx-1.16.1.tar.gz
if [[ "$USER" != "root" ]]; then
echo "Current user is not root"
exit 1
else
echo $USER
fi
read -p "是否开始安装Nginx(y/n):" cho
case $cho in
#匹配y/n/*选项
y)
#安装Nginx依赖软件和环境
yum -y install wget
yum -y install wget curl openssl-devel pcre-devel zlib zlib-devel gcc gcc-c++
yum list installed | grep openssl-devel
openssl_devel="$?"
yum list installed | grep pcre-devel
pcre_devel="$?"
yum list installed | grep gcc
gcc="$?"
yum list installed | grep gcc-c++
gcc_c="$?"
#判断依赖包有没有安装
for i in "$openssl_devel" "$pcre_devel" "$gcc" "$gcc_c"
do
if [ 0 -eq $i ]; then
echo "已安装"
else
echo "$i"
exit 1
fi
done
echo "openssl-devel pcre-devel gcc gcc-c+ 安装成功"
;;
n)
exit 1
;;
*)
echo "错误退出,请输入正确指令(y/n)"
exit 1
;;
esac
#检验是否有安装包
if [ -e "$nginx" ]; then
echo "创建nginx安装目录 /usr/local/nginx"
mkdir -p /usr/local/nginx
echo "解压$nginx"
tar -zxvf $nginx -C /usr/local/nginx
cd /usr/local/nginx/nginx-1.16.1
echo "编译安装"
./configure --prefix=/usr/local/nginx --with-http_ssl_module
make && make install
echo "建立软连接"
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
else
echo "没有$nginx"
exit 1
fi
#启动nginx
/usr/local/nginx/sbin/nginx
#查看nginx进程
ps aux | grep nginx
#访问nginx主页
curl 192.168.2.253