CentOS 6.6 安裝 Tengine 的教程詳解

來源:互聯網
上載者:User


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

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

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

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

Shell

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

2、安裝需要的組件

A、PCRE

PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 相容的Regex庫。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 #啟動服務
完。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.