Tengine——基础知识,tengine基础知识


http://bbs.linuxtone.org/forum.php?mod=viewthread&tid=21848


很多朋友对淘宝的Tengine感兴趣啊!现在将Tengine的一些资料整理整理分享于此。希望能与大家共同交流与学习,努力完成屌丝的逆袭!哈哈:)顺便感谢淘宝文景、淘宝卫越等各路牛人,很多东西都来自他们的分享。

至于Tengine的特性以及应用场景,参考这个吧: http://tengine.taobao.org/download/taobao_nginx_2012_06.pdf
我的帖子主要进行个有层次的基本实战操作。欢迎大家多提意见。
签名两张,基本操作与Nginx基本是一样的,tengine是可以100%兼容Nginx的。

1、安装Tengine。
[root@webserver1 soft]# wget http://tengine.taobao.org/download/tengine-1.4.1.tar.gz
[root@webserver1 soft]# tar xzvf tengine-1.4.1.tar.gz
[root@webserver1 soft]# cd tengine-1.4.1
[root@webserver1 tengine-1.4.1]# yum install pcre-devel -y    #安装正则表达式库
[root@webserver1 tengine-1.4.1]# ./configure --prefix=/opt/tengine
[root@webserver1 tengine-1.4.1]# make; make install

Tengine是静态编译模块的,所以如果要安装新的模块,需要重新编译Tengine。
./configure --add-module=/path/to/module
我们也可以查看下目前安装了哪些模块:
[root@webserver1 tengine]# ./sbin/nginx -V
Tengine version: Tengine/1.4.1 (nginx/1.2.3)
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-52)
TLS SNI support disabled
configure arguments: --prefix=/opt/tengine
loaded modules:
    ngx_core_module (static)
    ngx_errlog_module (static)
    ngx_conf_module (static)
    ngx_dso_module (static)
    ngx_syslog_module (static)
    ngx_events_module (static)
    ngx_event_core_module (static)
    ngx_epoll_module (static)
    ngx_procs_module (static)
    ngx_proc_core_module (static)
    ngx_openssl_module (static)
    ngx_regex_module (static)
    ngx_http_module (static)
    ngx_http_core_module (static)
    ngx_http_log_module (static)
    ngx_http_upstream_module (static)
    ngx_http_static_module (static)
    ngx_http_autoindex_module (static)
    ngx_http_index_module (static)
    ngx_http_auth_basic_module (static)
    ngx_http_access_module (static)
    ngx_http_limit_conn_module (static)
    ngx_http_limit_req_module (static)
    ngx_http_geo_module (static)
    ngx_http_map_module (static)
    ngx_http_split_clients_module (static)
    ngx_http_referer_module (static)
    ngx_http_rewrite_module (static)
    ngx_http_ssl_module (static)
    ngx_http_proxy_module (static)
    ngx_http_fastcgi_module (static)
    ngx_http_uwsgi_module (static)
    ngx_http_scgi_module (static)
    ngx_http_memcached_module (static)
    ngx_http_empty_gif_module (static)
    ngx_http_browser_module (static)
    ngx_http_user_agent_module (static)
    ngx_http_upstream_ip_hash_module (static)
    ngx_http_upstream_check_module (static)
    ngx_http_upstream_least_conn_module (static)
    ngx_http_upstream_keepalive_module (static)
    ngx_http_stub_status_module (static)
    ngx_http_write_filter_module (static)
    ngx_http_header_filter_module (static)
    ngx_http_chunked_filter_module (static)
    ngx_http_range_header_filter_module (static)
    ngx_http_gzip_filter_module (static)
    ngx_http_postpone_filter_module (static)
    ngx_http_ssi_filter_module (static)
    ngx_http_charset_filter_module (static)
    ngx_http_userid_filter_module (static)
    ngx_http_footer_filter_module (static)
    ngx_http_headers_filter_module (static)
    ngx_http_copy_filter_module (static)
    ngx_http_range_body_filter_module (static)
    ngx_http_not_modified_filter_module (static)
这里顺便提一下,apache的模块分两部分,一部分为静态的(apachectl -l),另一部是动态加载的,要看apach的配置文件(httpd.conf)的LoadModule部分。

2、看看Tengine的目录结构:
[root@webserver1 tengine]# tree
.
|-- conf
|   |-- browsers
|   |-- fastcgi.conf
|   |-- fastcgi.conf.default
|   |-- fastcgi_params
|   |-- fastcgi_params.default
|   |-- koi-utf
|   |-- koi-win
|   |-- mime.types
|   |-- mime.types.default
|   |-- module_stubs
|   |-- nginx.conf
|   |-- nginx.conf.default
|   |-- scgi_params
|   |-- scgi_params.default
|   |-- uwsgi_params
|   |-- uwsgi_params.default
|   `-- win-utf
|-- html
|   |-- 50x.html
|   `-- index.html
|-- logs
|-- modules
`-- sbin
    |-- dso_tool
    `-- nginx

