tengine installation under linux

 

Installation and configuration of nginx under linux http://aperise.iteye.com/blog/2223373
tengine installation under linux http://aperise.iteye.com/blog/2339601

 

tengine installation under linux

1. What is tengine?

    When it comes to tengine, we have to talk about nginx first. Everyone is not unfamiliar with nginx and can meet basic needs. If it involves advanced performance, then the commercial version of nginx plus must be used . When it comes to commercial use, everyone will Especially sensitive, is there any open source free? Yes, so tengine was born.

    Tengine ( http://tengine.taobao.org/index_cn.html ) is a web server project initiated by Taobao.com . On the basis of Nginx, it adds many advanced functions and features for the needs of high-traffic websites. The main features are :

  • Inherit all the features of Nginx-1.6.2, compatible with Nginx configuration;
  • Dynamic module loading (DSO) support. Adding a module no longer requires recompiling the entire Tengine;
  • Supports the SO_REUSEPORT option, and the connection performance is improved by three times that of the official nginx;
  • Support SPDY v3 protocol, automatically detect SPDY request and HTTP request on the same port;
  • Stream upload to HTTP backend server or FastCGI server, greatly reducing the I/O pressure of the machine;
  • More powerful load balancing capabilities, including consistent hash module and session retention module, can also perform active health checks on back-end servers, automatically go online and offline according to server status, and dynamically resolve domain names appearing in upstream;
  • Input filter mechanism support. It is more convenient to write Web application firewall by using this mechanism;
  • Support setting the number of retries for proxy, memcached, fastcgi, scgi, uwsgi when the backend fails
  • Dynamic scripting language Lua support. The extension function is very efficient and simple;
  • Supports logs in the form of pipes and syslogs (local and remote) and log sampling;
  • Support to collect Tengine running status by specified keywords (domain name, url, etc.);
  • Combine access requests of multiple CSS and JavaScript files into one request;
  • Automatically remove whitespace and comments to reduce page size
  • Automatically set the number of processes and bind CPU affinity according to the number of CPUs;
  • Monitor system load and resource occupancy to protect the system;
  • Display more friendly error information for operation and maintenance personnel, which is convenient for locating the faulty machine;
  • More powerful anti-attack (access speed limit) module;
  • More convenient command line parameters, such as listing compiled modules list, supported instructions, etc.;
  • Expiration time can be set according to the access file type

2. Preparation before installation of tengine

    2.1 Preparation of the compilation environment

yum -y install net-tools perl gcc gcc-c++ bzip2 autoconf automake

 

    2.2 Tengine user and group addition

#Create tengine users and groups
groupadd tengine
useradd -g tengine tengine #Set
user tengine password
passwd tengine

 

    2.3 openssl installation

        OpenSSL is a powerful secure socket layer cryptographic library, including major cryptographic algorithms, commonly used key and certificate encapsulation management functions and SSL protocols, and provides a wealth of applications for testing or other purposes. Installing OpenSSL (http://www.openssl.org/source/) is mainly to allow tengine to support Https access requests.

#1.安装openssl-1.0.2.tar.gz
#在https://www.openssl.org/source/下载openssl-1.0.2.tar.gz
#wget http://www.openssl.org/source/openssl-1.0.2.tar.gz
cd /home/tengine/software
#解压安装文件
tar -zxvf openssl-1.0.2.tar.gz
cd openssl-1.0.2
#prefix配置安装路径
./config --prefix=/home/tengine/openssl-1.0.2
make
make install

 

    2.4 zlib安装

        Zlib是提供资料压缩之用的函式库,当Tengine想启用GZIP压缩的时候就需要使用到Zlib(http://www.zlib.net/)。

#1.安装zlib-1.2.8.tar.gz
#在https://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz/download下载zlib-1.2.8.tar.gz
#wget https://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz
cd /home/tengine/software
#2解压安装文件
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
#3prefix配置安装路径
./configure --prefix=/home/tengine/zlib-1.2.8
make
make install

 

    2.5 pcre安装

        PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx rewrite依赖于PCRE库,所以在安装Tengine前一定要先安装PCRE,最新版本的PCRE可在官网(http://www.pcre.org/)获取。

 
#1.安装pcre-8.39.tar.gz
#在ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/下载pcre-8.39.tar.gz
#wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

cd /home/tengine/software
#2解压安装文件
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39

#3prefix配置安装路径
./configure --prefix=/home/tengine/pcre-8.39
make
make install

 

    2.6 jemalloc安装

        jemalloc(http://www.canonware.com/jemalloc/)是一个更好的内存管理工具,使用jemalloc可以更好的优化Tengine的内存管理。

#1.安装jemalloc-4.2.1.tar.bz2
#在http://www.canonware.com/download/jemalloc/下载jemalloc-4.2.1.tar.bz2
#wget http://www.canonware.com/download/jemalloc/jemalloc-4.2.1.tar.bz2
cd /home/tengine/software
#2解压安装文件
tar -jxvf jemalloc-4.2.1.tar.bz2
cd jemalloc-4.2.1
#3jemalloc配置安装路径
./configure --prefix=/home/tengine/jemalloc-4.2.1
make
make install

 

3.tengine安装

#1.安装tengine-2.1.2.tar.gz
cd /home/tengine/software
#2.解压安装文件
tar -zxvf tengine-2.1.2.tar.gz
cd tengine-2.1.2
#3.with-*这里都只配置上面pcre、zlib、openssl和jemalloc的解压所在目录位置,也即它们的源代码所在位置的目录,prefix配置安装路径
./configure --prefix=/home/tengine/tengine-2.1.2 \
--user=tengine \
--group=tengine \
--with-pcre=../pcre-8.39 \
--with-zlib=../zlib-1.2.8 \
--with-openssl=../openssl-1.0.2 \
--with-jemalloc=../jemalloc-4.2.1 \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_concat_module

make
make install

     注意:with-*指定依赖包源代码位置也即解压相关依赖库所在位置,切记不是安装位置,prefix配置安装路径

               以上操作都是使用root用户进行编译

    上面的安装在操作系统centos7.2上没遇到任何问题,如果在操作系统CentOS release 6.4遇到以下报错信息:

make -f objs/Makefile install
make[1]: Entering directory `/home/tengine/software/tengine-2.1.2'
cc -rdynamic -o objs/nginx \
        objs/src/core/nginx.o \
        objs/src/core/ngx_log.o \
        objs/src/core/ngx_palloc.o \
        objs/src/core/ngx_array.o \
        objs/src/core/ngx_list.o \
        objs/src/core/ngx_hash.o \
        objs/src/core/ngx_buf.o \
        objs/src/core/ngx_queue.o \
        objs/src/core/ngx_output_chain.o \
        objs/src/core/ngx_string.o \
        objs/src/core/ngx_parse.o \
        objs/src/core/ngx_inet.o \
        objs/src/core/ngx_file.o \
        objs/src/core/ngx_crc32.o \
        objs/src/core/ngx_murmurhash.o \
        objs/src/core/ngx_md5.o \
        objs/src/core/ngx_rbtree.o \
        objs/src/core/ngx_trie.o \
        objs/src/core/ngx_segment_tree.o \
        objs/src/core/ngx_radix_tree.o \
        objs/src/core/ngx_slab.o \
        objs/src/core/ngx_times.o \
        objs/src/core/ngx_shmtx.o \
        objs/src/core/ngx_connection.o \
        objs/src/core/ngx_cycle.o \
        objs/src/core/ngx_spinlock.o \
        objs/src/core/ngx_cpuinfo.o \
        objs/src/core/ngx_conf_file.o \
        objs/src/core/ngx_resolver.o \
        objs/src/core/ngx_open_file_cache.o \
        objs/src/core/ngx_crypt.o \
        objs/src/core/ngx_proxy_protocol.o \
        objs/src/event/ngx_event.o \
        objs/src/event/ngx_event_timer.o \
        objs/src/event/ngx_event_posted.o \
        objs/src/event/ngx_event_busy_lock.o \
        objs/src/event/ngx_event_accept.o \
        objs/src/event/ngx_event_connect.o \
        objs/src/event/ngx_event_pipe.o \
        objs/src/os/unix/ngx_time.o \
        objs/src/os/unix/ngx_errno.o \
        objs/src/os/unix/ngx_alloc.o \
        objs/src/os/unix/ngx_files.o \
        objs/src/os/unix/ngx_socket.o \
        objs/src/os/unix/ngx_recv.o \
        objs/src/os/unix/ngx_readv_chain.o \
        objs/src/os/unix/ngx_udp_recv.o \
        objs/src/os/unix/ngx_send.o \
        objs/src/os/unix/ngx_writev_chain.o \
        objs/src/os/unix/ngx_channel.o \
        objs/src/os/unix/ngx_shmem.o \
        objs/src/os/unix/ngx_process.o \
        objs/src/os/unix/ngx_daemon.o \
        objs/src/os/unix/ngx_setproctitle.o \
        objs/src/os/unix/ngx_posix_init.o \
        objs/src/os/unix/ngx_user.o \
        objs/src/os/unix/ngx_pipe.o \
        objs/src/os/unix/ngx_sysinfo.o \
        objs/src/os/unix/ngx_process_cycle.o \
        objs/src/os/unix/ngx_linux_init.o \
        objs/src/event/modules/ngx_epoll_module.o \
        objs/src/os/unix/ngx_linux_sendfile_chain.o \
        objs/src/os/unix/ngx_syslog.o \
        objs/src/core/ngx_dso_module.o \
        objs/src/proc/ngx_proc.o \
        objs/src/event/ngx_event_openssl.o \
        objs/src/event/ngx_event_openssl_stapling.o \
        objs/src/core/ngx_regex.o \
        objs/src/http/ngx_http.o \
        objs/src/http/ngx_http_core_module.o \
        objs/src/http/ngx_http_special_response.o \
        objs/src/http/ngx_http_request.o \
        objs/src/http/ngx_http_parse.o \
        objs/src/http/ngx_http_header_filter_module.o \
        objs/src/http/ngx_http_write_filter_module.o \
        objs/src/http/ngx_http_copy_filter_module.o \
        objs/src/http/modules/ngx_http_log_module.o \
        objs/src/http/ngx_http_request_body.o \
        objs/src/http/ngx_http_variables.o \
        objs/src/http/ngx_http_script.o \
        objs/src/http/ngx_http_upstream.o \
        objs/src/http/ngx_http_upstream_round_robin.o \
        objs/src/http/ngx_http_parse_time.o \
        objs/src/http/modules/ngx_http_static_module.o \
        objs/src/http/modules/ngx_http_index_module.o \
        objs/src/http/modules/ngx_http_chunked_filter_module.o \
        objs/src/http/modules/ngx_http_range_filter_module.o \
        objs/src/http/modules/ngx_http_headers_filter_module.o \
        objs/src/http/modules/ngx_http_not_modified_filter_module.o \
        objs/src/http/ngx_http_busy_lock.o \
        objs/src/http/ngx_http_file_cache.o \
        objs/src/http/modules/ngx_http_gzip_filter_module.o \
        objs/src/http/ngx_http_postpone_filter_module.o \
        objs/src/http/modules/ngx_http_ssi_filter_module.o \
        objs/src/http/modules/ngx_http_charset_filter_module.o \
        objs/src/http/modules/ngx_http_userid_filter_module.o \
        objs/src/http/modules/ngx_http_footer_filter_module.o \
        objs/src/http/modules/ngx_http_trim_filter_module.o \
        objs/src/http/modules/ngx_http_gzip_static_module.o \
        objs/src/http/modules/ngx_http_autoindex_module.o \
        objs/src/http/modules/ngx_http_concat_module.o \
        objs/src/http/modules/ngx_http_auth_basic_module.o \
        objs/src/http/modules/ngx_http_access_module.o \
        objs/src/http/modules/ngx_http_limit_conn_module.o \
        objs/src/http/modules/ngx_http_limit_req_module.o \
        objs/src/http/modules/ngx_http_realip_module.o \
        objs/src/http/modules/ngx_http_geo_module.o \
        objs/src/http/modules/ngx_http_map_module.o \
        objs/src/http/modules/ngx_http_split_clients_module.o \
        objs/src/http/modules/ngx_http_referer_module.o \
        objs/src/http/modules/ngx_http_rewrite_module.o \
        objs/src/http/modules/ngx_http_ssl_module.o \
        objs/src/http/modules/ngx_http_proxy_module.o \
        objs/src/http/modules/ngx_http_fastcgi_module.o \
        objs/src/http/modules/ngx_http_uwsgi_module.o \
        objs/src/http/modules/ngx_http_scgi_module.o \
        objs/src/http/modules/ngx_http_memcached_module.o \
        objs/src/http/modules/ngx_http_empty_gif_module.o \
        objs/src/http/modules/ngx_http_browser_module.o \
        objs/src/http/modules/ngx_http_user_agent_module.o \
        objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \
        objs/src/http/modules/ngx_http_upstream_consistent_hash_module.o \
        objs/src/http/ngx_http_upstream_check_module.o \
        objs/src/http/modules/ngx_http_upstream_least_conn_module.o \
        objs/src/http/modules/ngx_http_upstream_session_sticky_module.o \
        objs/src/http/modules/ngx_http_reqstat_module.o \
        objs/src/http/modules/ngx_http_upstream_keepalive_module.o \
        objs/src/http/modules/ngx_http_upstream_dynamic_module.o \
        objs/src/http/modules/ngx_http_stub_status_module.o \
        objs/ngx_modules.o \
        -lpthread -ldl -lcrypt ../pcre-8.39/.libs/libpcre.a ../openssl-1.0.2/.openssl/lib/libssl.a ../openssl-1.0.2/.openssl/lib/libcrypto.a -ldl ../zlib-1.2.8/libz.a ../jemalloc-4.2.1/lib/libjemalloc.a -lpthread
../jemalloc-4.2.1/lib/libjemalloc.a(nstime.o): In function `je_nstime_update':
/home/tengine/software/jemalloc-4.2.1/src/nstime.c:125: undefined reference to `clock_gettime'
/home/tengine/software/jemalloc-4.2.1/src/nstime.c:127: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] Error 1
make[1]: Leaving directory `/home/tengine/software/tengine-2.1.2'
make: *** [install] Error 2

    上面出错根本原因是编译nginx找不到实时库librt,只需将文件/home/tengine/software/tengine-2.1.2/objs/Makefile中的首行:

CC =    cc 

    修改为:

CC =    cc -lrt

    上面的编译出错问题即可解决,-lrt的意思是让编译的时候加入实时库librt.

 

4.修改tengine目录所属用户组和权限

chgrp -R tengine /home/tengine/tengine-2.1.2/
chown -R tengine /home/tengine/tengine-2.1.2/
chmod -R 755 /home/tengine/tengine-2.1.2/

 

5.tengine常用命令

    tegine命令其实和之前nginx并无差别,这里简单列举几个,其他命令详见nginx官网

#1.启动tengine
cd /home/tengine/tengine-2.1.2/sbin
./nginx
#2.查看端口
netstat -ntlp
#3.关闭tengine
cd /home/tengine/tengine-2.1.2/sbin
./nginx -s stop

 

6.Tengine加入PATH

#编辑/home/tengine/.bashrc,加入Tengine启动脚本到PATH
vi /home/tengine/.bashrc
export TENGINE_HOME=/home/tengine/tengine-2.1.2
export PATH=$PATH:$TENGINE_HOME/sbin

 

7.Tengine开机自启动

#Create a soft connection
ln -s /home/tengine/tengine-2.1.2/sbin/nginx /etc/init.d/nginx #Give
execution permission
chmod a+x /etc/init.d/nginx
vi /etc/rc .local #Add
the following content
/etc/init.d/nginx

 

8. Configuration example

    For details, see the previous blog nginx installation and configuration under linux

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326916478&siteId=291194637