NSX Edge ロードバランサ(LB)を NSX API で設定変更してみます。

 

概要については、こちらをどうぞ。

NSX Edge LB の API 操作を体験してみる。Part 1(はじめに)

 

前回の投稿はこちらです。

NSX Edge LB の API 操作を体験してみる。Part 4(LB メンバのステータス確認)

 

手順について。

 

今回は、既存の NSX Edge に、NSX API で SSL 証明書作成~仮想サーバ設定をします。

既存の NSX Edge(Perimeter-Gateway)の設定変更をします。

  1. SSL証明書の生成
    1. CSR 作成
    2. 自己署名による証明書の作成
  2. アプリケーションプロファイルの作成
  3. バックエンド プールの作成とメンバの追加
  4. 仮想サーバの設定変更

 

設定対象になる NSX Edge の ID は edge-2 です。

nsxapi-lb-p5-01.png

 

1-1. SSL証明書の生成: CSR 作成

 

今回の SSL 設定では、NSX Edge で 自己署名の証明書を作成して使用します。

 

まず CSR (証明書の署名要求)を、下記の情報で作成します。

  • 共通名: web-app.corp.local
  • 組織名: web-app.corp.local
  • 組織単位: VMWorld
  • 地域: San Francisco
  • 状態(というか州): CA
  • 国: US


XML ファイル(csr-web-app.txt)を作成します。

cat <<EOF > csr-web-app.txt

<csr>

  <subject>

    <attribute>

      <key>CN</key>

      <value>web-app.corp.local</value>

    </attribute>

    <attribute>

      <key>O</key>

      <value>web-app.corp.local</value>

    </attribute>

    <attribute>

      <key>OU</key>

      <value>VMworld</value>

    </attribute>

    <attribute>

      <key>L</key>

      <value>San Francisco</value>

    </attribute>

    <attribute>

      <key>ST</key>

      <value>CA</value>

    </attribute>

    <attribute>

      <key>C</key>

      <value>US</value>

    </attribute>

  </subject>

  <algorithm>RSA</algorithm>

  <keySize>2048</keySize>

</csr>

EOF

 

XML ファイルを読み込んで、CSR を作成します。

cat csr-web-app.txt | curl -k -s -u admin:VMware1! -X POST -H 'Content-type: text/xml' -d @- https://192.168.110.15/api/2.0/services/truststore/csr/edge-2

 

SSL 証明書の署名で指定するため、今回作成した CSR の ID を特定しておきます。

curl -k -s -u admin:VMware1! -X GET https://192.168.110.15/api/2.0/services/truststore/csr/scope/edge-2 | xmllint --xpath '//csr[cn="web-app.corp.local"]/objectId' - | more

 

CSR の ID は、csr-5 でした。

nsxapi-lb-p5-02.png

 

ちなみに、この CSR の情報は、下記で表示することができます。

curl -k -s -u admin:VMware1! -X GET https://192.168.110.15/api/2.0/services/truststore/csr/csr-5 | xmllint --format -

 

1-2. SSL証明書の生成: 自己署名による証明書の作成

 

自己署名付き証明書を作成します。

先ほど作成した csr-5 を、有効期限 365日で署名します。

curl -k -s -u admin:VMware1! -X PUT https://192.168.110.15/api/2.0/services/truststore/csr/csr-5?noOfDays=365

 

証明書の情報は、下記のように確認することができます。

curl -k -s -u admin:VMware1! -X GET https://192.168.110.15/api/2.0/services/truststore/certificate/scope/edge-2 | xmllint --format -

 

後の手順で指定するため、作成した証明書の ID を確認しておきます。

curl -k -s -u admin:VMware1! -X GET https://192.168.110.15/api/2.0/services/truststore/certificate/scope/edge-2 | xmllint --xpath '//certificate[name="web-app.corp.local"]/objectId' - | more

 

certificate-11 として作成されたことがわかります。

nsxapi-lb-p5-03.png

 

Web Client でも、今回作成した CSR と SSL 証明書が表示されます。

nsxapi-lb-p5-04.png

 

2. アプリケーションプロファイルの作成

 

SSL 終端のためのアプリケーション プロファイルを作成します。

  • 名前: Web-SSL-Term-Profile-01
  • タイプ: HTTPS
  • サービス証明書: 証明書「web-app.corp.local」 → certificate-11

 

XML ファイル(app-prof-sslterm.txt)を作成します。

cat <<EOF > app-prof-sslterm.txt

<applicationProfile>

  <name>Web-SSL-Term-Profile-01</name>

  <insertXForwardedFor>false</insertXForwardedFor>

  <sslPassthrough>false</sslPassthrough>

  <template>HTTPS</template>

  <serverSslEnabled>false</serverSslEnabled>

  <clientSsl>

    <clientAuth>ignore</clientAuth>

    <serviceCertificate>certificate-11</serviceCertificate>

  </clientSsl>

</applicationProfile>

EOF

 

アプリケーション プロファイルを作成します。

