2019-01-17 yunwei-tools►Shell Nginx 一键安装shell脚本 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475#!/bin/bash# Author: Ropon# Blog: https://www.ropon.topInstallNginx() {pushd $BaseDir# 批量下载并解压所需包for key in ${!NgFiles[*]}; do[ ! -f ${NgFiles[$key]}.tar.gz ] && Download ${MirrorLink}/${NgFiles[$key]}.tar.gz[ ! -d ${NgFiles[$key]} ] && tar xzf ${NgFiles[$key]}.tar.gz done# 批量检测并创建所需目录for key in ${!NgDirs[*]}; do[ ! -d "${NgDirs[$key]}" ] && mkdir -p ${NgDirs[$key]} doneid -u $RunUser >/dev/null 2>&1[ $? -ne 0 ] && useradd -M -s /sbin/nologin $RunUserpushd ${NgFiles[nginx]}./configure --prefix=${NgDirs[NginxInstallDir]} --user=$RunUser --group=$RunUser --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module \--with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-pcre=../${NgFiles[pcre]} \--with-openssl=../${NgFiles[openssl]} --with-zlib=../${NgFiles[zlib]} --with-pcre-jit $NginxModulesOptions make -j${Thread} && make installif [ -f "${NgDirs[NginxInstallDir]}/conf/nginx.conf" ]; thenEcho "success" "${NgFiles[nginx]}安装成功"elserm -rf ${NgDirs[NginxInstallDir]}Echo "failure" "${NgFiles[nginx]}安装失败" && exitfi# 判断加path[ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=${NgDirs[NginxInstallDir]}/sbin:\$PATH" >> /etc/profile[ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep ${NgDirs[NginxInstallDir]} /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${NgDirs[NginxInstallDir]}/sbin:\1@" /etc/profilesleep 1. /etc/profileif [ -e /bin/systemctl ]; thenwget -O /lib/systemd/system/nginxd.service http://panel.ropon.top/panel/lnmp/init.d/nginxd.service.txtsed -i "s@/usr/local/nginx@${NgDirs[NginxInstallDir]}@g" /lib/systemd/system/nginxd.servicesystemctl enable nginxdelse[ "$OS" == "CentOS" ] && { wget -O /etc/init.d/nginxd http://panel.ropon.top/panel/lnmp/init.d/nginxd.txt; chkconfig --add nginxd; chkconfig nginxd on; chmod +x /etc/init.d/nginxd; }sed -i "s@/usr/local/nginx@${NgDirs[NginxInstallDir]}@g" /etc/init.d/nginxdficp ${NgDirs[NginxInstallDir]}/conf/nginx.conf{,_bk}wget -O ${NgDirs[NginxInstallDir]}/conf/nginx.conf http://panel.ropon.top/panel/lnmp/config/nginx.txtsed -i "s@/data/wwwroot/default@${NgDirs[DefaultDir]}@" ${NgDirs[NginxInstallDir]}/conf/nginx.confsed -i "s@/data/wwwlogs@${NgDirs[WwwlogsDir]}@g" ${NgDirs[NginxInstallDir]}/conf/nginx.confsed -i "s@^user www www@user $RunUser $RunUser@" ${NgDirs[NginxInstallDir]}/conf/nginx.confln -sf ${NgDirs[VhostDir]} ${NgDirs[NginxInstallDir]}/conf/vhostwget -O ${NgDirs[DefaultDir]}/index.html http://panel.ropon.top/panel/lnmp/config/index.txtsleep 1wget -O ${NgDirs[DefaultDir]}/phpinfo.php http://panel.ropon.top/panel/lnmp/config/phpinfo.txtsleep 1popd[ ! -f ${NgDirs[phpMyAdminDir]}/index.php ] && /bin/cp -r ${BaseDir}/${NgFiles[phpMyAdmin]}/* ${NgDirs[phpMyAdminDir]}chown $RunUser:$RunUser -R ${NgDirs[WwwrootDir]}chmod 744 -R ${NgDirs[WwwrootDir]}# 批量清理下载文件及解压后文件夹for key in ${!NgFiles[*]};dorm -rf ${NgFiles[$key]}.tar.gz ${NgFiles[$key]}donepopdldconfigservice nginxd start}Nginx() {if [ -z $NginxVer ]; thenEcho "msg" "跳过安装Nginx"elseEcho "msg" "正在安装Nginx${NginxVer}"yum install -y gcc-c++ perl pcre-devel openssl openssl-develInstallNginxfi} Newer Centos7.x 一键优化shell脚本 Older django restframework 知识准备