tengine.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. # http://oneinstack.com
  9. # https://github.com/lj2007331/oneinstack
  10. Install_Tengine() {
  11. cd $oneinstack_dir/src
  12. src_url=http://mirrors.linuxeye.com/oneinstack/src/pcre-$pcre_version.tar.gz && Download_src
  13. src_url=http://tengine.taobao.org/download/tengine-$tengine_version.tar.gz && Download_src
  14. id -u $run_user >/dev/null 2>&1
  15. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  16. tar xzf pcre-$pcre_version.tar.gz
  17. tar xzf tengine-$tengine_version.tar.gz
  18. cd tengine-$tengine_version
  19. # Modify Tengine version
  20. #sed -i 's@TENGINE "/" TENGINE_VERSION@"Tengine/unknown"@' src/core/nginx.h
  21. # close debug
  22. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc
  23. if [ "$je_tc_malloc" == '1' ];then
  24. malloc_module='--with-jemalloc'
  25. elif [ "$je_tc_malloc" == '2' ];then
  26. malloc_module='--with-google_perftools_module'
  27. mkdir /tmp/tcmalloc
  28. chown -R ${run_user}.$run_user /tmp/tcmalloc
  29. fi
  30. [ ! -d "$tengine_install_dir" ] && mkdir -p $tengine_install_dir
  31. ./configure --prefix=$tengine_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_spdy_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_concat_module=shared --with-http_sysguard_module=shared --with-pcre=../pcre-$pcre_version --with-pcre-jit $malloc_module
  32. make && make install
  33. if [ -e "$tengine_install_dir/conf/nginx.conf" ];then
  34. cd ..
  35. rm -rf tengine-$tengine_version
  36. echo "${CSUCCESS}Tengine install successfully! ${CEND}"
  37. else
  38. rm -rf $tengine_install_dir
  39. echo "${CFAILURE}Tengine install failed, Please Contact the author! ${CEND}"
  40. kill -9 $$
  41. fi
  42. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$tengine_install_dir/sbin:\$PATH" >> /etc/profile
  43. [ -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
  44. . /etc/profile
  45. [ "$OS" == 'CentOS' ] && { /bin/cp ../init.d/Nginx-init-CentOS /etc/init.d/nginx; chkconfig --add nginx; chkconfig nginx on; }
  46. [[ $OS =~ ^Ubuntu$|^Debian$ ]] && { /bin/cp ../init.d/Nginx-init-Ubuntu /etc/init.d/nginx; update-rc.d nginx defaults; }
  47. cd ..
  48. sed -i "s@/usr/local/nginx@$tengine_install_dir@g" /etc/init.d/nginx
  49. mv $tengine_install_dir/conf/nginx.conf{,_bk}
  50. if [[ $Apache_version =~ ^[1-2]$ ]];then
  51. /bin/cp config/nginx_apache.conf $tengine_install_dir/conf/nginx.conf
  52. elif [[ $Tomcat_version =~ ^[1-2]$ ]] && [ ! -e "$php_install_dir/bin/php" ];then
  53. /bin/cp config/nginx_tomcat.conf $tengine_install_dir/conf/nginx.conf
  54. else
  55. /bin/cp config/nginx.conf $tengine_install_dir/conf/nginx.conf
  56. [ "$PHP_yn" == 'y' ] && [ -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
  57. fi
  58. cat > $tengine_install_dir/conf/proxy.conf << EOF
  59. proxy_connect_timeout 300s;
  60. proxy_send_timeout 900;
  61. proxy_read_timeout 900;
  62. proxy_buffer_size 32k;
  63. proxy_buffers 4 64k;
  64. proxy_busy_buffers_size 128k;
  65. proxy_redirect off;
  66. proxy_hide_header Vary;
  67. proxy_set_header Accept-Encoding '';
  68. proxy_set_header Referer \$http_referer;
  69. proxy_set_header Cookie \$http_cookie;
  70. proxy_set_header Host \$host;
  71. proxy_set_header X-Real-IP \$remote_addr;
  72. proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  73. EOF
  74. sed -i "s@/data/wwwroot/default@$wwwroot_dir/default@" $tengine_install_dir/conf/nginx.conf
  75. sed -i "s@/data/wwwlogs@$wwwlogs_dir@g" $tengine_install_dir/conf/nginx.conf
  76. sed -i "s@^user www www@user $run_user $run_user@" $tengine_install_dir/conf/nginx.conf
  77. [ "$je_tc_malloc" == '2' ] && sed -i 's@^pid\(.*\)@pid\1\ngoogle_perftools_profiles /tmp/tcmalloc;@' $tengine_install_dir/conf/nginx.conf
  78. uname -r | awk -F'.' '{if ($1$2>=39)S=0;else S=1}{exit S}' && [ -z "`grep 'reuse_port on;' $tengine_install_dir/conf/nginx.conf`" ] && sed -i "s@worker_connections 51200;@worker_connections 51200;\n reuse_port on;@" $tengine_install_dir/conf/nginx.conf
  79. # worker_cpu_affinity
  80. sed -i "s@^worker_processes.*@worker_processes auto;\nworker_cpu_affinity auto;\ndso {\n\tload ngx_http_concat_module.so;\n\tload ngx_http_sysguard_module.so;\n}@" $tengine_install_dir/conf/nginx.conf
  81. # logrotate nginx log
  82. cat > /etc/logrotate.d/nginx << EOF
  83. $wwwlogs_dir/*nginx.log {
  84. daily
  85. rotate 5
  86. missingok
  87. dateext
  88. compress
  89. notifempty
  90. sharedscripts
  91. postrotate
  92. [ -e /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  93. endscript
  94. }
  95. EOF
  96. ldconfig
  97. service nginx start
  98. }