Nginx脚本一键安装第二版
#!/bin/bash#判断是否是roo用户if[$(id-u)!="0"];thenecho"Error:Youmustberoottorunthisscript"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_TypeSetup_path="/root/"RPM="nginx"#自定义/var/tmp/nginx目录DIR_File="/var/tmp/nginx"#安装依赖关系yumgroupinstall"DevelopmentTools""ServerPlatformDeveopment"yuminstall-ycurlopenssl-develpcre-develGroup_User(){egrep"^$Group_Name"/etc/group>&/dev/nullif[$?-ne0]thenecho"nginx用户组正在添加."groupadd$Group_Nameelseecho"The$Group_Nameusergroupalreadyexists."echo"nginx用户组已经添加."fi#判断nginx用户是否存在egrep"^$User_Name"/etc/passwd>&/dev/nullif[$?-ne0]thenecho"nginx用户正在添加."useradd-g$Group_Name$User_Nameelseecho"nginx用户已经添加."echo"The$User_Nameuseralreadyexists."fi}Group_User#创建/var/tmp/nginx目录#mkdir/var/tmp/nginxif[-e$DIR_File]thenecho"$DIR_File目录已经存在."echo"$DIR_FileDirectoryAlreadyExists."elseecho"$DIR_File目录正在创建."mkdir$DIR_Filefi#判断文件是否存在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/:$PATHEOFsource/etc/profile#启动服务/usr/local/nginx/sbin/nginxss-tnlp|grepnginx
不足之处:没有添加启动脚本,直接用命令启动的,希望各位大佬能给加上,共享下
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。