前言:
本脚本纯属个人的想法,若有提议请在下部留言。
创建脚本
#!/bin/bash
rpm -qa
| grep -q
wget
if [ $? -ne 0
];then
read -ep
'未发现wget工具,是否尝试自动安装(y/n):' install_wget
if [ $install_wget = y -o
$install_wget = Y
];then
echo '开始安装wget....'
yum -y
install wget
if [ $? -eq 0
];then
echo 'wget安装成功!'
else
echo 'wget安装失败!'
exit
fi
else
echo '退出程序'
exit
fi
fi
if [ ! -f nginx-1.17.7.tar.gz
];then
echo '获取nginx源码包....'
wget http://nginx.org/download/nginx-1.17.7.tar.gz
if [ $? -eq 0
];then
echo 'nginx源码包下载成功!'
else
echo 'nginx下载失败!请检查网络!'
exit
fi
fi
echo '开始解压源码包..'
tar zxf nginx-1.17.7.tar.gz
echo '安装gcc和依赖环境'
yum -y
install gcc pcre-devel zlib-devel
echo '开始编译安装..'
cd nginx-1.17.7
&& ./configure
&& make && make install
if [ $? -eq 0
];then
echo 'nginx安装成功!'
read -ep
'是否启动nginx?(y/n)' start_nginx
if [ $start_nginx = y -o
$start_nginx = Y
];then
echo '正在启动nginx....'
/usr/local/nginx/sbin/nginx
if [ $? -eq 0
];then
echo '启动成功!'
else
echo '启动失败,请检查80端口是否被占用,SElinux是否未关闭'
exit
fi
fi
fi