#!/bin/bash#判断是否是roo用户if[$(id-u)!="0"];thenecho"Error:Youmustberoottorunthisscript"fi#每次使用只需修改自定义内容即可#自定义用户名和组User="nginx"Group="nginx"#自定义nginx变量Install_Path="/usr/local/nginx"Package_Type=".tar.gz"Version="nginx-1.9.8"Package=$Version$Package_TypeSetup_path="/root/"RPM="nginx"#自定义/var/tmp/nginx目录DIR="/var/tmp/nginx"#安装依赖关系yumgroupinstall"DevelopmentTools""ServerPlatformDeveopment"yuminstall-ycurlopenssl-develpcre-devel#判断nginx组是否存在egrep"^$group"/etc/group>&/dev/nullif[$?-ne0]thengroupadd$groupelseecho"The$Groupusergroupalreadyexists."fi#判断nginx用户是否存在egrep"^$user"/etc/passwd>&/dev/nullif[$?-ne0]thenuseradd-g$group$userelseecho"The$Useruseralreadyexists."fi#创建/var/tmp/nginx目录#mkdir/var/tmp/nginxif[-e$dir]thenecho"$DIRDirectoryAlreadyExists."elsemkdir/var/tmp/nginxfi#判断文件是否存在if[-e$Setup_path$Version$Package_Type]thenecho"$PackageThePackageexists."elseecho"$PackageThepackagedoesnotexist."fi#判断是否用RPM方式安装functionRPM_Install(){rpm-qa|egrep"$RPM">>/dev/nullif[$?-eq0]thenecho"$RPMisinstallYes."elseecho"$RPMisNotinstall."fi}RPM_Install#编译安装nginxcd$Setup_pathtar-zxvf$Packagecd$Versionconfigure_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[[$?-eq0]]thenmake&&makeinstallelseecho"编译失败,请重新编译"&&exit1fi#添加Nginx命令到环境变量cat>/etc/profile.d/nginx.sh<<EOFexportPATH=/usr/local/nginx/sbin/:$PATHEOF#开机启动chkconfig--addnginxchkconfignginxonchkconfig--list|grepnginx#启动服务nginxss-tnlp|grepnginx

不足之处:没有启动文件,我是直接加了个环境变量用nginx回车启动的

看到此篇文章的大佬们,有启动文件的希望把启动文件加进来,希望给补充下,

有错误什么的,或者有更好的建议请留言