溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Nginx1.10編譯安裝

發(fā)布時(shí)間:2020-07-22 22:41:15 來源:網(wǎng)絡(luò) 閱讀:539 作者:哈哈怪1111 欄目:建站服務(wù)器

Nginx1.10編譯安裝


企業(yè)實(shí)戰(zhàn)千萬PV的Nginx就得這么安裝

更多文章請(qǐng)?jiān)L問 烏龜運(yùn)維 wuguiyunwei.com


已經(jīng)上線六個(gè)個(gè)多月 現(xiàn)在非常穩(wěn)定 這是現(xiàn)在的整理


Nginx 下載

wget http://nginx.org/download/nginx-1.10.3.tar.gz

 

Openssl 下載

Wget https://www.openssl.org/source/openssl-1.1.0e.tar.gz

 

Pcre 下載

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

 

下載 jemalloc

wget https://github.com/jemalloc/jemalloc/releases/download/4.5.0/jemalloc-4.5.0.tar.bz2

解壓源碼包后如下圖

Nginx1.10編譯安裝

使用ljemalloc內(nèi)存優(yōu)化工具優(yōu)化Nginx

jemalloc是一個(gè)通用的malloc(3),實(shí)現(xiàn)強(qiáng)調(diào)碎片回避和可擴(kuò)展并發(fā)支持。jemalloc首先在2005年被用作FreeBSD libc分配器,從那時(shí)起它已經(jīng)發(fā)現(xiàn)了許多依賴于其可預(yù)測(cè)的行為的應(yīng)用程序。2010年,jemalloc開發(fā)工作擴(kuò)展到包括開發(fā)者支持功能,例如堆分析和廣泛的監(jiān)視/調(diào)整掛鉤?,F(xiàn)代的jemalloc版本繼續(xù)被集成回FreeBSD,因此通用性仍然至關(guān)重要。持續(xù)的開發(fā)努力趨向于使jemalloc成為用于廣泛的苛刻應(yīng)用的最佳分配器,并消除/減輕對(duì)現(xiàn)實(shí)世界應(yīng)用具有實(shí)際影響的弱點(diǎn)。

安裝 jemalloc

Nginx1.10編譯安裝

Nginx1.10編譯安裝

Nginx1.10編譯安裝

Nginx1.10編譯安裝

接下來安裝Nginx

安裝一些依賴  yum -y install zlib-devel gcc gcc-c++

創(chuàng)建用戶 useradd -M -s /sbin/nologin www

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.1.0e --with-pcre=../pcre-8.39 --with-pcre-jit --with-ld-opt=-ljemalloc

 

模塊介紹

–with-http_stub_status_module       //Nginx狀態(tài)監(jiān)控模塊

–with-http_v2_module               //配置Nginx支持HTTP2.0

–with-http_ssl_module              //配置Nginx 支持HTTPS

–with-http_gzip_static_module         //開啟Gzip靜態(tài)壓縮

–with-http_realip_module                 //獲取客戶端真是ip

–with-http_flv_module              //為Flash視頻(FLV)文件提供偽流服務(wù)器端支持

–with-http_mp4_module           //為MP4文件提供偽流服務(wù)器端支持。以.mp4,.m4v或.m4a文件擴(kuò)展名

–with-openssl=../openssl-1.1.0e       //指定Nginx ssl模塊依賴的ssl庫

–with-pcre=../pcre-8.39             //指定Nginx pcre模塊依賴的pcre庫

–with-pcre-jit                               //構(gòu)建具有“即時(shí)編譯”支持的PCRE庫

–with-ld-opt=                               //傳遞給C鏈接器的其他參數(shù)

Nginx1.10編譯安裝

Nginx1.10編譯安裝

啟動(dòng)Nginx查看端口監(jiān)聽狀況成功如下圖

Nginx1.10編譯安裝

接下來編寫配置nginx啟動(dòng)腳本(Centos“6-7”通用)

安裝工具 yum -y install coreutils

安裝daemontools daemontools是用于管理UNIX服務(wù)的工具的集合

以下安裝方法來自官網(wǎng) http://cr.yp.to/daemontools/install.html

mkdir -p /package

chmod 1755 /packagecd /package

下載 wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz

gunzip daemontools-0.76.tar

tar -xpf daemontools-0.76.tar

rm -f daemontools-0.76.tar

cd admin/daemontools-0.76

安裝

sed -i ‘s/extern int errno;/#include <errno.h>/1’ ./src/error.h

package/install

腳本內(nèi)容如下直接復(fù)制粘貼就可以用(請(qǐng)把上面環(huán)境配置好)

vim /etc/init.d/nginx

chmode +x /etc/init.d/nginx

Cent7 如下

Nginx1.10編譯安裝

Cent6 如下

Nginx1.10編譯安裝

#!/bin/sh
# chkconfig:   - 86 16
# http://goyun.org
. /etc/rc.d/init.d/functions

. /etc/sysconfig/network

[ "$NETWORKING" = "no" ] && exit 0

nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/lock/subsys/nginx

make_dirs() {  if [ -z "`grep $user /etc/passwd`" ]; then
    useradd -M -s /bin/nologin $user
  fi
  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: "
  $nginx -s stop
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f $lockfile
  return $retval
}

restart() {
  configtest || return $?
  stop
  sleep 3
  start
}

reload() {
  configtest || return $?
  echo -n $"Reloading $prog: "
  $nginx -s reload
  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
  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
添加Nginx為系統(tǒng)服務(wù) 開機(jī)自啟

Nginx1.10編譯安裝


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI