Tengine 安裝配置全過程


在先前的文章中介紹過Tengine,先前只是使用了運維人員配置好的內容,未自己進行過安裝配置。週末閒來無事,對於Tengine進行了嘗試性的安裝。記錄下面方便以後再做改進。

Tengine官網上有個非常簡單的教程,中間並未涉及到一些常用的設置,所以僅供參考。一下午爲本人的安裝步驟及過程。

1、安裝必要的編譯環境好

由於Tengine安裝需要使用源代碼自行編譯,所以在安裝前需要安裝必要的編譯工具:



# yum update
# yum install gcc gcc-c++ autoconf automake

2、安裝需要的組件

A、PCRE

PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx rewrite依賴於PCRE庫,所以在安裝Tengine前一定要先安裝PCRE,最新版本的PCRE可在官網(http://www.pcre.org/)獲取。具體安裝流程爲:

:

cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
tar zxvf pcre-8.36.tar.gz
cd pcre-8.36
./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的訪問請求。具體是否安裝看需求。

複製代碼 代碼如下:

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.tar.gz
./configure --prefix=/usr/local/openssl
make && make install

C、Zlib

Zlib是提供資料壓縮之用的函式庫,當Tengine想啓用GZIP壓縮的時候就需要使用到Zlib(http://www.zlib.net/)。



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.tar.gz
./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.tar.bz2
./configure --prefix=/usr/local/jemalloc
make && make install

3、安裝Tengine

在主要核心的組件安裝完畢以後就可以安裝Tegine了,最新版本的Tegine可從官網(http://tengine.taobao.org/)獲取。
在編譯安裝前還需要做的一件事是添加一個專門的用戶來執行Tengine。當然你也可以用root(不建議)。

複製代碼 代碼如下:

groupadd www-data
useradd -s /sbin/nologin -g www-data www-data

接下來纔是進行安裝:



cd /usr/local/src
wget http://tengine.taobao.org/download/tengine-2.1.0.tar.gz
tar -zxvf tengine-2.1.0.tar.gz
cd tengine-2.1.0
./configure --prefix=/usr/local/nginx \
--user=www-data \
--group=www-data \
--with-pcre=/usr/local/src/pcre-8.36 \
--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的路徑爲源文件的路徑。

4、配置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 #啓動服務
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章