成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

Nginx 安裝

Yu_Huang / 2256人閱讀

摘要:使用雙處理器的系統(tǒng)使用可能會(huì)造成內(nèi)核崩潰高效方法,使用于內(nèi)核版本及以后的系統(tǒng),內(nèi)核要打補(bǔ)丁可執(zhí)行的實(shí)時(shí)信號(hào),不常見(jiàn)使用于,,和使用于,為了防止出現(xiàn)內(nèi)核崩潰的問(wèn)題,有必要安裝這個(gè)安全補(bǔ)丁。

nginx的優(yōu)點(diǎn)[摘自互聯(lián)網(wǎng)]
1. 處理靜態(tài)文件、索引文件以及自動(dòng)索引;打開(kāi)文件描述符緩沖。
2. 無(wú)緩存的反向代理加速,簡(jiǎn)單的負(fù)載均衡和容錯(cuò)。
3. FastCGI:簡(jiǎn)單的負(fù)載均衡和容錯(cuò)。
4. 模塊化的結(jié)構(gòu):包括 gzipping,byte ranges,chunked responses,以及SSI-filter等f(wàn)ilter。如果由FastCGI或其他代理服務(wù)器處理單頁(yè)中存在的多個(gè)SSI,則這項(xiàng)處理可以并行運(yùn)行,而不需要相互等待。
5. 支持SSL和TLS SNI
6. Nginx?專為性能優(yōu)化而開(kāi)發(fā),性能是其最重要的考量,實(shí)現(xiàn)上非常注重效率。它支持內(nèi)核Poll模型,能經(jīng)受高負(fù)載的考驗(yàn),有報(bào)告表明能支持高達(dá)50000個(gè)并發(fā)連接數(shù)。感謝Nginx為我們選擇了epoll and kqueue作為開(kāi)發(fā)模型。
7.?Nginx具有很高的穩(wěn)定性。其他HTTP服務(wù)器,當(dāng)遇到訪問(wèn)的峰值,或者有人惡意發(fā)起慢速連接時(shí),很可能會(huì)導(dǎo)致服務(wù)器物理內(nèi)存耗盡或頻繁交換,失去響應(yīng),只能重啟服務(wù)器。例如當(dāng)前apache一旦上到200個(gè)以上進(jìn)程,web響應(yīng)速度就明顯非常緩慢了。而Nginx采取了分階段資源分配技術(shù),使得它的CPU與內(nèi)存占用率非常低。Nginx官方表示保持10000個(gè)沒(méi)有活動(dòng)的連接,它只占2.5M內(nèi)存,所以類似DDOS這樣的攻擊對(duì)Nginx來(lái)說(shuō)基本上是毫無(wú)用處的。就穩(wěn)定性而言,Nginx比lighthttpd更勝一籌。
8. Nginx支持熱部署。它的啟動(dòng)特別容易,并且?guī)缀蹩梢宰龅?*24不間斷運(yùn)行,即使運(yùn)行數(shù)個(gè)月也不需要重新啟動(dòng)。你還能夠在不間斷服務(wù)的情況下,對(duì)軟件版本進(jìn)行升級(jí)。
9. Nginx采用master-slave模型,能夠充分利用SMP的優(yōu)勢(shì),且能夠減少工作進(jìn)程在磁盤(pán)I/O的阻塞延遲。當(dāng)采用select()/poll()調(diào)用時(shí),還可以限制每個(gè)進(jìn)程的連接數(shù)。
10. Nginx代碼質(zhì)量非常高,代碼很規(guī)范,手法成熟,模塊擴(kuò)展也很容易,特別值得一提的是強(qiáng)大的Upstream與Filter鏈。Upstream為諸如reverse proxy,與其他服務(wù)器通信模塊的編寫(xiě)奠定了很好的基礎(chǔ)。而Filter鏈最酷的部分就是各個(gè)filter不必等待前一個(gè)filter執(zhí)行完畢。它可以把前一個(gè)filter的輸出作為當(dāng)前filter的輸入,這有點(diǎn)像Unix的管道。這意味著,一個(gè)模塊可以開(kāi)始?jí)嚎s從后端服務(wù)器發(fā)送過(guò)來(lái)的請(qǐng)求,且可以在模塊接收完成后端服務(wù)器的整個(gè)請(qǐng)求之前把壓縮流轉(zhuǎn)向客戶端。?
11. 作為郵件代理服務(wù)器:Nginx同時(shí)也是一個(gè)非常優(yōu)秀的郵件代理服務(wù)器(最早開(kāi)發(fā)這個(gè)產(chǎn)品的目的之一也是作為郵件代理服務(wù)器),Last.fm描述了成功并且美妙的使用經(jīng)驗(yàn)。
11. Nginx采用了一些os提供的最新特性如對(duì)sendfile(Linux 2.2+),accept-filter(FreeBSD 4.1+),TCP_DEFER_ACCEPT(Linux 2.4+)的支持,從而大大提高了性能。?
事件模型
Nginx支持如下處理連接的方法(I/O復(fù)用方法),這些方法可以通過(guò)use指令指定。
1. select 標(biāo)準(zhǔn)方法
2. Poll 標(biāo)準(zhǔn)方法
3. Kueue 高效方法。使用FreeBSD 4.1+,OpenBSD 2.9+,NetBSD 2.0 和 MaxOS X。使用雙處理器的MacOS X系統(tǒng)使用kqueue可能會(huì)造成內(nèi)核崩潰
4. Epoll 高效方法,使用于Linux內(nèi)核2.6版本及以后的系統(tǒng),2.4內(nèi)核要打補(bǔ)丁
5. Rtsig 可執(zhí)行的實(shí)時(shí)信號(hào),不常見(jiàn)?
6. /dev/poll 使用于 Solaris 7 11/99+,HP/UX 11.22+(eventport),IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+
7. Eventport 使用于Solaris 10,為了防止出現(xiàn)內(nèi)核崩潰的問(wèn)題,有必要安裝這個(gè)安全補(bǔ)丁。
安裝 規(guī)劃
a. 主機(jī)名:n1.web.org
b. IP地址:192.168.128.21
c. 系統(tǒng):CentOS 6.5 64bit
d. 源碼目錄:/usr/local/src
e. 安裝目錄:/opt/nginx
安裝
a. 所需軟件包
    pcre-8.35.tar.gz
    zlib-1.2.8.tar.gz
    nginx-1.6.2.tar.gz
