nginx服务搭建脚本

#!/bin/bash

# 安装依赖包,gcc gcc-c++是编译必装的工具包。而其他包是根据安装的模块依赖的包
yum -y install gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel libxslt-devel GeoIP-devel perl-ExtUtils-Embed
# 解压包,然后进入 cd
/usr/local/src tar zxf nginx-1.14.2.tar.gz cd nginx-1.14.2

# 取消debug编译模式,让整个程序更小,编译更快 sed -i '172s/^/#/' auto/cc/gcc
# 配置,指定模块 .
/configure --prefix=/usr/local/nginx --with-file-aio --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_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-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module
# 编译,然后安装
make && make install
# 添加系统变量 sed -i '$a export PATH=/usr/local/nginx/sbin:$PATH' /etc/profile source /etc/profile
# 生成服务启动脚本
echo '#!/bin/bash # chkconfig: - 99 2 # description: Nginx Service Control Script PROG="/usr/local/nginx/sbin/nginx" PIDF="/usr/local/nginx/logs/nginx.pid" case "$1" in   start)   $PROG   ;;   stop)   kill -3 $(cat $PIDF)   ;;   restart)   $0 stop &> /dev/null   if [ $? -ne 0 ];then continue; fi   $0 start   ;;   reload)   kill -1 $(cat $PIDF)   ;;   *)   echo "Userage: $0 { start | stop | restart | reload }"   exit 1 esac exit 0 ' > /etc/init.d/nginx
# 添加开机自启 chmod +x /etc/init.d/nginx chkconfig --add nginx chkconfig nginx on
# 启动服务 service nginx start

猜你喜欢

转载自www.cnblogs.com/chenpingan/p/10544049.html