tengine.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # Blog: http://blog.linuxeye.com
  4. Install_Tengine()
  5. {
  6. cd $oneinstack_dir/src
  7. . ../functions/download.sh
  8. . ../functions/check_os.sh
  9. . ../options.conf
  10. src_url=http://downloads.sourceforge.net/project/pcre/pcre/$pcre_version/pcre-$pcre_version.tar.gz && Download_src
  11. src_url=http://tengine.taobao.org/download/tengine-$tengine_version.tar.gz && Download_src
  12. tar xzf pcre-$pcre_version.tar.gz
  13. cd pcre-$pcre_version
  14. ./configure
  15. make && make install
  16. cd ../
  17. tar xzf tengine-$tengine_version.tar.gz
  18. id -u $run_user >/dev/null 2>&1
  19. [ $? -ne 0 ] && useradd -M -s /sbin/nologin $run_user
  20. cd tengine-$tengine_version
  21. # Modify Tengine version
  22. #sed -i 's@TENGINE "/" TENGINE_VERSION@"Tengine/unknown"@' src/core/nginx.h
  23. # close debug
  24. sed -i 's@CFLAGS="$CFLAGS -g"@#CFLAGS="$CFLAGS -g"@' auto/cc/gcc
  25. # make[1]: *** [objs/src/event/ngx_event_openssl.o] Error 1
  26. 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
  27. 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
  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 [ -d "$tengine_install_dir/conf" ];then
  39. echo -e "\033[32mTengine install successfully! \033[0m"
  40. else
  41. rm -rf $tengine_install_dir
  42. echo -e "\033[31mTengine install failed, Please Contact the author! \033[0m"
  43. kill -9 $$
  44. fi
  45. [ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=$tengine_install_dir/sbin:\$PATH" >> /etc/profile
  46. [ -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
  47. . /etc/profile
  48. cd ../../
  49. OS_CentOS='/bin/cp init/Nginx-init-CentOS /etc/init.d/nginx \n
  50. chkconfig --add nginx \n
  51. chkconfig nginx on'
  52. OS_Debian_Ubuntu='/bin/cp init/Nginx-init-Ubuntu /etc/init.d/nginx \n
  53. update-rc.d nginx defaults'
  54. OS_command
  55. sed -i "s@/usr/local/nginx@$tengine_install_dir@g" /etc/init.d/nginx
  56. mv $tengine_install_dir/conf/nginx.conf{,_bk}
  57. if [ "$Apache_version" == '1' -o "$Apache_version" == '2' ];then
  58. /bin/cp conf/nginx_apache.conf $tengine_install_dir/conf/nginx.conf
  59. else
  60. /bin/cp conf/nginx.conf $tengine_install_dir/conf/nginx.conf
  61. fi
  62. sed -i "s@/home/wwwroot/default@$wwwroot_dir/default@" $tengine_install_dir/conf/nginx.conf
  63. sed -i "s@/home/wwwlogs@$wwwlogs_dir@g" $tengine_install_dir/conf/nginx.conf
  64. sed -i "s@^user www www@user $run_user $run_user@" $tengine_install_dir/conf/nginx.conf
  65. [ "$je_tc_malloc" == '2' ] && sed -i 's@^pid\(.*\)@pid\1\ngoogle_perftools_profiles /tmp/tcmalloc;@' $tengine_install_dir/conf/nginx.conf
  66. # worker_cpu_affinity
  67. 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
  68. # logrotate nginx log
  69. cat > /etc/logrotate.d/nginx << EOF
  70. $wwwlogs_dir/*nginx.log {
  71. daily
  72. rotate 5
  73. missingok
  74. dateext
  75. compress
  76. notifempty
  77. sharedscripts
  78. postrotate
  79. [ -e /var/run/nginx.pid ] && kill -USR1 \`cat /var/run/nginx.pid\`
  80. endscript
  81. }
  82. EOF
  83. sed -i "s@^web_install_dir.*@web_install_dir=$tengine_install_dir@" options.conf
  84. ldconfig
  85. service nginx start
  86. }