b. 準(zhǔn)備工作
    [root@nginx1 ~]# yum -y install gcc gcc-c++ autoconf automake make libtool openssl openssl-devel
    [root@nginx1 ~]# useradd -M -s /sbin/nologin www
c. 安裝pcre
    [root@nginx1 src]# tar -zxvf pcre-8.35.tar.gz 
    [root@nginx1 src]# cd pcre-8.35
    [root@nginx1 pcre-8.35]# ./configure --prefix=/opt/nginx/pcre
    [root@nginx1 pcre-8.35]# make && make install
d. 安裝zlib
    [root@nginx1 src]# tar -zxvf zlib-1.2.8.tar.gz 
    [root@nginx1 src]# cd zlib-1.2.8
    [root@nginx1 zlib-1.2.8]# ./configure --prefix=/opt/nginx/zlib
    [root@nginx1 zlib-1.2.8]# make && make install
e. 安裝nginx
    [root@nginx1 src]# tar -zxvf nginx-1.6.2.tar.gz 
    [root@nginx1 src]# cd nginx-1.6.2
    [root@nginx1 nginx-1.6.2]# more nginx.configure 
    ./configure 
    --user=www --group=www 
    --prefix=/opt/nginx/nginx 
    --with-http_stub_status_module 
    --with-http_ssl_module 
    --with-http_realip_module 
    --with-http_sub_module 
    --with-http_flv_module 
    --with-http_dav_module 
    --with-http_addition_module 
    --with-pcre=/usr/local/src/pcre-8.35 
    --with-zlib=/usr/local/src/zlib-1.2.8 
    --with-cc-opt="-O3" 
    --with-cpu-opt=opteron
    [root@nginx1 nginx-1.6.2]# make && make install
f. Nginx編譯優(yōu)化
    ① GCC 參數(shù)優(yōu)化
    默認(rèn)nginx使用的GCC的編譯參數(shù)是-O。需要更加優(yōu)化可以使用以下兩個(gè)參數(shù)(即上面安裝nginx時(shí).configure的最后兩項(xiàng)) --with-cc-opt="-O3" --with-cpu-opt=opteron 使得編譯針對(duì)特定CPU以及增加GCC的優(yōu)化。此方法僅對(duì)性能有所改善(大概增加性能1%左右)并不會(huì)有很大的性能提升,僅供參考。?
    ② 修改Nginx的header偽裝服務(wù)器
    vi nginx-1.6.2/src/core/nginx.h
    #ifndef _NGINX_H_INCLUDED_
    #define _NGINX_H_INCLUDED_?
    #define nginx_version ? ? ?1005007
    #define NGINX_VERSION ? ? ?"**1.5.7**"
    #define NGINX_VER ? ? ? ? ?"**nginx**/" NGINX_VERSION
    #define NGINX_VAR ? ? ? ? ?"NGINX"
    #define NGX_OLDPID_EXT ? ? ".oldbin"
    #endif /* _NGINX_H_INCLUDED_ */?
    修改加粗標(biāo)記的文字為自己想要修改的文字即可。如,NGINX_VERSION 修改為5.7,NGINX_VER修改為Milo。
    用curl測(cè)試:curl -I 192.168.128.21,Server會(huì)返回Milo/5.7,而不是原來(lái)的Nginx服務(wù)器和版本號(hào)了。
    ③ Tcmalloc優(yōu)化Nginx性能
    從Nginx 0.6.29 添加Feature:the ngx_google_perftools_module 以來(lái),Nginx也可以利用Tcmalloc來(lái)提升性能。