cat app-prof-sslterm.txt | curl -k -s -u admin:VMware1! -X POST -H 'Content-type: text/xml' -d @- https://192.168.110.15/api/4.0/edges/edge-2/loadbalancer/config/applicationprofiles

 

applicationProfile-2 として作成されました。

nsxapi-lb-p5-05.png

 

作成されたアプリケーション プロファイルの ID は、API でも確認できます。

curl -k -s -u admin:VMware1! -X GET https://192.168.110.15/api/4.0/edges/edge-2/loadbalancer/config/applicationprofiles | xmllint --xpath '//applicationProfile[name="Web-SSL-Term-Profile-01"]/applicationProfileId' - | more

nsxapi-lb-p5-05a.png

 

3. バックエンド プールの作成とメンバの追加

 

プールへのメンバーの追加前回と異なり、Edge から Web サーバへは 80番ポートを指定。

 

今回のプール設定です。

  • 名前: Web-Tier-Pool-02
  • モニタ: NONE のまま

 

メンバ1

  • 名前: web-01a
  • IP 172.16.10.11
  • ポート: 80
  • モニタ ポート: 80

 

メンバ2

  • 名前: web-02a
  • IP 172.16.10.12
  • ポート: 80
  • モニタ ポート: 80

 

XML ファイル(pool-web-tier-2.txt)を作成します。

cat <<EOF > pool-web-tier-2.txt

<pool>

  <name>Web-Tier-Pool-02</name>

  <description></description>

  <transparent>false</transparent>

  <algorithm>round-robin</algorithm>

  <member>

    <ipAddress>172.16.10.11</ipAddress>

    <weight>1</weight>

    <port>80</port>

    <name>web-01a</name>

    <monitorPort>80</monitorPort>

  </member>

  <member>

    <ipAddress>172.16.10.12</ipAddress>

    <weight>1</weight>

    <port>80</port>

    <name>web-02a</name>

    <monitorPort>80</monitorPort>

  </member>

</pool>

EOF

 

プールを作成します。

cat pool-web-tier-2.txt | curl -k -s -u admin:VMware1! -X POST -H 'Content-type: text/xml' -d @- https://192.168.110.15/api/4.0/edges/edge-2/loadbalancer/config/pools

 

pool-2 としてプールが作成されました。Web Client ではこう見えます。

nsxapi-lb-p5-06.png

 

作成されたプールの ID は、API でも確認できます。

curl -k -s -u admin:VMware1! -X GET https://192.168.110.15/api/4.0/edges/edge-2/loadbalancer/config/pools | xmllint --xpath '//pool[name="Web-Tier-Pool-02"]/poolId' - | more

nsxapi-lb-p5-07.png

 

4. 仮想サーバの設定変更

 

今回は、既存の仮想サーバの設定を変更します。

 

仮想サーバ「Web-Tier-SSL-01」の ID を確認しておきます。

curl -k -s -u admin:VMware1! -X GET https://192.168.110.15/api/4.0/edges/edge-2/loadbalancer/config/virtualservers | xmllint --xpath '//virtualServer[name="Web-Tier-SSL-01"]/virtualServerId' - | more

 

設定対象の仮想サーバの ID は、virtualServer-1 です。

nsxapi-lb-p5-08.png

 

変更しない設定値は、もともとの値を指定しておきます。

  • 名前: Web-Tier-SSL-01 → virtualServer-1
  • IP アドレス: 192.168.100.4
  • プロトコル: HTTPS
  • ポート: 443
  • アプリケーション プロファイル: Web-SSL-Term-Profile-01 → applicationProfile-2 ★変更
  • デフォルト プール: Web-Tier-Pool-02 → pool-2 ★変更

 

XML ファイル(vs-web-tier-2.txt)を作成します。

cat <<EOF > vs-web-tier-2.txt

<virtualServer>

  <virtualServerId>virtualServer-1</virtualServerId>

  <name>Web-Tier-SSL-01</name>

  <enabled>true</enabled>

  <ipAddress>192.168.100.4</ipAddress>

  <protocol>https</protocol>

  <port>443</port>

  <connectionLimit>0</connectionLimit>

  <connectionRateLimit>0</connectionRateLimit>

  <applicationProfileId>applicationProfile-2</applicationProfileId>

  <defaultPoolId>pool-2</defaultPoolId>

  <enableServiceInsertion>false</enableServiceInsertion>

  <accelerationEnabled>false</accelerationEnabled>

</virtualServer>

EOF

 

XML ファイルを読み込んで、設定変更します。

cat vs-web-tier-2.txt | curl -k -s -u admin:VMware1! -X PUT -H 'Content-type: text/xml' -d @- https://192.168.110.15/api/4.0/edges/edge-2/loadbalancer/config/virtualservers/virtualServer-1

 

設定変更が反映されました。

nsxapi-lb-p5-09.png

 

これで、テストページ「SSL-Offload-Web-A...」の表示ができるようになります。

nsxapi-lb-p5-10.png

 

HoL のシナリオをもとにした単純な設定ですが、

このように NSX Edge のロードバランサを NSX API で設定するととができます。

 

以上、NSX API で NSX Edge LB を設定してみる話でした。