CentOSに7 nginxのWebサービスの展開

A、nginxのサービス基盤

nginxのは、最高の安定性とシステムリソースの低消費の利点を知られているパフォーマンスの最適化、のために特別に開発され、高い処理能力HTTP同時接続(単一の物理サーバが同時要求50,000 30,000をサポートすることができます)。このため、ソーシャルネットワーキング、ニュース、電子商取引およびウェブホスティングの多数を提供し、サービス会社は、nginxのWebサービスを提供することを選択しました。

1、nginxのサービスの利点

nginxのは非常に優れた特性の多くを持っていた非常に高性能のWeb牛とリバースプロキシサーバー、次のとおりです。

  • 高い同時接続:50,000公式テストは2に実行する同時接続、本番環境での〜3Wの同時接続をサポートすることができます。
  • 少ないメモリ消費量:同時接続の3W、オープン10のnginxのプロセスが消費のみメモリ150M(15M×10 = 150M);
  • 設定ファイルは非常に簡単です:理解しやすいプログラムと同じスタイル。
  • コスト:nginxのは、オープンソースソフトウェア、自由に使用すると、購入F5 BIG-IPとして、NetScalerの負荷分散スイッチなどのハードウェアは数十元の数十万人に何千ものを必要とされます。
  • サポート書き換え書き換えルール:別のドメイン名、URL、およびHTTPリクエストに応じて、異なるバックエンドサーバーファームに配布されています。
  • 内蔵ヘルスチェック機能:バックエンドWebサーバーのnginxのプロキシのバックエンドがダウンした場合、フロントアクセスには影響しません。
  • 保存帯域幅:GZIP圧縮をサポートし、あなたがローカルブラウザキャッシュヘッダーヘッドを追加することができます。
  • 高い安定性:リバースプロキシ、確率は最小限のダウンタイムです。

第二に、nginxのインストールおよび展開

1、準備ができて

nginxの最新の安定バージョン1.12.0、それは公式サイトからファイルをインストールすることができますnginxの公式サイト /ダウンロード。

1)CentOSに7サーバー;
2)Windowsクライアント:
3)CentOSに7オペレーティング・システム・イメージ、
4)nginxのミラーを、
全てのミラーとnginxのインストールパッケージは、アクセスネットワークディスク抽出するために使用することができます。https://pan.baidu.com/s/18iRCuiMEyGbEFSeBp17uVQ
抽出コード:qszt

2、nginxのサーバー配備インストールを開始

1)マウントLinuxのCD、は/ usr / src /ディレクトリにnginxの依存プログラムをコピーします

CentOSに7 nginxのWebサービスの展開

[root@centos02 ~]# mount /dev/cdrom /mnt/    <!--挂载光盘-->
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# cp /mnt/nginx-1.6.0.tar.gz /usr/src/ <!--拷贝Nginx包到/usr/src/目录-->

2)ディレクトリMNTは/ usr / src /ディレクトリにすべてのデータをコピーし、LAMPディスクを切り替えます

[root@centos02 ~]# umount /mnt/ &lt;!--卸载光盘--&gt;
CentOSに7 nginxのWebサービスの展開

[root@centos02 ~]# mount /dev/cdrom /mnt/   <!--挂载光盘-->
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# cp /mnt/* /usr/src/ <!--将光盘目录下所有数据拷贝到/usr/src/目录-->

3)オペレーティング・システム、インストール依存プログラムnginxのに光ディスクを切り替えます

[root@centos02 ~]# umount /mnt/ &lt;!--卸载光盘--&gt;
CentOSに7 nginxのWebサービスの展開

[root@centos02 ~]# mount /dev/cdrom /mnt/   <!--挂载光盘-->
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos02 ~]# rm -rf /etc/yum.repos.d/CentOS-* <!--清除系统自带yum源-->
[root@centos02 ~]# yum -y install pcre-devel zlib-devel <!--安装Nginx的依赖程序-->
[root@centos02 ~]# useradd -M -s /sbin/nologin nginx <!--创建管理Nginx的用户-->
[root@centos02 ~]# tar zxvf /usr/src/nginx-1.6.0.tar.gz -C /usr/src/ 
<!--解压缩Nginx软件包-->
[root@centos02 ~]# cd /usr/src/nginx-1.6.0/ 
[root@centos02 nginx-1.6.0]# ./configure --prefix=/usr/local/nginx
--user=nginx --group=nginx --with-http_stub_status_module
<!--配置Nginx-->
[root@centos02 nginx-1.6.0]# make && make install  <!--编译安装Nginx-->
[root@centos02 ~]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin/ <!--优化Nginx执行命令-->