3、启动/停止 Tengine:
[root@webserver1 tengine]# ./sbin/nginx -c ./conf/nginx.conf -p /opt/tengine/      #可执行文件还是nginx的文件名
[root@webserver1 tengine]# ./sbin/nginx -s stop
[root@webserver1 tengine]# ./sbin/nginx -s reload   #这个很常用哦,平滑更新配置。

4、检查配置文件:
先介绍下tengine的启动过程:
在启动nginx 、停止nginx 、更新nginx配置时, nginx首先都会检查配置的正确性。如果配置文件不正确,对应前面这三种操作,nginx不会启动,不会停止服务,保持之前的配置继续工作。(不错,我喜欢!!)
[root@webserver1 tengine]# ./sbin/nginx -t
the configuration file /opt/tengine/conf/nginx.conf syntax is ok
configuration file /opt/tengine/conf/nginx.conf test is successful   #成功啦~~~~~~

5、热更新代码:
更新tengine时,不停止服务,不丢失请求。哈哈,这个给力吧。
[root@webserver1 tengine]# kill -USR2 `cat /opt/tengine/logs/nginx.pid`
[root@webserver1 tengine]# kill -QUIT `cat /opt/tengine/logs/nginx.pid.oldbin`
至于原理,上网搜搜看吧,这里就是重新生成了一个新进程,然后干掉原来的老进程。
可以通过kill -l查看下kill的信号有哪些?
[root@webserver1 tengine]# kill -l
1) SIGHUP         2) SIGINT         3) SIGQUIT         4) SIGILL
5) SIGTRAP         6) SIGABRT         7) SIGBUS         8) SIGFPE
9) SIGKILL        10) SIGUSR1        11) SIGSEGV        12) SIGUSR2
13) SIGPIPE        14) SIGALRM        15) SIGTERM        16) SIGSTKFLT
17) SIGCHLD        18) SIGCONT        19) SIGSTOP        20) SIGTSTP
21) SIGTTIN        22) SIGTTOU        23) SIGURG        24) SIGXCPU
25) SIGXFSZ        26) SIGVTALRM        27) SIGPROF        28) SIGWINCH
29) SIGIO        30) SIGPWR        31) SIGSYS        34) SIGRTMIN
35) SIGRTMIN+1        36) SIGRTMIN+2        37) SIGRTMIN+3        38) SIGRTMIN+4
39) SIGRTMIN+5        40) SIGRTMIN+6        41) SIGRTMIN+7        42) SIGRTMIN+8
43) SIGRTMIN+9        44) SIGRTMIN+10        45) SIGRTMIN+11        46) SIGRTMIN+12
47) SIGRTMIN+13        48) SIGRTMIN+14        49) SIGRTMIN+15        50) SIGRTMAX-14
51) SIGRTMAX-13        52) SIGRTMAX-12        53) SIGRTMAX-11        54) SIGRTMAX-10
55) SIGRTMAX-9        56) SIGRTMAX-8        57) SIGRTMAX-7        58) SIGRTMAX-6
59) SIGRTMAX-5        60) SIGRTMAX-4        61) SIGRTMAX-3        62) SIGRTMAX-2
63) SIGRTMAX-1        64) SIGRTMAX

最后,我们再查看下tengine的目录结构:
[root@webserver1 tengine]# tree
.
|-- client_body_temp
|-- conf
|   |-- browsers
|   |-- fastcgi.conf
|   |-- fastcgi.conf.default
|   |-- fastcgi_params
|   |-- fastcgi_params.default
|   |-- koi-utf
|   |-- koi-win
|   |-- mime.types
|   |-- mime.types.default
|   |-- module_stubs
|   |-- nginx.conf
|   |-- nginx.conf.default
|   |-- scgi_params
|   |-- scgi_params.default
|   |-- uwsgi_params
|   |-- uwsgi_params.default
|   `-- win-utf
|-- fastcgi_temp
|-- html
|   |-- 50x.html
|   `-- index.html
|-- logs
|   |-- access.log
|   |-- error.log
|   `-- nginx.pid
|-- modules
|-- proxy_temp
|-- sbin
|   |-- dso_tool
|   `-- nginx
|-- scgi_temp
`-- uwsgi_temp

比之前的多了不少呀?这次帖子没有介绍配置方面的东西。未完待续。。。敬请期待:)
PS:强烈建议,能否优化下帖子编辑器。或者谁可以教教我,怎么设置才能所见即所得呢???编译颜色和字体太痛苦了。

相关内容

    暂无相关文章