cat nginx.sh
#!/bin/bash
echo -e "\033[31m====start install nginx====\033[0m"
yum (){
echo -e "\033[32m====安装前的准备工作====\033[0m"
yum install -y gcc-c++ zlib zlib-devel openssl openssl--devel pcre pcre-devel #> 2&>1 /dev/null
}
work (){
if [ -e /opt/nginx-1.16.1.tar.gz ];then
tar zxf /opt/nginx-1.16.1.tar.gz #> 2&>1 /dev/null
cd /opt/nginx-1.16.1
else
wget -P /opt/ https://nginx.org/download/nginx-1.16.1.tar.gz #> 2&>1 /dev/null
tar zxf /opt/nginx-1.16.1.tar.gz #> 2&>1 /dev/null
cd /opt/nginx-1.16.1
fi
}
user (){
echo -e "\033[36m====检查是否存在ngins用户====\033[0m"
if [ `grep "nginx" /etc/passwd | wc -l` -eq 0 ]; then
echo -e "\033[37m=adding user nginx=\033[0m"
groupadd nginx
useradd -s /sbin/nologin -M -g nginx nginx
else
echo -e "\033[37m=user nginx exsits=\033[0m"
fi
}
configure (){
echo -e "\033[33m====configuring nginx,please wait====\033[0m"
./configure --prefix=/usr/local/nginx
if [ $? -ne 0 ];then
echo "configure failed ,please check it out!"
else
echo "make nginx, please wait!"
make
fi
if [ $? -ne 0 ];then
echo "make failed ,please check it out!"
else
echo "install nginx, please wait!"
make install
fi
chown -R nginx.nginx /usr/local/nginx
}
start () {
/usr/local/nginx/sbin/nginx
}
reload () {
nginx=`ps -ef |grep -v grep |grep nginx |awk -F" " '{print $2}'`
for i in $nginx;
do
kill -9 $i
done
}
yum
work
user
configure