3、nginxの基本的な管理サービス

[root@centos02 ~]# nginx    <!--启动Nginx服务-->
[root@centos02 ~]# netstat -anptu | grep nginx 
                     <!--监听Nginx服务是否启动成功-->
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4663/nginx: master  
[root@centos02 ~]# killall -s QUIT nginx   <!--关闭Nginx服务-->
[root@centos02 ~]# killall -3 nginx       <!--关闭Nginx服务-->
[root@centos02 ~]# killall -1 nginx     <!--重新启动Nginx-->
[root@centos02 ~]# killall -s HUP nginx   <!--重新启动Nginx-->
[root@centos02 ~]# vim /etc/init.d/nginx <!--编写Nginx服务管理脚本-->
#!/bin/bash
#chkconfig: 35 90 30
#description:nginx server
PROG="/usr/local/nginx/sbin/nginx"
PIDF="/usr/local/nginx/logs/nginx.pid"
case "$1" in
start)
$PROG
;;
stop)
kill -s QUIT $(cat $PIDF)
;;
restart)
$0 stop
$0 start
;;
reload)
kill 0s HUP $(cat $PIDF)
;;
*)
echo "Usage:$0 (start|stop|restart|reload)"
exit 1
esac
exit 0
[root@centos02 ~]# chmod +x /etc/init.d/nginx <!--添加脚本执行权限-->
[root@centos02 ~]# chkconfig --add nginx <!--添加为系统服务-->
[root@centos02 ~]# chkconfig --level 35 nginx on <!--设置开机自动启动-->
[root@centos02 ~]# /etc/init.d/nginx stop<!--脚本停止Nginx服务-->
[root@centos02 ~]# /etc/init.d/nginx start<!--脚本启动Nginx服务-->
[root@centos02 ~]# /etc/init.d/nginx restart<!--脚本重启Nginx服务-->

1つのカードネットワークセグメントとnginxのサーバーとクライアントの構成は、アクセスnginxのWebサーバーにゲートウェイを設定します
CentOSに7 nginxのWebサービスの展開

4、nginxの一般的なコンフィギュレーション・ファイル

[root@centos02 ~]# ls -ld /usr/local/nginx/conf/nginx.conf
-rw-r--r-- 1 root root 2656 11月 28 17:22
/usr/local/nginx/conf/nginx.conf       <!--Nginx的主配置文件-->
[root@centos02 ~]# ls -ld /usr/local/nginx/sbin/
drwxr-xr-x 2 root root 19 11月 28 17:22
/usr/local/nginx/sbin/      <!--管理Nginx服务程序文件-->
[root@centos02 ~]# ls -ld /usr/local/nginx/html/
drwxr-xr-x 2 root root 40 11月 28 17:22
/usr/local/nginx/html/      <!--Nginx的网站根目录-->
[root@centos02 ~]# ls -ld /usr/local/nginx/logs/
drwxr-xr-x 2 root root 58 11月 28 17:47 
/usr/local/nginx/logs/   <!--Nginx的网站日志记录-->

図5に示すように、修飾されたマスター構成ファイルnginxの

[root@centos02 ~]# cp /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/conf/nginx.conf.bak   <!--备份主配置文件-->
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf 
                            <!--编辑主配置文件-->
  3 user  nginx;       <!--运行用户-->
  4 worker_processes  1;     <!--工作进程数量-->
  6 error_log  logs/error.log;   <!--错误日志文件的位置-->
