1
0

tengine.sh 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_Tengine() {
  11. pushd ${oneinstack_dir}/src > /dev/null
  12. id -g ${run_group} >/dev/null 2>&1
  13. [ $? -ne 0 ] && groupadd ${run_group}
  14. id -u ${run_user} >/dev/null 2>&1
  15. [ $? -ne 0 ] && useradd -g ${run_group} -M -s /sbin/nologin ${run_user}
  16. tar xzf pcre-${pcre_ver}.tar.gz
  17. tar xzf tengine-${tengine_ver}.tar.gz
  18. tar xzf openssl-${openssl11_ver}.tar.gz
  19. pushd tengine-${tengine_ver} > /dev/null
  20. # Modify Tengine version
  21. #sed -i 's@TENGINE "/" TENGINE_VERSION@"Tengine/unknown"@' src/core/nginx.h
  22. [ ! -d "${tengine_install_dir}" ] && mkdir -p ${tengine_install_dir}
  23. ./configure --prefix=${tengine_install_dir} --user=${run_user} --group=${run_group} --with-http_v2_module --with-http_ssl_module --with-stream --with-stream_ssl_preread_module --with-stream_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-${openssl11_ver} --with-pcre=../pcre-${pcre_ver} --with-pcre-jit --with-jemalloc ${nginx_modules_options}
  24. make && make install
  25. if [ -e "${tengine_install_dir}/conf/nginx.conf" ]; then
  26. popd > /dev/null
  27. rm -rf pcre-${pcre_ver}* openssl-${openssl11_ver}* tengine-${tengine_ver}*
  28. echo "${CSUCCESS}Tengine installed successfully! ${CEND}"
  29. else
  30. rm -rf pcre-${pcre_ver}* openssl-${openssl11_ver}* tengine-${tengine_ver}* rm -rf ${tengine_install_dir}*
  31. echo "${CFAILURE}Tengine install failed, Please Contact the author! ${CEND}"
  32. kill -9 $$; exit 1;
  33. fi
  34. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=${tengine_install_dir}/sbin:\$PATH" >> /etc/profile
  35. [ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep ${tengine_install_dir} /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=${tengine_install_dir}/sbin:\1@" /etc/profile
  36. . /etc/profile
  37. /bin/cp ../init.d/nginx.service /lib/systemd/system/
  38. sed -i "s@/usr/local/nginx@${tengine_install_dir}@g" /lib/systemd/system/nginx.service
  39. systemctl enable nginx
  40. mv ${tengine_install_dir}/conf/nginx.conf{,_bk}
  41. if [ "${apache_flag}" == 'y' ] || [ -e "${apache_install_dir}/bin/httpd" ]; then
  42. /bin/cp ../config/nginx_apache.conf ${tengine_install_dir}/conf/nginx.conf
  43. elif { [[ ${tomcat_option} =~ ^[1-4]$ ]] || [ -e "${tomcat_install_dir}/conf/server.xml" ]; } && { [[ ! ${php_option} =~ ^[1-9]$|^1[0-1]$ ]] && [ ! -e "${php_install_dir}/bin/php" ]; }; then
  44. /bin/cp ../config/nginx_tomcat.conf ${tengine_install_dir}/conf/nginx.conf
  45. else
  46. /bin/cp ../config/nginx.conf ${tengine_install_dir}/conf/nginx.conf
  47. [[ "${php_option}" =~ ^[1-9]$|^1[0-1]$ ]] && [ -z "`grep '/php-fpm_status' ${tengine_install_dir}/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 }@" ${tengine_install_dir}/conf/nginx.conf
  48. fi
  49. cat > ${tengine_install_dir}/conf/proxy.conf << EOF
  50. proxy_connect_timeout 300s;
  51. proxy_send_timeout 900;
  52. proxy_read_timeout 900;
  53. proxy_buffer_size 32k;
  54. proxy_buffers 4 64k;
  55. proxy_busy_buffers_size 128k;
  56. proxy_redirect off;
  57. proxy_hide_header Vary;
  58. proxy_set_header Accept-Encoding '';
  59. proxy_set_header Referer \$http_referer;
  60. proxy_set_header Cookie \$http_cookie;
  61. proxy_set_header Host \$host;
  62. proxy_set_header X-Real-IP \$remote_addr;
  63. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  64. proxy_set_header X-Forwarded-Proto \$scheme;
  65. EOF
  66. sed -i "s@/data/wwwroot/default@${wwwroot_dir}/default@" ${tengine_install_dir}/conf/nginx.conf
  67. sed -i "s@/data/wwwlogs@${wwwlogs_dir}@g" ${tengine_install_dir}/conf/nginx.conf
  68. sed -i "s@^user www www@user ${run_user} ${run_group}@" ${tengine_install_dir}/conf/nginx.conf
  69. # logrotate nginx log
  70. cat > /etc/logrotate.d/nginx << EOF
  71. ${wwwlogs_dir}/*nginx.log {
  72. daily
  73. rotate 5
  74. missingok
  75. dateext
  76. compress
  77. notifempty
  78. sharedscripts
  79. postrotate
  80. [ -e /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  81. endscript
  82. }
  83. EOF
  84. popd > /dev/null
  85. ldconfig
  86. systemctl start nginx
  87. }