[LTMP搭建] Centos 6.5 安裝配置 Tengine

接上篇:http://www.cnblogs.com/antarctican/p/3752812.html (安裝PHP)php

  

    一. 安裝依賴的擴展    html

    記得前幾天編譯tengine,不使用 --with-http_lua_module , 也就不須要如下1》、2》、3》 的 lua部分了。linux

    1》 Lua library(Tengine的lua擴展須要),nginx

[root@localhost src]# yum install readline-devel

[root@localhost src]# wget -c http://www.lua.org/ftp/lua-5.1.5.tar.gz
[root@localhost src]# tar -zxvf lua-5.1.5.tar.gz 
[root@localhost src]# cd lua-5.1.5
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// 若是是64位系統,到 lua-x.x.x/src/Makefile增長 -fPIC ,不然後面可能會出現(本文錯誤6) ‘relocation R_X86_64_32 against `luaO_nilobject_'
# vim src/Makefile         
CFLAGS= -fPIC -O2 -Wall $(MYCFLAGS)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[root@localhost lua-5.1.5]# make linux && make install

    2》 scrons。 這個只是此處編譯tolua++須要才安裝c++

[root@localhost src]# rpm -ivh http://jaist.dl.sourceforge.net/project/scons/scons/2.3.1/scons-2.3.1-1.noarch.rpm

    3》 tolua++ git

[root@localhost src]# wget -c http://www.codenix.com/~tolua/tolua++-1.0.93.tar.bz2
[root@localhost src]# tar -jvxf tolua++-1.0.93.tar.bz2
[root@localhost src]# cd tolua++-1.0.93
[root@localhost tolua++-1.0.93]# vim config_linux.py
 // 將
  LIBS = ['lua50', 'lualib50', 'dl', 'm']
 // 改成
  LIBS = ['lua', 'dl', 'm']

 [root@localhost tolua++-1.0.93]# scons allgithub

 [root@localhost tolua++-1.0.93]# scons installvim

  lua系列安裝完畢,查看api

  [root@localhost src]# lua -vbash

  [root@localhost src]# tolua++ -v

  

    4》GD (http_image_filter_module 須要). 帶過

 

    二. 編譯tengine。 

    此處附帶選項比較多,中途出錯誤終止可能性大,很折騰。

 
 

./configure --prefix=/usr/local/tengine
--lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid
--error-log-path=/var/logs/nginx/error.log
--http-log-path=/var/logs/nginx/access.log
--user=www
--group=www
--with-pcre=/usr/local/src/pcre-8.35            ## 這裏指定的是PCRE的解壓目錄,不是安裝目錄,不然報錯
--with-pcre-opt=-fPIC
--with-openssl=/usr/local/src/openssl-1.0.1i       ## 解壓後的源文件目錄
--with-openssl-opt=-fPIC

--with-md5=/usr/lib                      ## openssl 依賴md5
--with-backtrace_module
--with-http_stub_status_module
--with-http_gzip_static_module
--with-http_realip_module
--with-http_concat_module=shared
--with-http_sysguard_module=shared
--with-http_limit_conn_module=shared
--with-http_limit_req_module=shared
--with-http_split_clients_module=shared
--with-http_footer_filter_module=shared
// --with-http_geoip_module=shared             ## geoip,可不用
--with-http_sub_module=shared
--with-http_access_module=shared
--with-http_upstream_ip_hash_module=shared
--with-http_upstream_least_conn_module=shared
--with-http_referer_module=shared
--with-http_rewrite_module=shared
--with-http_memcached_module=shared
--with-http_upstream_session_sticky_module=shared
--with-http_addition_module=shared
// --with-http_image_filter_module=shared
--with-http_user_agent_module=shared
--with-http_empty_gif_module=shared
--with-http_browser_module=shared
// --with-google_perftools_module             ## google 的分析C/C++軟件內存和CPU使用(tcmalloc,CPU)的工具, 很是規項
--with-http_map_module=shared
--with-http_userid_filter_module=shared
--with-http_charset_filter_module=shared
--with-http_trim_filter_module=shared
--with-http_lua_module=shared
// --without-http_fastcgi_module
// --without-http_uwsgi_module
// --without-http_scgi_module
// --without-select_module
// --without-poll_module
// --add-module=../nginx-hmux-module-1.3
// --add-module=../nginx_tcp_proxy_module-0.4.5
// --with-ld-opt='-ltcmalloc_minimal'
// --http-client-body-temp-path=/data/nginx_temp/nginx_client
// --http-proxy-temp-path=/data/nginx_temp/nginx_proxy
// --http-fastcgi-temp-path=/data/nginx_temp/nginx_fastcgi

