openresty.sh 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_OpenResty() {
  11. pushd ${oneinstack_dir}/src
  12. id -u $run_user >/dev/null 2>&1
  13. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  14. tar xzf pcre-$pcre_version.tar.gz
  15. tar xzf openresty-$openresty_version.tar.gz
  16. tar xzf openssl-$openssl_version.tar.gz
  17. pushd openresty-$openresty_version
  18. # close debug
  19. openresty_version_tmp=${openresty_version%.*}
  20. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' bundle/nginx-$openresty_version_tmp/auto/cc/gcc # close debug
  21. if [ "$je_tc_malloc" == '1' ]; then
  22. malloc_module="--with-ld-opt='-ljemalloc'"
  23. elif [ "$je_tc_malloc" == '2' ]; then
  24. malloc_module='--with-google_perftools_module'
  25. mkdir /tmp/tcmalloc
  26. chown -R ${run_user}.$run_user /tmp/tcmalloc
  27. fi
  28. [ ! -d "$openresty_install_dir" ] && mkdir -p $openresty_install_dir
  29. ./configure --prefix=$openresty_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-$openssl_version --with-pcre=../pcre-$pcre_version --with-pcre-jit $malloc_module
  30. make -j ${THREAD} && make install
  31. if [ -e "$openresty_install_dir/nginx/conf/nginx.conf" ]; then
  32. popd
  33. rm -rf openresty-$openresty_version
  34. echo "${CSUCCESS}OpenResty installed successfully! ${CEND}"
  35. else
  36. rm -rf $openresty_install_dir
  37. echo "${CFAILURE}OpenResty install failed, Please Contact the author! ${CEND}"
  38. kill -9 $$
  39. fi
  40. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$openresty_install_dir/nginx/sbin:\$PATH" >> /etc/profile
  41. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep $openresty_install_dir /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=$openresty_install_dir/nginx/sbin:\1@" /etc/profile
  42. . /etc/profile
  43. [ "$OS" == 'CentOS' ] && { /bin/cp ../init.d/Nginx-init-CentOS /etc/init.d/nginx; chkconfig --add nginx; chkconfig nginx on; }
  44. [[ $OS =~ ^Ubuntu$|^Debian$ ]] && { /bin/cp ../init.d/Nginx-init-Ubuntu /etc/init.d/nginx; update-rc.d nginx defaults; }
  45. sed -i "s@/usr/local/nginx@$openresty_install_dir/nginx@g" /etc/init.d/nginx
  46. mv $openresty_install_dir/nginx/conf/nginx.conf{,_bk}
  47. if [[ $Apache_version =~ ^[1-2]$ ]]; then
  48. /bin/cp ../config/nginx_apache.conf $openresty_install_dir/nginx/conf/nginx.conf
  49. elif [[ $Tomcat_version =~ ^[1-2]$ ]] && [ ! -e "$php_install_dir/bin/php" ]; then
  50. /bin/cp ../config/nginx_tomcat.conf $openresty_install_dir/nginx/conf/nginx.conf
  51. else
  52. /bin/cp ../config/nginx.conf $openresty_install_dir/nginx/conf/nginx.conf
  53. [ "$PHP_yn" == 'y' ] && [ -z "`grep '/php-fpm_status' $openresty_install_dir/nginx/conf/nginx.conf`" ] && sed -i "s@index index.html index.php;@index index.html index.php;\n location ~ /php-fpm_status {\n #fastcgi_pass remote_php_ip:9000;\n fastcgi_pass unix:/dev/shm/php-cgi.sock;\n fastcgi_index index.php;\n include fastcgi.conf;\n allow 127.0.0.1;\n deny all;\n }@" $openresty_install_dir/nginx/conf/nginx.conf
  54. fi
  55. cat > $openresty_install_dir/nginx/conf/proxy.conf << EOF
  56. proxy_connect_timeout 300s;
  57. proxy_send_timeout 900;
  58. proxy_read_timeout 900;
  59. proxy_buffer_size 32k;
  60. proxy_buffers 4 64k;
  61. proxy_busy_buffers_size 128k;
  62. proxy_redirect off;
  63. proxy_hide_header Vary;
  64. proxy_set_header Accept-Encoding '';
  65. proxy_set_header Referer \$http_referer;
  66. proxy_set_header Cookie \$http_cookie;
  67. proxy_set_header Host \$host;
  68. proxy_set_header X-Real-IP \$remote_addr;
  69. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  70. EOF
  71. sed -i "s@/data/wwwroot/default@$wwwroot_dir/default@" $openresty_install_dir/nginx/conf/nginx.conf
  72. sed -i "s@/data/wwwlogs@$wwwlogs_dir@g" $openresty_install_dir/nginx/conf/nginx.conf
  73. sed -i "s@^user www www@user $run_user $run_user@" $openresty_install_dir/nginx/conf/nginx.conf
  74. [ "$je_tc_malloc" == '2' ] && sed -i 's@^pid\(.*\)@pid\1\ngoogle_perftools_profiles /tmp/tcmalloc;@' $openresty_install_dir/nginx/conf/nginx.conf
  75. # logrotate nginx log
  76. cat > /etc/logrotate.d/nginx << EOF
  77. $wwwlogs_dir/*nginx.log {
  78. daily
  79. rotate 5
  80. missingok
  81. dateext
  82. compress
  83. notifempty
  84. sharedscripts
  85. postrotate
  86. [ -e /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  87. endscript
  88. }
  89. EOF
  90. popd
  91. ldconfig
  92. service nginx start
  93. }