GNU/Linux >> Linux の 問題 >  >> Rocky Linux

RockyLinux8にNginx用のVarnish7をインストールする方法

Varnish cacheは、コンテンツをメモリにキャッシュすることでWebサイトを高速化するために使用される無料のオープンソースキャッシュアクセラレータです。これは非常に高速で、ページの読み込み時間を短縮します。これにより、SERPが向上し、ユーザーエクスペリエンスが向上します。 Facebook、Twitter、Wikipediaなどの多くの組織で使用されています。 Varnishは、Nginxと、クライアントからリクエストを受信して​​バックエンドに転送するクライアントの間に位置します。 Varnishはメモリからコンテンツを提供するため、これによりWebサーバーのパフォーマンスが向上します。

このチュートリアルでは、RockyLinux8のNginxの前にVarnish7をインストールする方法を紹介します。

前提条件
  • RockyLinux8を実行しているサーバー。
  • ルートパスワードはサーバーで構成されています。

Varnish7をインストール

開始する前に、システムから既存のワニスモジュールを無効にする必要があります。次のコマンドを実行して無効にできます:

dnf module disable varnish

次の出力が表示されます。

==============================================================================================================================================
 Package                           Architecture                     Version                           Repository                         Size
==============================================================================================================================================
Disabling modules:
 varnish                                                                                                                                     

Transaction Summary
==============================================================================================================================================

Is this ok [y/N]: y
Complete!

次に、次のコマンドを使用してEPELリポジトリをインストールします。

dnf install epel-release -y

次に、次のコマンドを使用して、VarnishCache7リポジトリをシステムに追加します。

curl -s https://packagecloud.io/install/repositories/varnishcache/varnish70/script.rpm.sh | bash

リポジトリが追加されたら、次のコマンドを使用してVarnish7をインストールします。

dnf install varnish -y

インストールが正常に完了したら、次のコマンドを使用してワニスに関する情報を確認します。

rpm -qi varnish

次の出力が表示されます。

Name        : varnish
Version     : 7.0.2
Release     : 1.el8
Architecture: x86_64
Install Date: Sunday 13 February 2022 06:24:35 AM UTC
Group       : System Environment/Daemons
Size        : 8907085
License     : BSD
Signature   : (none)
Source RPM  : varnish-7.0.2-1.el8.src.rpm
Build Date  : Wednesday 12 January 2022 02:25:34 PM UTC
Build Host  : 7fc509e75620
Relocations : (not relocatable)
URL         : https://www.varnish-cache.org/
Summary     : High-performance HTTP accelerator
Description :
This is Varnish Cache, a high-performance HTTP accelerator.
ワニスサービスの管理

Varnishをインストールした後、次のコマンドを使用して、Varnishサービスを開始し、システムの再起動時に開始できるようにします。

systemctl start varnish
systemctl enable varnish

次のコマンドを使用して、ワニスのステータスを確認できます。

systemctl status varnish

次の出力が得られます:

