负载均衡之(2)--------linux下tengine安装

 

linux下nginx安装、配置实战http://aperise.iteye.com/blog/2223373
linux下tengine安装http://aperise.iteye.com/blog/2339601

 

linux下tengine安装

1.什么是tengine?

    说到tengine,首先还是得说下nginx了,大家对于nginx并不陌生,对于基本的需求都能满足,如果是涉及高级性能,那么就必须使用商用版nginx plus了,一谈到商用,大家就特别敏感,有没有开源免费的呢,有的,所以tengine诞生了。

    Tengine(http://tengine.taobao.org/index_cn.html)是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。主要特性有

  • 继承Nginx-1.6.2的所有特性,兼容Nginx的配置;
  • 动态模块加载(DSO)支持。加入一个模块不再需要重新编译整个Tengine;
  • 支持SO_REUSEPORT选项,建连性能提升为官方nginx的三倍;
  • 支持SPDY v3协议,自动检测同一端口的SPDY请求和HTTP请求;
  • 流式上传到HTTP后端服务器或FastCGI服务器,大量减少机器的I/O压力;
  • 更加强大的负载均衡能力,包括一致性hash模块、会话保持模块,还可以对后端的服务器进行主动健康检查,根据服务器状态自动上线下线,以及动态解析upstream中出现的域名;
  • 输入过滤器机制支持。通过使用这种机制Web应用防火墙的编写更为方便;
  • 支持设置proxy、memcached、fastcgi、scgi、uwsgi在后端失败时的重试次数
  • 动态脚本语言Lua支持。扩展功能非常高效简单;
  • 支持管道(pipe)和syslog(本地和远端)形式的日志以及日志抽样;
  • 支持按指定关键字(域名,url等)收集Tengine运行状态;
  • 组合多个CSS、JavaScript文件的访问请求变成一个请求;
  • 自动去除空白字符和注释从而减小页面的体积
  • 自动根据CPU数目设置进程个数和绑定CPU亲缘性;
  • 监控系统的负载和资源占用从而对系统进行保护;
  • 显示对运维人员更友好的出错信息,便于定位出错机器;
  • 更强大的防攻击(访问速度限制)模块;
  • 更方便的命令行参数,如列出编译的模块列表、支持的指令等;
  • 可以根据访问文件类型设置过期时间

2.tengine安装前准备

    2.1 编译环境准备

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

 

    2.2 Tengine用户和组添加

#创建tengine用户和组 
groupadd tengine
useradd -g tengine tengine
#设置用户tengine密码
passwd tengine

 

    2.3 openssl安装

        OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。安装OpenSSL(http://www.openssl.org/source/)主要是为了让tengine支持Https的访问请求。

#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开机自启动

#创建软连接
ln -s /home/tengine/tengine-2.1.2/sbin/nginx /etc/init.d/nginx
#赋予执行权限
chmod a+x /etc/init.d/nginx
vi /etc/rc.local
#增加如下内容
/etc/init.d/nginx

 

8.配置例子

    详见上一篇博客linux下nginx安装、配置实战

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值