合併:

./configure --prefix=/usr/local/tengine --lock-path=/var/lock/nginx.lock --pid-path=/var/run/nginx.pid --error-log-path=/var/logs/nginx/error.log --http-log-path=/var/logs/nginx/access.log --user=www --group=www --with-pcre=/usr/local/src/pcre-8.35 --with-pcre-opt=-fPIC --with-openssl=/usr/local/src/openssl-1.0.1i --with-openssl-opt=-fPIC --with-md5=/usr/lib --with-backtrace_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_concat_module=shared --with-http_sysguard_module=shared --with-http_limit_conn_module=shared --with-http_limit_req_module=shared --with-http_split_clients_module=shared --with-http_footer_filter_module=shared --with-http_sub_module=shared --with-http_access_module=shared --with-http_upstream_ip_hash_module=shared --with-http_upstream_least_conn_module=shared --with-http_referer_module=shared --with-http_rewrite_module=shared --with-http_memcached_module=shared --with-http_upstream_session_sticky_module=shared --with-http_addition_module=shared --with-http_user_agent_module=shared --with-http_empty_gif_module=shared --with-http_browser_module=shared --with-http_map_module=shared --with-http_userid_filter_module=shared --with-http_charset_filter_module=shared --with-http_trim_filter_module=shared --with-http_lua_module=shared 

   最好先# make test, 這中間可能會有提示錯誤

  make && make install

  # /usr/local/tengine/sbin/nginx -c /usr/local/tengine/conf/nginx.conf    ## 指定conf的位置

  若是此時尚未編譯時指定的user和group,建立

[root@localhost src]# groupadd www
[root@localhost src]# useradd -s -M /sbin/nologin -g www www

  若是能運行 /usr/local/sbin/nginx -v, 看到版本模塊信息, 說明已安裝成功。

   

    3、報錯及解決方法  

    1.  PCRE dir指定錯誤。 我在指定 --with-pcre=shared時一樣出現以下錯誤,改成 PCRE 解壓編譯時的原目錄就行了

[root@localhost tengine-2.0.3]# make test
make -f objs/Makefile test
make[1]: Entering directory `/usr/local/src/tengine-2.0.3'
cd shared \
    && if [ -f Makefile ]; then make distclean; fi \
    && CC="gcc" CFLAGS="-fPIC -pipe" \
    ./configure --disable-shared 
/bin/sh: line 0: cd: shared: No such file or directory
make[1]: *** [shared/Makefile] Error 1
make[1]: Leaving directory `/usr/local/src/tengine-2.0.3'
make: *** [test] Error 2

    

   2.  須要 C++ compiler。 可能因爲卸載某些軟件時一同卸載了。

configure: error: You need a C++ compiler for C++ support.
make[1]: *** [/usr/local/src/pcre-8.35/Makefile] Error 1
make[1]: Leaving directory `/usr/local/src/tengine-2.0.3'
make: *** [test] Error 2

  運行 yum install -y gcc gcc-c++

 

  3.  這是由於,openssl的路徑指定錯誤, 同pcre同樣,--with-openssl 不是安裝目錄而是解壓後的源文件目錄。

make[2]: Entering directory `/usr/local/openssl'
make[2]: *** No rule to make target `clean'.  Stop.
make[2]: Leaving directory `/usr/local/openssl'
make[1]: *** [/usr/local/openssl/.openssl/include/openssl/ssl.h] Error 2
make[1]: Leaving directory `/usr/local/src/tengine-2.0.3'
make: *** [test] Error 2

 

  4.  這個問題,百度google必應都找不到 關於 prove 的了。

  只有github上有說

    TEST_NGINX_BINARY=/path/to/nginx/sbin/nginx prove cases
    TEST_NGINX_BINARY=/path/to/nginx/sbin/nginx prove nginx-tests
/bin/sh: prove: command not found
make[1]: *** [test] Error 127
make[1]: Leaving directory `/usr/local/src/tengine-2.0.3'
make: *** [test] Error 2

  ^^ 再次編譯時已經找到解決方法了,  command not found 通常有兩種狀況: 

  1.  該程序已安裝可是命令並未這 # echo $PATH 這些路徑中, 這種加軟連接能夠解決。 

  2.  帶該命令的程序並未安裝,麻煩就在於不知道由什麼程序提供, 不過能夠用此方法(也可能你的軟件庫沒有該程序):

    # yum provides *bin/prove    // 這裏 'prove' 就是剛剛缺乏的command,

    // 找到結果是 perl-Test-Harness.xxx

    # yum install perl-Test-Harness

 

  5.  搜了好久, 最新版Tolua++ 1.0.93 暫不支持Lua 5.2.x

