tengine.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. # make[1]: *** [objs/src/event/ngx_event_openssl.o] Error 1
  29. sed -i 's@\(.*\)this option allow a potential SSL 2.0 rollback (CAN-2005-2969)\(.*\)@#ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING\n\1this option allow a potential SSL 2.0 rollback (CAN-2005-2969)\2@' src/event/ngx_event_openssl.c
  30. sed -i 's@\(.*\)SSL_CTX_set_options(ssl->ctx, SSL_OP_MSIE_SSLV2_RSA_PADDING)\(.*\)@\1SSL_CTX_set_options(ssl->ctx, SSL_OP_MSIE_SSLV2_RSA_PADDING)\2\n#endif@' src/event/ngx_event_openssl.c
  31. if [ "$je_tc_malloc" == '1' ];then
  32. malloc_module='--with-jemalloc'
  33. elif [ "$je_tc_malloc" == '2' ];then
  34. malloc_module='--with-google_perftools_module'
  35. mkdir /tmp/tcmalloc
  36. chown -R ${run_user}.$run_user /tmp/tcmalloc
  37. fi
  38. [ ! -d "$tengine_install_dir" ] && mkdir -p $tengine_install_dir
  39. ./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
  40. make && make install
  41. if [ -e "$tengine_install_dir/conf/nginx.conf" ];then
  42. cd ..
  43. rm -rf tengine-$tengine_version
  44. echo "${CSUCCESS}Tengine install successfully! ${CEND}"
  45. else
  46. rm -rf $tengine_install_dir
  47. echo "${CFAILURE}Tengine install failed, Please Contact the author! ${CEND}"
  48. kill -9 $$
  49. fi
  50. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$tengine_install_dir/sbin:\$PATH" >> /etc/profile
  51. [ -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
  52. . /etc/profile
  53. OS_CentOS='/bin/cp ../init.d/Nginx-init-CentOS /etc/init.d/nginx \n
  54. chkconfig --add nginx \n
  55. chkconfig nginx on'
  56. OS_Debian_Ubuntu='/bin/cp ../init.d/Nginx-init-Ubuntu /etc/init.d/nginx \n
  57. update-rc.d nginx defaults'
  58. OS_command
  59. cd ..
  60. sed -i "s@/usr/local/nginx@$tengine_install_dir@g" /etc/init.d/nginx
  61. mv $tengine_install_dir/conf/nginx.conf{,_bk}
  62. if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
  63. /bin/cp config/nginx_apache.conf $tengine_install_dir/conf/nginx.conf
  64. else
  65. /bin/cp config/nginx.conf $tengine_install_dir/conf/nginx.conf
  66. fi
  67. sed -i "s@/home/wwwroot/default@$wwwroot_dir/default@" $tengine_install_dir/conf/nginx.conf
  68. sed -i "s@/home/wwwlogs@$wwwlogs_dir@g" $tengine_install_dir/conf/nginx.conf
  69. sed -i "s@^user www www@user $run_user $run_user@" $tengine_install_dir/conf/nginx.conf
  70. [ "$je_tc_malloc" == '2' ] && sed -i 's@^pid\(.*\)@pid\1\ngoogle_perftools_profiles /tmp/tcmalloc;@' $tengine_install_dir/conf/nginx.conf
  71. # worker_cpu_affinity
  72. 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
  73. # logrotate nginx log
  74. cat > /etc/logrotate.d/nginx << EOF
  75. $wwwlogs_dir/*nginx.log {
  76. daily
  77. rotate 5
  78. missingok
  79. dateext
  80. compress
  81. notifempty
  82. sharedscripts
  83. postrotate
  84. [ -e /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  85. endscript
  86. }
  87. EOF
  88. sed -i "s@^web_install_dir.*@web_install_dir=$tengine_install_dir@" options.conf
  89. ldconfig
  90. service nginx start
  91. }