一、安裝必要的編譯環境好
因爲Tengine安裝須要使用源代碼自行編譯,因此在安裝前須要安裝必要的編譯工具:html
# yum update # yum install gcc gcc-c++ autoconf automake
二、安裝須要的組件
A、PCRE
PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx rewrite依賴於PCRE庫,因此在安裝Tengine前必定要先安裝PCRE,最新版本的PCRE可在官網(http://www.pcre.org/)獲取。具體安裝流程爲:nginx
# cd /usr/local/src # wget http://ncu.dl.sourceforge.net/project/pcre/pcre/8.38/pcre-8.38.tar.gz # tar zxvf pcre-8.38.tar.gz # cd pcre-8.38 # ./configure --prefix=/usr/local/pcre # make && make install
附加信息:
源碼的安裝通常由3個步驟組成:配置(configure)、編譯(make)、安裝(make install)。
Configure是一個可執行腳本,它有不少選項,在待安裝的源碼路徑下使用命令./configure –help輸出詳細的選項列表。其中–prefix選項是配置安裝的路徑,若是不配置該選項,安裝後可執行文件默認放在/usr /local/bin,庫文件默認放在/usr/local/lib,配置文件默認放在/usr/local/etc,其它的資源文件放在/usr /local/share,比較凌亂。
若是配置–prefix,如:./configure –prefix=/usr/local/test,能夠把全部資源文件放在/usr/local/test的路徑中,不會雜亂。
用了—prefix選項的另外一個好處是卸載軟件或移植軟件。當某個安裝的軟件再也不須要時,只須簡單的刪除該安裝目錄,就能夠把軟件卸載得乾乾淨淨;移植軟件只需拷貝整個目錄到另一個機器便可(相同的操做系統)。固然要卸載程序,也能夠在原來的make目錄下用一次make uninstall,但前提是make文件指定過uninstall。
B、OpenSSL
OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、經常使用的密鑰和證書封裝管理功能及SSL協議,並提供豐富的應用程序供測試或其它目的使用。,安裝OpenSSL(http://www.openssl.org/source/)主要是爲了讓tengine支持Https的訪問請求。具體是否安裝看需求。c++
# cd /usr/local/src # wget http://www.openssl.org/source/openssl-1.0.2.tar.gz # tar zxvf openssl-1.0.2.tar.gz # cd openssl-1.0.2 # ./Configure --prefix=/usr/local/openssl # make && make install
C、Zlib
Zlib是提供資料壓縮之用的函式庫,當Tengine想啓用GZIP壓縮的時候就須要使用到Zlib(http://www.zlib.net/)。web
# cd /usr/local/src # wget http://zlib.net/zlib-1.2.8.tar.gz # tar zxvf zlib-1.2.8.tar.gz # cd zlib-1.2.8 # ./configure --prefix=/usr/local/zlib # make && make install
D、jemalloc
jemalloc(http://www.canonware.com/jemalloc/)是一個更好的內存管理工具,使用jemalloc能夠更好的優化Tengine的內存管理。正則表達式
# cd /usr/local/src # wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2 # tar jxvf jemalloc-3.6.0.tar.bz2 # cd jemalloc-3.6.0 # ./configure --prefix=/usr/local/jemalloc # make && make install
三、安裝Tengine
在主要核心的組件安裝完畢之後就能夠安裝Tegine了,最新版本的Tegine可從官網(http://tengine.taobao.org/)獲取。
在編譯安裝前還須要作的一件事是添加一個專門的用戶來執行Tengine。固然你也能夠用root(不建議)。算法
# groupadd www-data # useradd -s /sbin/nologin -g www-data www-data
接下來纔是進行安裝:vim
# cd /usr/local/src # wget http://tengine.taobao.org/download/tengine-2.1.2.tar.gz # tar -zxvf tengine-2.1.2.tar.gz # cd tengine-2.1.2 # ./configure --prefix=/usr/local/nginx \ --user=www-data \ --group=www-data \ --with-pcre=/usr/local/src/pcre-8.38 \ --with-openssl=/usr/local/src/openssl-1.0.2 \ --with-jemalloc=/usr/local/src/jemalloc-3.6.0 \ --with-http_gzip_static_module \ --with-http_realip_module \ --with-http_stub_status_module \ --with-http_concat_module \ --with-zlib=/usr/local/src/zlib-1.2.8 # make && make install
注意配置的時候 –with-pcre 、–with-openssl、–with-jemalloc、–with-zlib的路徑爲源文件的路徑。
四、配置Tengine,設置tengine自動啓動瀏覽器
#vim /etc/rc.d/init.d/nginx #編輯啓動文件添加下面內容 #!/bin/bash # nginx Startup script for the Nginx HTTP Server # it is v.0.0.2 version. # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/logs/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid } reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL 保存退出 chmod 775 /etc/rc.d/init.d/nginx #賦予文件執行權限 chkconfig nginx on #設置開機啓動 service nginx restart #啓動服務
瀏覽器中輸入地址訪問以下安全
參考:bash
http://tengine.taobao.org/document_cn/install_cn.html
http://blog.csdn.net/shirdrn/article/details/9731215