? varnish.service - Varnish Cache, a high-performance HTTP accelerator
   Loaded: loaded (/usr/lib/systemd/system/varnish.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-02-13 06:24:56 UTC; 6s ago
  Process: 2555 ExecStart=/usr/sbin/varnishd -a :6081 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m (c>
 Main PID: 2556 (varnishd)
    Tasks: 217
   Memory: 104.5M
   CGroup: /system.slice/varnish.service
           ??2556 /usr/sbin/varnishd -a :6081 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m
           ??2567 /usr/sbin/varnishd -a :6081 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m

Feb 13 06:24:55 rockylinux systemd[1]: Starting Varnish Cache, a high-performance HTTP accelerator...
Feb 13 06:24:55 rockylinux varnishd[2556]: Version: varnish-7.0.2 revision 9b5f68e19ca0ab60010641e305fd12822f18d42c
Feb 13 06:24:55 rockylinux varnishd[2556]: Platform: Linux,4.18.0-348.12.2.el8_5.x86_64,x86_64,-junix,-smalloc,-sdefault,-hcritbit
Feb 13 06:24:55 rockylinux varnishd[2556]: Child (2567) Started
Feb 13 06:24:56 rockylinux varnishd[2556]: Child (2567) said Child starts
Feb 13 06:24:56 rockylinux systemd[1]: Started Varnish Cache, a high-performance HTTP accelerator.
ワニスの構成

デフォルトでは、Varnishはポート6081でリッスンします。ここでは、Varnishを使用して着信HTTP接続を受け入れます。したがって、ポート80でリッスンするようにVarnishを構成する必要があります。これは、/usr/lib/systemd/system/varnish.serviceを編集することで実行できます。 ファイル:

nano /usr/lib/systemd/system/varnish.service

以下に示すように、ポート6081を80に変更します。

ExecStart=/usr/sbin/varnishd -a :80 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,2g

ファイルを保存して閉じてから、systemdデーモンをリロードして変更を適用します。

systemctl daemon-reload

次に、Varnishサービスを再起動して、変更を適用します。

systemctl restart varnish

次に、次のコマンドを使用して、Varnishリスニングポートを確認します。

ss -antpl | grep varnish

次の出力にVarnishリスニングポートが表示されます。

LISTEN 0      10         127.0.0.1:46093      0.0.0.0:*    users:(("varnishd",pid=2819,fd=13))                            
LISTEN 0      128          0.0.0.0:80         0.0.0.0:*    users:(("cache-main",pid=2830,fd=6),("varnishd",pid=2819,fd=6))
LISTEN 0      128        127.0.0.1:8443       0.0.0.0:*    users:(("cache-main",pid=2830,fd=9),("varnishd",pid=2819,fd=9))
LISTEN 0      10             [::1]:33963         [::]:*    users:(("varnishd",pid=2819,fd=12))                            
LISTEN 0      128             [::]:80            [::]:*    users:(("cache-main",pid=2830,fd=7),("varnishd",pid=2819,fd=7))
LISTEN 0      128            [::1]:8443          [::]:*    users:(("cache-main",pid=2830,fd=8),("varnishd",pid=2819,fd=8))

Varnishと連携するようにNginxを構成する

このセクションでは、Nginxをインストールし、Varnishで動作するように構成します。まず、次のコマンドを使用してNginxパッケージをインストールします。

dnf install nginx -y

Nginxをインストールした後、Nginx構成ファイルを編集し、Nginxのデフォルトのリスニングポートを 80から変更する必要があります。 8080へ 。

次のコマンドを使用して、Nginxメイン構成ファイルを編集します。

nano /etc/nginx/nginx.conf

次の行を見つけます:

	listen       80 default_server;
        listen       [::]:80 default_server;

そして、それらを次の行に置き換えました:

	listen       8080 default_server;
        listen       [::]:8080 default_server;

終了したらファイルを保存して閉じ、Nginxサービスを開始して変更を適用します。

systemctl start nginx

次のコマンドを使用して、Nginxのステータスを確認することもできます。

systemctl status nginx

次の出力が得られます:

? nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2022-02-13 06:29:02 UTC; 8s ago
  Process: 5627 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 5626 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 5624 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 5629 (nginx)
    Tasks: 2 (limit: 11412)
   Memory: 6.7M
   CGroup: /system.slice/nginx.service
           ??5629 nginx: master process /usr/sbin/nginx
           ??5630 nginx: worker process

Feb 13 06:29:02 rockylinux systemd[1]: Starting The nginx HTTP and reverse proxy server...
Feb 13 06:29:02 rockylinux nginx[5626]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 13 06:29:02 rockylinux nginx[5626]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 13 06:29:02 rockylinux systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Feb 13 06:29:02 rockylinux systemd[1]: Started The nginx HTTP and reverse proxy server.
Varnishキャッシュを確認する

この時点で、Varnishがインストールされ、NginxWebサーバーで構成されます。次に、Varnishキャッシュをテストします。

次のコマンドを実行して、Varnishキャッシュを確認します。

curl -I http://your-server-ip

すべてが正常であれば、次の出力が得られます:

HTTP/1.1 200 OK
Server: nginx/1.14.1
Date: Sun, 13 Feb 2022 06:30:06 GMT
Content-Type: text/html
Content-Length: 3429
Last-Modified: Thu, 10 Jun 2021 09:09:03 GMT
ETag: "60c1d6af-d65"
X-Varnish: 2
Age: 0
Via: 1.1 varnish (Varnish/7.0)
Accept-Ranges: bytes
Connection: keep-alive
結論

おめでとう!これで、VarnishwithNginxがRockyLinux8に正常にインストールされました。これで、本番環境にVarnishを実装して、Webサイトのパフォーマンスを高速化できます。ご不明な点がございましたら、お気軽にお問い合わせください。


Rocky Linux
  1. RockyLinux8にNginxを使用してModSecurityをインストールする方法

  2. RockyLinux8にGulp.jsをインストールする方法

  3. Rocky Linux 8 に Redis をインストールする方法

  1. RockyLinux8にNGINX用のLet'sEncryptSSLをインストールする方法

  2. RockyLinux8にPython3.9をインストールする方法

  3. RockyLinux8にNginxを使用してApacheTomcat10をインストールする方法

  1. RockyLinuxにNginxでJoomlaをインストールする方法

  2. RockyLinux8.4のインストール方法

  3. RockyLinux8にDockerCEをインストールする方法