12 pid        logs/nginx.pid;     <!--PID文件的位置-->
16     use epoll;        <!--使用epoll模型-->
17     worker_connections  1024; <!--每进程处理1024个连接-->
29     #access_log  logs/access.log  main; <!--访问日志的位置-->
31     sendfile        on;           <!--开启高效传输文件模式-->
35     keepalive_timeout  65;       <!--连接保持超时-->
39     server { <!--server的开始,一个server表示一个虚拟主机-->
40         listen       80;     <!--Web服务的监听配置-->
41         server_name  localhost; <!--网站名称(FQDN)-->
44         charset utf-8;    <!--网页的默认字符集-->
48         location / {     <!--根目录配置-->
49             root   html; <!--网站根目录的位置,相对于安装目录-->
50             index  index.html index.html;<!--默认首页(索引页)-->
51         }
84     }            <!--server结束-->
  • 聞く:定義するポートは、「IPアドレス:ポート番号」で定義されているIPアドレスを可能にしながら、フォーマット、ルート文が設定された特定のアクセスページ文書のパスの場所に使用され、ディレクトリの下にデフォルトのhtml / nginxのインストールディレクトリは、必要に応じて変更することができます他のパス/ var / www / htmlと設定などが、変更はnginxのユーザーが読み取りアクセス権を持っていることを確認する必要があります。

  • worker_processes:ワークプロセスの数を指定することができるCPUコアの合計数を参照して、サーバのCPU場合は、マルチコアプロセッサの複数によって、ワークプロセスの数を表します。worker_connectionsの設定項目に反映特定の意味。

  • worker_connections:この設定項目は、例えば、典型的には10000未満の(デフォルトは1024)、構成要素上のワークプロセスの数に関連する各プロセス接続処理を、指定:ワークプロセスの数が8である場合、各処理プロセス4096接続、接続の数は、nginxの通常のサービスが30,000以上(* 8 = 32768 4096)を有する可能にしました。もちろん、パフォーマンスは、サーバハードウェア、ネットワーク帯域幅の特定の物理的な条件に依存します。

国家統計に6、nginxのは、コンフィギュレーションアクセス

