tengine.sh 4.7 KB

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