天天看點

[Nginx基礎]-- 源碼安裝nginx

一、安裝nginx
安裝步驟:
1\\下載下傳使用穩定版本:nginx-1.8.1.tar.gz
2\\使用ssh工具複制到/home目錄下,解壓—》tar –zxvf  nginx-1.8.1.tar.gz 
3\\進入解壓後的目錄: cd  /home/nginx-1.8.1
#./configure  --prefix=/home/nginx(此處的/home/nginx目錄是安裝目錄) ---à回車
A、如果預編譯,檢查沒有錯誤則說明正确!可以下一步安裝
B、如果有錯誤,檢視目前版本---》yum info ?(如zlib)
(1)然後安裝對應得版本,本次安裝時,需要jdk對應nginx版本都是開發者版本:
”yum –y install  pcre-devel”、”yum –y install  zlib-devel”
強制解除安裝: “rpm -e --nodeps pcre ”
           (2)再檢查./configure  --prefix=/home/nginx沒有錯誤
4\\在剛才的解壓目錄下(cd  /home/nginx-1.8.1)下,執行make指令---》然後make install
5\\通路不成功,說明防火牆開着
            需要關閉防火牆---------》service iptables status  -------àservice iptables stop(close)
            檢視開機是否啟動à chkconfig  --list | grep ntp----à關閉chkconfig  iptables off(on)
           檢視程序—》[root@node4 logs]# ps aux | grep nginx-----》殺死程序:kill pid
 6\\浏覽器通路:192.168.142.102即可
 
優點:可以自定義添加nginx的功能子產品
 
二、安裝tengine
 
A---解壓tengine.tar.gz到home目錄下
B---在解壓目錄下,執行預編譯檢查
./configure \
  --prefix=/opt/sxt/soft/tengine-2.1.0/ \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx/nginx.pid  \
  --lock-path=/var/lock/nginx.lock \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --http-client-body-temp-path=/var/tmp/nginx/client/ \
  --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  --http-scgi-temp-path=/var/tmp/nginx/scgi \
  --with-pcre
(a)檢查正常:在目前解壓目錄下執行”make && make install ”
(b)如果檢查異常:根據需要安裝開發者包
C---添加到系統資料庫:vim /etc/network 
D---進入” /etc/network”目錄下,建立nginx,将nginx裡面的内容(檢視本文備注)拷貝進來,
注意三點,a)建立檔案,b)編輯模式,c)這裡要修改兩個參數
nginx="/opt/sxt/soft/tengine-2.1.0/sbin/nginx"
NGINX_CONF_FILE="/opt/sxt/soft/tengine-2.1.0/conf/nginx.conf"
E---在” /etc/network”目錄下,修改權限可執行,#chmod 755 nginx
F---遞歸調用建立需要的檔案夾  mkdir  –p  /var/tmp/nginx/client/
G --service nginx start(stop,restart)  啟動正常結果
the configuration file /opt/sxt/soft/tengine-2.1.0/conf/nginx.conf syntax is ok
configuration file /opt/sxt/soft/tengine-2.1.0/conf/nginx.conf test is successful
Stopping nginx:                                            [  OK  ]
Starting nginx:                                            [  OK  ]
M不用yum安裝----》原因源安裝是可以安裝子產品,而yum則不行,必須解除安裝後才能重新安裝
 
 
 
 
備注一:tengine的配置:建立的nginx檔案在---》 cd /etc/network目錄下
#!/bin/bash
#
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/tengine-2.1/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/tengine-2.1/conf/nginx.conf"
#[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
#make_dirs() {
#   # make required directories
#   user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
#   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
#   for opt in $options; do
#       if [ `echo $opt | grep '.*-temp-path'` ]; then
#           value=`echo $opt | cut -d "=" -f 2`
#           if [ ! -d "$value" ]; then
#               # echo "creating" $value
#               mkdir -p $value && chown -R $user $value
#           fi
#       fi
#   done
#}
start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
#    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
restart() {
    configtest || return $?
    stop
    sleep 1
    start
}
reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
#  -HUP是nginx平滑重新開機參數  
    killproc $nginx -HUP
    RETVAL=$?
    echo
}
force_reload() {
    restart
}
configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac      
上一篇: 字首數組

繼續閱讀