[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf 
 <!--修改nginx配置文件,指定访问位置并打开stub_status配置-->
 52         location /status {
 53                 stub_status     on;
 54                 access_log off;
 55         }
[root@centos02 ~]# /etc/init.d/nginx restart<!--重启Nginx服务--> 

クライアントアクセス状態の統計ページ:
CentOSに7 nginxのWebサービスの展開

  • アクティブな接続は:アクティブな接続の現在の数を示します。

  • サーバーが処理要求を受け入れる:、処理された接続の数を表す3つの数字が続き、接続情報が処理されたことを、成功のTCPハンドシェイク時間を示し、要求の数は、処理されています。

第三に、仮想ホストの設定

1、DNSサーバのインストール

[root@centos02 ~]# yum -y install bind bind-chroot bind-utils 
                              <!--安装DNS-->
[root@centos02 ~]# echo "" > /etc/named.conf 
           <!--清空主配置文件-->
[root@centos02 ~]# vim /etc/named.conf <!--修改主配置文件-->
options {
        listen-on port 53 { 192.168.100.20; };
        directory "/var/named";
}
zone    "benet.com"     IN      {
        type    master;
        file    "benet.com.zone";
}
zone    "accp.com"      IN      {
        type    master;
        file    "accp.com.zone";
}
[root@centos02 ~]# named-checkconf -z /etc/named.conf
              <!--检查主配置文件是否配置错误-->
[root@centos02 ~]# vim /var/named/benet.com.zone  
               <!--配置benet.com的正向解析区域-->
$TTL    86400
@       SOA     benet.com.      root.benet.com(
        2019112801
        1H
        15M
        1W
        1D
)
@       NS      centos02.benet.com.
centos02 A      192.168.100.20
www      A      192.168.100.20
[root@centos02 ~]# chmod +x /var/named/benet.com.zone  
                    <!--正向解析区域配置文件添加执行权限-->
[root@centos02 ~]# chown named:named
/var/named/benet.com.zone <!--修改属主属组-->
[root@centos02 ~]# named-checkzone benet.com
/var/named/benet.com.zone   
         <!--检查benet.com正向解析区域配置文件是否错误-->
zone benet.com/IN: loaded serial 2019112801
OK
[root@centos02 ~]# cp /var/named/benet.com.zone
/var/named/accp.com.zone  
   <!--复制benet.com正向解析区域到accp.com正向解析区域-->
[root@centos02 ~]# vim /var/named/accp.com.zone  
                    <!--修改accp.com正向解析区域配置文件-->
$TTL    86400
@       SOA     accp.com.       root.accp.com(
        2019112801
        1H
        15M
        1W
        1D
)
@       NS      centos02.accp.com.
centos02 A      192.168.100.20
www      A      192.168.100.20
[root@centos02 ~]# named-checkzone accp.com
/var/named/accp.com.zone  
           <!--检查accp.com正向解析区域配置文件是否错误-->
[root@centos02 ~]# vim /etc/sysconfig/network-scripts/
ifcfg-ens32  <!--编辑网卡添加主DNS-->
DNS1=192.168.100.20   <!--添加主DNS-->
[root@centos02 ~]# systemctl restart network<!--重启网卡服务-->
[root@centos02 ~]# systemctl start named <!--启动DNS服务器-->
[root@centos02 ~]# systemctl enable named<!--设置开机自动启动-->
[root@centos02 ~]# nslookup www.benet.com  
                 <!--解析域名测试是否正常-->
Server:     192.168.100.20
Address:    192.168.100.20#53

Name:   www.benet.com
Address: 192.168.100.20

[root@centos02 ~]# nslookup www.accp.com
                  <!--解析域名测试是否正常-->
Server:     192.168.100.20
Address:    192.168.100.20#53

Name:   www.accp.com
Address: 192.168.100.20

2は、configure名前ベースのバーチャルホスト

「HTTP {}」タグはアクセスログを含め、HTTPサーバーの設定を定義するために使用されたを使用してnginxの設定ファイルは、httpポート、Webディレクトリ、デフォルトの文字セット、接続が残るだけでなく、仮想ウェブホスティング、PHPの決意グローバル設定と他のサイトの大タグ部分は、サブセット内の「{}サーバ」を規定することを含みます。特定のサイトの設定の代わりに「サーバー{}」。

            <!--创建虚拟主机网站根目录--> 
[root@centos02 ~]# mkdir -p /var/www/benetcom  
[root@centos02 ~]# mkdir -p /var/www/accpcom  
              <!--创建虚拟主机的网站主页--> 
[root@centos02 ~]# echo "www.benet.com" > 
/var/www/benetcom/index.html
[root@centos02 ~]# echo "www.accp.com" > 
/var/www/accpcom/index.html
[root@centos02 ~]# vim /usr/local/nginx/conf/nginx.conf  
                     <!--修改Nginx主配置文件支持虚拟主机-->
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  {           <!--server开始-->
                listen www.benet.com:80;  <!--监听的域名及端口-->
                server_name www.benet.com;     <!--网站名称-->
                charset utf-8;          <!--默认字符集-->
                access_log      logs/www.benet.com.access.log; 
                                                    <!--访问日志位置-->
                error_log       logs/www.benet.com.error.log;
                                                       <!--错误日志位置-->
                location / {       <!--根目录配置-->
                                root /var/www/benetcom/; <!--网站根目录-->
                                index index.html;       <!--默认首页-->
                        }
                }       <!--server结尾-->

<!--以下配置请参考以上注释-->
        server  {
                listen www.accp.com:80;
                server_name www.accp.com;
                charset utf-8;
                access_log      logs/www.accp.com.access.log;
                error_log       logs/www.accp.com.error.log;
                location / {
                                root /var/www/accpcom/;
                                index index.html;
                        }
                }
[root@centos02 ~]# nginx -t   <!--检查Nginx是否配置错误-->
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@centos02 ~]# systemctl restart named<!--重新启动DNS服务-->
[root@centos02 ~]# /etc/init.d/nginx restart<!--重新启动Nginx服务-->

DNSクライアントがアドレスを追加し、アクセスドメインのテストが成功しました
CentOSに7 nginxのWebサービスの展開

CentOSに7 nginxのWebサービスの展開

------この記事を締結、読んでくれてありがとう------

おすすめ

転載: blog.51cto.com/14156658/2454960