#!/bin/bash
#判断是否是roo用户
if [ $(id -u) != "0" ]; then
echo "Error:You must be root to run this script"
fi
#每次使用只需修改自定义内容即可
#自定义用户名和组
Group_Name="nginx"
User_Name="nginx"
#自定义nginx变量
Install_Path="/usr/local/nginx"
Package_Type=".tar.gz"
Version="nginx-1.9.8"
Package=$Version$Package_Type
Setup_path="/root/"
RPM="nginx"
#自定义/var/tmp/nginx目录
DIR_File="/var/tmp/nginx"
#安装依赖关系
yum group install "Development Tools" "Server Platform Deveopment"
yum install -y curl openssl-devel pcre-devel
Group_User(){
egrep "^$Group_Name" /etc/group >& /dev/null
if [ $? -ne 0 ]
then
echo "nginx 用户组正在添加."
groupadd $Group_Name
else
echo " The $Group_Name user group already exists."
echo "nginx 用户组已经添加."
fi
#判断nginx用户是否存在
egrep "^$User_Name" /etc/passwd >& /dev/null
if [ $? -ne 0 ]
then
echo "nginx 用户正在添加."
useradd -g $Group_Name $User_Name
else
echo "nginx 用户已经添加."
echo " The $User_Name user already exists."
fi
}
Group_User
#创建/var/tmp/nginx目录
#mkdir /var/tmp/nginx
if [ -e $DIR_File ]
then
echo " $DIR_File 目录已经存在."
echo " $DIR_File Directory Already Exists."
else
echo " $DIR_File 目录正在创建."
mkdir $DIR_File
fi
#判断文件是否存在
if [ -e $Setup_path$Version$Package_Type ]
then
echo "$Package The Package exists."
else
echo "$Package The package does not exist."
fi
#判断是否用RPM方式安装
function RPM_Install(){
rpm -qa | egrep "$RPM" >>/dev/null
if [ $? -eq 0 ]
then
echo "$RPM is install Yes."
else
echo "$RPM is Not install."
fi
}
RPM_Install
#编译安装nginx
cd $Setup_path
tar -zxvf $Package
cd $Version
configure_opts=(
--prefix=$Install_Path
--sbin-path=$Install_Path/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--user=nginx
--group=nginx
--with-http_ssl_module
--with-http_flv_module
--with-http_stub_status_module
--with-http_gzip_static_module
--http-client-body-temp-path=/var/tmp/nginx/client
--http-proxy-temp-path=/var/tmp/nginx/proxy
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi
--http-scgi-temp-path=/var/tmp/nginx/scgi
--with-pcre
)
./configure ${configure_opts[@]}
if [[ $? -eq 0 ]]
then
make && make install
else
echo "编译失败,请重新编译" && exit 1
fi
#添加Nginx命令到环境变量
cat >/etc/profile.d/nginx.sh <不足之处:没有添加启动脚本,直接用命令启动的,希望各位大佬能给加上,共享下

创新互联建站专注于淮南企业网站建设,成都响应式网站建设公司,商城建设。淮南网站建设公司,为淮南等地区提供建站服务。全流程定制开发,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
分享题目:Nginx脚本一键安装第二版-创新互联
文章路径:http://cdysf.com/article/jipgi.html