linux下nginx安装、配置实战 | http://aperise.iteye.com/blog/2223373 |
linux下tengine安装 | http://aperise.iteye.com/blog/2339601 |
说到tengine,首先还是得说下nginx了,大家对于nginx并不陌生,对于基本的需求都能满足,如果是涉及高级性能,那么就必须使用商用版nginx plus了,一谈到商用,大家就特别敏感,有没有开源免费的呢,有的,所以tengine诞生了。
Tengine(http://tengine.taobao.org/index_cn.html)是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。主要特性有:
yum -y install net-tools perl gcc gcc-c++ bzip2 autoconf automake
#创建tengine用户和组
groupadd tengine
useradd -g tengine tengine
#设置用户tengine密码
passwd tengine
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
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
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
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
#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.
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/
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
#编辑/home/tengine/.bashrc,加入Tengine启动脚本到PATH
vi /home/tengine/.bashrc
export TENGINE_HOME=/home/tengine/tengine-2.1.2
export PATH=$PATH:$TENGINE_HOME/sbin
#创建软连接
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
详见上一篇博客linux下nginx安装、配置实战