src/http/modules/lua/ngx_http_lua_log.c:81: error: ‘LUA_GLOBALSINDEX’ undeclared (first use in this function)
make[1]: *** [objs/src/http/modules/lua/ngx_http_lua_log.o] Error 1

  

  6.    這個聽說是64位下可能有的錯誤。

/usr/bin/ld: /usr/local/lib/liblua.a(lapi.o): relocation R_X86_64_32 against `luaO_nilobject_' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/liblua.a: could not read symbols: Bad value

    見編譯lua步驟說明,64bit系統可能出現的這個問題。  

 

  7.  查看 version時, 提示 libssl.so.1.0.0 找不到。此時nginx也沒法啓動。

[root@localhost tengine]# /usr/local/tengine/sbin/nginx -V
sbin/nginx: error while loading shared libraries: libssl.so.1.0.0: cannot open shared object file: No such file or directory

  ldd 查看 ,爲 not found

[root@localhost tengine]# ldd sbin/nginx
	linux-gate.so.1 =>  (0x00880000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00f05000)
	libdl.so.2 => /lib/libdl.so.2 (0x001ef000)
	libcrypt.so.1 => /lib/libcrypt.so.1 (0x00a0b000)
	libpcre.so.0 => /lib/libpcre.so.0 (0x00c21000)
	libssl.so.1.0.0 => not found
	libcrypto.so.1.0.0 => not found
	libz.so.1 => /lib/libz.so.1 (0x001f4000)
	libc.so.6 => /lib/libc.so.6 (0x00208000)
	/lib/ld-linux.so.2 (0x00d5b000)
	libfreebl3.so => /lib/libfreebl3.so (0x00748000)

  這時在  /etc/ld.so.conf.d/ 新建一個.conf 的文件,內容爲 libssl 的位置: 

[root@localhost tengine]# cd /etc/ld.so.conf.d 
[root@localhostld.so.conf.d]# touch www-libs.conf             // *.conf 自動載入
[root@localhostld.so.conf.d]# echo '/usr/local/lib' > www-libs.conf    // 注:/usr/local/lib 爲我 libssl.so.1.0.0 的位置
[root@localhostld.so.conf.d]# ldconfig

  如今能夠看到 nginx的版本及模塊信息了

 

  4、 輔助設置

  設置開機啓動。

  先建立nginx啓動腳本。

    # vim /etc/init.d/nginx

  而後修改(紅色部分)並粘貼, 保存退出。 (這是copy來的內容)

#!/bin/bash
# Tengine Startup script# processname: nginx
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# pidfile: /var/run/nginx.pid
# config: /usr/local/tengine/conf/nginx.conf

nginxd=/usr/local/tengine/sbin/nginx
nginx_config=/usr/local/tengine/conf/nginx.conf
nginx_pid=/var/run/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 "tengine is 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 /var/run/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 --level 2345 nginx on  

 

 若是啓動失敗,錯誤提示如: 

     nginx: [emerg] unknown directive "deny" in ...

這通常是未載入帶該directive的module(見官方module頁)。 nginx全部的module目前必須編譯時選擇, 幸虧tengine能夠動態載入

 nginx.conf 

dso {
    load ngx_http_fastcgi_module.so;
    load ngx_http_rewrite_module.so;
    load ngx_http_access_module;          ## 'deny', 'allow' 就屬於這個module
}

http { ...... }

錯誤提示如:
      nginx: [emerg] unknown "fastcgi_https" variable  ...

這通常是 server 配置中使用了未定義的變量 $fastcgi_https , 使用正確的變量或自定義便可。

 

配置nginx.conf,使用和 php-fpm 相同的 user 和 group, use epoll ,不出意外nginx已經可以運行php了。 

相關文章
相關標籤/搜索