配置[簡(jiǎn)單的初步配置]
    [root@nginx1 conf]# more nginx.conf
    user  www www;
    worker_processes  1;

    error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;

    pid        /var/run/nginx.pid;

    worker_rlimit_nofile 65535;
    events {
        use epoll;
        worker_connections  65535;
    }

    http {
        include       mime.types;
        default_type  application/octet-stream;

        log_format  main  "$remote_addr - $remote_user [$time_local] "$request" "
                          "$status $body_bytes_sent "$http_referer" "
                          ""$http_user_agent" "$http_x_forwarded_for"";

        access_log  logs/access.log  main;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 8m;

        sendfile        on;
        tcp_nopush     on;

        #keepalive_timeout  0;
        keepalive_timeout  65;

        tcp_nodelay on;
        gzip  on;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_http_version 1.0;
        gzip_comp_level 2;
        gzip_types text/plain application/x-javascript text/css application/xml;
        gzip_vary on;

        server {
            listen       80;
            server_name  web.xsl.com;
            index index.html index.htm;
            root /app/web/www;

            # location / {
            #    root   html;
            #    index  index.html index.htm;
            # }

            #error_page  404              /404.html;

            # redirect server error pages to the static page /50x.html
            #
            # error_page   500 502 503 504  /50x.html;
            # location = /50x.html {
            #    root   html;
            # }

            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}

            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}

            # deny access to .htaccess files, if Apache"s document root
            # concurs with nginx"s one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }


        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;

        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}


        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;

        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;

        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;

        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;

        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}

    }
啟動(dòng)腳本
    [root@nginx1 conf]# more /etc/init.d/nginx 
    #!/bin/sh
    #
    # chkconfig: - 85 15

    # processname: nginx
    # config: /opt/nginx/nginx/conf/nginx.conf
    # pidfile: /var/run/nginx.pid

    # 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="/opt/nginx/nginx/sbin/nginx"
    prog=$(basename $nginx)

    NGINX_CONF_FILE="/opt/nginx/nginx/conf/nginx.conf"

    lockfile=/var/lock/subsys/nginx

    start() {
        [ -x $nginx ] || exit 5
        [ -f $NGINX_CONF_FILE ] || exit 6
        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
        start
    }

    reload() {
        configtest || return $?
        echo -n $"Reloading $prog: "
        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

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/39185.html

相關(guān)文章

  • nginx服務(wù)器詳細(xì)安裝過(guò)程(使用yum 和 源碼包兩種安裝方式,并說(shuō)明其區(qū)別)

    摘要:網(wǎng)上看別人寫(xiě)的服務(wù)器配置,有的是源碼包安裝的,有的時(shí)安裝的。通過(guò)源碼包編譯安裝的軟件,通常都放在包名路徑下。正則表達(dá)式使用在指令和模塊中。 網(wǎng)上看別人寫(xiě)的 nginx 服務(wù)器配置 ,有的是源碼包安裝的,有的時(shí) yum 安裝的。如果是新手,可能會(huì)有疑問(wèn),這兩種安裝方式有什么區(qū)別?我應(yīng)該使用哪種方式?系統(tǒng)里可以兩個(gè)都安裝可以嗎?怎么卸載?等等問(wèn)題,那么在這里,我做下總結(jié),詳細(xì)介紹下這兩種方...

    waruqi 評(píng)論0 收藏0
  • Nginx筆記-0-Centos環(huán)境下安裝

    摘要:如果發(fā)現(xiàn)運(yùn)行只有一行回顯,可能是當(dāng)前端口被占用,使用端口號(hào),默認(rèn),如果打印結(jié)果為兩行或以上,即端口被占用,需要修改配置文件的端口號(hào)再重新運(yùn)行。 概述 記錄一下 Nginx 通過(guò)安裝包以及通過(guò)源代碼安裝兩種方式。目標(biāo)是第一次接觸 Nginx 的人也能看懂直接用。 一. 使用安裝包配置 Tip: 這種安裝方式比較簡(jiǎn)單,官方文檔也說(shuō)得比較清楚詳細(xì)。這里搭建的環(huán)境是 Centos7, 可以sy...

    Rindia 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<