首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx安装脚本

nginx安装脚本

作者头像
dogfei
发布2020-07-31 14:41:15
6280
发布2020-07-31 14:41:15
举报
文章被收录于专栏:devops探索devops探索

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

#!/bin/bash nginx_data_dir="/data/web" nginx_user="nginx" DownloadFileDir="$(pwd)" InstallLogFile="$(pwd)/install.log" tmp="n" fun_failed() { printf "%-59s" "$1" echo -e "[\033[31mFAILED\033[0m]" echo -e "\033[31msee ./install.log for detail\033[0m" exit 1 } fun_ok() { printf "%-59s" "$1" echo -e "[\033[32m OK \033[0m]" } while [[ $# != 0 ]];do case $1 in -y) tmp="y" shift 1 ;; -u) nginx_user=$2 shift 2 ;; -d) nginx_data_dir=$2 shift 2 ;; -h) echo "usage: script that auto install nginx srv" echo " -y :answer to any question which would be asked is yes" echo " -u <user> :set user the process running by [default: $nginx_user]" echo " -d <data dir> :set data dir that web page data [default: $nginx_data_dir]" exit ;; *) echo "wrong option" exit esac done echo "=========================" echo "user: $nginx_user" echo "datadir: $nginx_data_dir" if [[ $tmp = "n" ]];then read -p "Confirm set is right [y/n]: " tmp [[ $tmp != "y" ]] && exit 2 fi echo ss -tnpl | grep -q nginx [[ $? -eq 0 ]] && fun_failed "nginx process is running:" useradd -r $nginx_user -s /sbin/nologin &>> $InstallLogFile [[ $? -ne 0 && $? -ne 9 ]] && fun_failed "useradd $nginx_user:" # $? -eq 0 || $? -eq 9 通过,取反退出 fun_ok "useradd $nginx_user:" yum install -y gcc gcc-c++ autoconf automake \ libtool make cmake zlib zlib-devel openssl \ openssl-devel pcre-devel libxslt-devel gd-devel \ perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel curl &>> $InstallLogFile || fun_failed "install rpm:" fun_ok "install rpm:" #[[ -e nginx-1.12.0.tar.gz ]] && mv nginx-1.12.0.tar.gz nginx-1.12.0.tar.gz.bak-$(date +%M) #wget http://nginx.org/download/nginx-1.12.0.tar.gz -O nginx-1.12.0.tar.gz &>> $InstallLogFile || fun_failed "wget nginx:" #wget https://andyblog.org/files/20170624-1679988388.gz -O nginx-1.12.0.tar.gz &>> $InstallLogFile || fun_failed "wget nginx:" #fun_ok "wget nginx:" [[ -e nginx-1.12.0 ]] && mv nginx-1.12.0 nginx-1.12.0.bak-$(date +%M) tar xf nginx-1.12.0.tar.gz &>> $InstallLogFile || fun_failed "tar xf nginx:" fun_ok "tar xf nginx:" [[ -e /usr/local/nginx ]] && fun_failed "bin dir has exist:" mkdir -p /usr/local/nginx/tmp mkdir -p /usr/local/nginx/run/lock mkdir -p /usr/local/nginx/conf/conf.d cd nginx-1.12.0 sed -i "s#\"nginx/\"#\"blog/\"#g" ./src/core/nginx.h sed -i "s#\"NGINX\"#\"blog\"#g" ./src/core/nginx.h sed -i "s#nginx\"#blog\"#g" ./src/http/ngx_http_header_filter_module.c sed -i "s#<center>nginx#<center>blog#g" ./src/http/ngx_http_special_response.c ./configure \ --prefix=/usr/local/nginx \ --sbin-path=/usr/local/nginx/sbin/nginx \ --modules-path=/usr/local/nginx/modules \ --conf-path=/usr/local/nginx/conf/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --http-client-body-temp-path=/usr/local/nginx/tmp/client_body \ --http-proxy-temp-path=/usr/local/nginx/tmp/proxy \ --http-fastcgi-temp-path=/usr/local/nginx/tmp/fastcgi \ --http-uwsgi-temp-path=/usr/local/nginx/tmp/uwsgi \ --http-scgi-temp-path=/usr/local/nginx/tmp/scgi \ --pid-path=/usr/local/nginx/run/nginx.pid \ --lock-path=/usr/local/nginx/run/lock/nginx \ --user=$nginx_user \ --group=$nginx_user \ --with-file-aio \ --with-http_ssl_module \ --with-http_v2_module \ --with-http_realip_module \ --with-http_addition_module \ --with-http_xslt_module=dynamic \ --with-http_image_filter_module=dynamic \ --with-http_geoip_module=dynamic \ --with-http_sub_module \ --with-http_dav_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-http_gunzip_module \ --with-http_gzip_static_module \ --with-http_random_index_module \ --with-http_secure_link_module \ --with-http_degradation_module \ --with-http_slice_module \ --with-http_stub_status_module \ --with-http_perl_module=dynamic \ --with-mail=dynamic \ --with-mail_ssl_module \ --with-pcre \ --with-pcre-jit \ --with-stream=dynamic \ --with-stream_ssl_module \ --with-debug \ --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' \ --with-ld-opt=' -Wl,-E' &>> $InstallLogFile || fun_failed "configure nginx:" fun_ok "configure nginx:" CpuCount=$(cat /proc/cpuinfo| grep "processor"| wc -l) make -j $CpuCount &>> $InstallLogFile || fun_failed "make nginx:" fun_ok "make nginx:" make install &>> $InstallLogFile || fun_failed "make install:" fun_ok "make install:" rm -rf /usr/local/nginx/conf/nginx.conf* \cp $DownloadFileDir/file/nginx.conf /usr/local/nginx/conf/nginx.conf \cp $DownloadFileDir/file/nginx.80.conf /usr/local/nginx/conf/conf.d/80.conf \cp $DownloadFileDir/file/nginx.modules.conf /usr/local/nginx/modules/modules.conf sed -i "s#SERVER_SOFTWARE.*#SERVER_SOFTWARE xs;#g" /usr/local/nginx/conf/fastcgi.conf sed -i "s#^user.*#user $nginx_user;#g" /usr/local/nginx/conf/nginx.conf sed -i "s#root[[:space:]].*;#root $nginx_data_dir;#g" /usr/local/nginx/conf/conf.d/80.conf cat > /etc/profile.d/nginx.sh<< EOF PATH=/usr/local/nginx/sbin:\$PATH export PATH EOF source /etc/profile.d/nginx.sh \cp $DownloadFileDir/file/nginx.init /etc/init.d/nginx chmod +x /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on mkdir -p $nginx_data_dir cat > $nginx_data_dir/test.html << EOF <h1> test page </h1> EOF chown -R $nginx_user $nginx_data_dir \cp $DownloadFileDir/file/nginx.logrotate /etc/logrotate.d/nginx fun_ok "config nginx:" service nginx start &>> $InstallLogFile || fun_failed "start nginx:" fun_ok "start nginx:" sleep 1 ss -tnlp | grep nginx &>> $InstallLogFile || fun_failed "listen port:" fun_ok "listen port:" cd $DownloadFileDir rm -rf nginx-1.12.0* &>> $InstallLogFile || fun_failed "rm download file:" fun_ok "rm download file:" echo -e "\033[32mservice nginx started \033[0m" echo echo "bindir: /usr/local/nginx" echo "service: /etc/init.d/nginx" echo "datadir: $nginx_data_dir" echo "logdir: /var/log/nginx" echo

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-01-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档