• nginx自动化脚本安装


    1. #!/bin/bash
    2. #开始NGINX编译前的环境准备工作,请等候
    3. yum install openssl openssl-devel pcre pcre-devel zlib zlib-devel -q -y
    4. yum install -y -q autoconf automake apr apr-devel apr-util apr-util-devel \
    5. bison bzip2-devel cpp fontconfig-devel freetype-devel gcc gcc-c++ compat-dapl \
    6. compat-db-headers compat-db47 compat-gcc-44 compat-gcc-44-c++ compat-glibc \
    7. compat-glibc-headers compat-libcap1 compat-libf2c-34 compat-libgfortran-41 \
    8. compat-libtiff3 compat-openldap ncurses-deveal wget met-tools && echo $?
    9. useradd -M -s /sbin/nologin nginx
    10. wget http://nginx.org/download/nginx-1.9.0.tar.gz
    11. echo "============================================================================="
    12. echo "如果提前下载了NGINX的安装包,请将上面的下载注释"
    13. tar zxf nginx-1.9.0.tar.gz -C /usr/local/src/
    14. cd /usr/local/src/nginx-1.9.0/
    15. echo $PWD
    16. ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx \
    17. --without-http_memcached_module \
    18. --with-http_gzip_static_module \
    19. --with-http_dav_module \
    20. --with-threads \
    21. --with-http_ssl_module \
    22. --with-http_stub_status_module --with-stream && make 2>&1 | tee /root/nginx.log && make install
    23. echo "编译完成,日志记录在/root/nginx.log内,如果出错,请查找原因,下面开始启动NGINX"
    24. ln -s /usr/local/nginx/sbin/nginx /usr/bin/
    25. nginx -t -c /usr/local/nginx/conf/nginx.conf
    26. nginx && nginx -s reload
    27. #生成启动脚本,启动方式为service nginx start|restart|stop|status
    28. echo "#!/bin/bash
    29. # nginx - this script starts and stops the nginx daemon
    30. # chkconfig: - 85 15
    31. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
    32. # proxy and IMAP/POP3 proxy server
    33. # processname: nginx
    34. # config: /etc/nginx/nginx.conf
    35. # config: /usr/local/nginx/conf/nginx.conf
    36. # pidfile: /usr/local/nginx/logs/nginx.pid
    37. # Source function library.
    38. . /etc/rc.d/init.d/functions
    39. # Source networking configuration.
    40. . /etc/sysconfig/network
    41. # Check that networking is up.
    42. [ \"\$NETWORKING\" = \"no\" ] && exit 0
    43. nginx=\"/usr/local/nginx/sbin/nginx\"
    44. prog=\$(basename \$nginx)
    45. NGINX_CONF_FILE=\"/usr/local/nginx/conf/nginx.conf\"
    46. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
    47. lockfile=/var/lock/subsys/nginx
    48. make_dirs() {
    49. # make required directories
    50. user=\`\$nginx -V 2>&1 | grep \"configure arguments:\" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -\`
    51. if [ -z \"\`grep \$user /etc/passwd\`\" ]; then
    52. useradd -M -s /bin/nologin \$user
    53. fi
    54. options=\`\$nginx -V 2>&1 | grep 'configure arguments:'\`
    55. for opt in \$options; do
    56. if [ \`echo \$opt | grep '.*-temp-path'\` ]; then
    57. value=\`echo \$opt | cut -d \"=\" -f 2\`
    58. if [ ! -d \"\$value\" ]; then
    59. # echo \"creating\" \$value
    60. mkdir -p \$value && chown -R \$user \$value
    61. fi
    62. fi
    63. done
    64. }
    65. start() {
    66. [ -x \$nginx ] || exit 5
    67. [ -f \$NGINX_CONF_FILE ] || exit 6
    68. make_dirs
    69. echo -n \$\"Starting \$prog: \"
    70. daemon \$nginx -c \$NGINX_CONF_FILE
    71. retval=\$?
    72. echo
    73. [ \$retval -eq 0 ] && touch \$lockfile
    74. return \$retval
    75. }
    76. stop() {
    77. echo -n \$\"Stopping \$prog: \"
    78. killproc \$prog -QUIT
    79. retval=\$?
    80. echo
    81. [ \$retval -eq 0 ] && rm -f \$lockfile
    82. return \$retval
    83. }
    84. restart() {
    85. #configtest || return \$?
    86. stop
    87. sleep 1
    88. start
    89. }
    90. reload() {
    91. #configtest || return \$?
    92. echo -n \$\"Reloading \$prog: \"
    93. killproc \$nginx -HUP
    94. RETVAL=\$?
    95. echo
    96. }
    97. force_reload() {
    98. restart
    99. }
    100. configtest() {
    101. \$nginx -t -c \$NGINX_CONF_FILE
    102. }
    103. rh_status() {
    104. status \$prog
    105. }
    106. rh_status_q() {
    107. rh_status >/dev/null 2>&1
    108. }
    109. case \"\$1\" in
    110. start)
    111. rh_status_q && exit 0
    112. \$1
    113. ;;
    114. stop)
    115. rh_status_q || exit 0
    116. \$1
    117. ;;
    118. restart|configtest)
    119. \$1
    120. ;;
    121. reload)
    122. rh_status_q || exit 7
    123. \$1
    124. ;;
    125. force-reload)
    126. force_reload
    127. ;;
    128. status)
    129. rh_status
    130. ;;
    131. condrestart|try-restart)
    132. rh_status_q || exit 0
    133. ;;
    134. *)
    135. echo \$\"Usage: \$0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}\"
    136. exit 2
    137. esac
    138. ">/etc/init.d/nginx
    139. chmod +x /etc/init.d/nginx
    140. echo "启动方式为service nginx start|restart|stop|status,热重启方式为: nginx -s reload"
    141. chkconfig --add nginx && chkconfig nginx on && service nginx restart

  • 相关阅读:
    【React】第七部分 Dom的diffing算法
    redis集群最少使用三个主节点和使用16384个槽以及主节点数量不超过1000的原因
    像Django一样开发FastAPI之: AppBoot 入门指南
    【Linux】05.部署Microsoft SQL Server
    泽众APM性能监控软件
    Linux基础命令[24]-su
    SpringBoot+ECharts+Html 地图案例详解
    FPGA-1、verilog书写基本格式
    C语言——深度剖析数据在内存中的存储
    多线程复习笔记
  • 原文地址:https://blog.csdn.net/wt_white/article/details/134553020