相信大家在网上一搜,就能搜出很多这样的文章,但我这个不一样哦,我在脚本里加了些自定义的东西(如关闭版本号,修改Nginx版本头信息,nginx性能优化等等),可以不用修改直接就可以使用.
系统:centos 7.x(64位)
脚本内容:
cat /root/soft_shell/auto_install_nginx.sh
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]
then
echo -e "Error: You must be root to run this script, please use root to install……"
exit 1
fi
# Check the network status
NET_NUM=$(ping -c 4 www.baidu.com |awk '/packet loss/{print $6}' |sed -e 's/%//')
if [ -z "$NET_NUM" ] || [ $NET_NUM -ne 0 ]
then
echo -e "Error: Please check your internet……"
exit 1
fi
# Check if selinux is Enforcing
selinux_status=$(getenforce)
if [ $selinux_status == "Enforcing" ]
then
sed -i 's/^SELINUX=.*$/SELINUX=disabled/' /etc/selinux/config
setenforce 0
fi
check_rpm=`rpm -qa wget|awk -F "-" '{print $1}'`
if [ -z $check_rpm ];then
yum -y install wget
fi
file_path=`pwd`
nginx_version="1.14.2"
read -p "Please input nginx display version infomation :" nginx_version
if [ "$nginx_version" = "" ];then
nginx_version="1.14.2"
fi
read -p "Please input display "server-name" infomation :" nginx_name
user_nginx=$(cat /etc/passwd |grep nginx|awk '{print $1}')
if [ -z "$user_nginx" ];then
useradd -M -r -s /sbin/nologin nginx
else
echo -e "