NSX Load Balancer

Były już wpisy o ESG, a jedną ze składowych jest NSX Load Balancer, na którym skupię się w dzisiejszym wpisie.

Przygotowanie środowiska

Do celów testowych mam już 2 wirtualne maszyny z Photon OS, na którym uruchomię nginx jak kontener – tu trochę zabawy oraz poznanie Dockera. Będą one nam służyły jak serwery do których będziemy balansować ruch.

Nasza konfiguracja będzie wyglądać tak jak na rysunku

Logujemy się do wirtualnej (kroki powtórzymy na drugiej maszynie)

Last login: Wed Jun 21 07:04:58 2017 from 192.168.0.100
root@photon-cb64c1f92f04 [ ~ ]#

uruchamiamy Dockera

root@photon-cb64c1f92f04 [ ~ ]# systemctl start docker

uruchamiamy kontener z nginx z przekierowanie portu 80

root@photon-cb64c1f92f04 [ ~ ]# docker run -d -p 80:80 vmwarecna/nginx
Unable to find image 'vmwarecna/nginx:latest' locally
latest: Pulling from vmwarecna/nginx








Digest: sha256:f73bbae0f31823c06478b1fa5efb4957bc25239802fd5ea94e4442c0a6090d23
Status: Downloaded newer image for vmwarecna/nginx:latest
6f943686e8aa3906afa4208aa799e50fa144b5b341afdf786081994f9aafdb65
root@photon-cb64c1f92f04 [ ~ ]#

przechodzimy do basha na kontenerze

root@photon-cb64c1f92f04 [ ~ ]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
547e822003eb        vmwarecna/nginx     "nginx -g 'daemon off"   21 seconds ago      Up 20 seconds       0.0.0.0:80->80/tcp, 443/tcp   hungry_ptolemy
root@photon-cb64c1f92f04 [ ~ ]# docker exec -it 547e822003eb bash
root@547e822003eb:/#

Instalujemy sobie edytor jakiś

root@547e822003eb:/# apt-get update
Get:1 http://security.debian.org wheezy/updates Release.gpg [1554 B]
Get:2 http://security.debian.org wheezy/updates Release [39.0 kB]                                                            
Get:3 http://security.debian.org wheezy/updates/main amd64 Packages [679 kB]                                              
Get:4 http://nginx.org wheezy Release.gpg [287 B]                                                
Get:5 http://http.debian.net wheezy Release.gpg [2373 B]              
Get:6 http://nginx.org wheezy Release [2343 B]                        
Ign http://nginx.org wheezy Release                                     
Get:7 http://http.debian.net wheezy-updates Release.gpg [1554 B]        
Get:8 http://http.debian.net wheezy Release [191 kB]
Get:9 http://nginx.org wheezy/nginx amd64 Packages [27.9 kB]
Get:10 http://http.debian.net wheezy-updates Release [155 kB]                          
Get:11 http://http.debian.net wheezy/main amd64 Packages [7634 kB]                        
Get:12 http://http.debian.net wheezy-updates/main amd64 Packages [7481 B]
Fetched 8742 kB in 3s (2778 kB/s)
Reading package lists... Done
W: GPG error: http://nginx.org wheezy Release: The following signatures were invalid: KEYEXPIRED 1471427554
root@547e822003eb:/# apt-get install vim
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libgpm2 vim-common vim-runtime
Suggested packages:
  gpm ctags vim-doc vim-scripts
The following NEW packages will be installed:
  libgpm2 vim vim-common vim-runtime
0 upgraded, 4 newly installed, 0 to remove and 16 not upgraded.
Need to get 5642 kB of archives.
After this operation, 25.2 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://security.debian.org/ wheezy/updates/main vim-common amd64 2:7.3.547-7+deb7u3 [163 kB]
Get:2 http://security.debian.org/ wheezy/updates/main vim-runtime all 2:7.3.547-7+deb7u3 [4601 kB]
Get:3 http://http.debian.net/debian/ wheezy/main libgpm2 amd64 1.20.4-6 [35.8 kB]
Get:4 http://security.debian.org/ wheezy/updates/main vim amd64 2:7.3.547-7+deb7u3 [842 kB]
Fetched 5642 kB in 1s (5418 kB/s)                        
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libgpm2:amd64.
(Reading database ... 7163 files and directories currently installed.)
Unpacking libgpm2:amd64 (from .../libgpm2_1.20.4-6_amd64.deb) ...
Selecting previously unselected package vim-common.
Unpacking vim-common (from .../vim-common_2%3a7.3.547-7+deb7u3_amd64.deb) ...
Selecting previously unselected package vim-runtime.
Unpacking vim-runtime (from .../vim-runtime_2%3a7.3.547-7+deb7u3_all.deb) ...
Adding 'diversion of /usr/share/vim/vim73/doc/help.txt to /usr/share/vim/vim73/doc/help.txt.vim-tiny by vim-runtime'
Adding 'diversion of /usr/share/vim/vim73/doc/tags to /usr/share/vim/vim73/doc/tags.vim-tiny by vim-runtime'
Selecting previously unselected package vim.
Unpacking vim (from .../vim_2%3a7.3.547-7+deb7u3_amd64.deb) ...
Setting up libgpm2:amd64 (1.20.4-6) ...
Setting up vim-common (2:7.3.547-7+deb7u3) ...
Setting up vim-runtime (2:7.3.547-7+deb7u3) ...
Processing /usr/share/vim/addons/doc
Setting up vim (2:7.3.547-7+deb7u3) ...
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vim (vim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vimdiff (vimdiff) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rvim (rvim) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/rview (rview) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/vi (vi) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/view (view) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/ex (ex) in auto mode
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in auto mode
root@547e822003eb:/#

Modyfikujemy plik index.html gdzie dodajemy ip serwera

root@547e822003eb:/# vi /usr/share/nginx/html/index.html 
<!DOCTYPE html>
<html>
 <head>
  <title>Welcome to nginx!</title>
  <style>
       body {
           width: 35em;
            margin: 0 auto;
              font-family: Tahoma, Verdana, Arial, sans-serif;
      }

       img {
         margin-left: auto;
       margin-right: auto;
      }
  </style>
 </head>
 <body>
  <h1>Welcome to nginx on Photon! My IP 172.16.11.12</h1>
  <p>If you see this page, the nginx web server is successfully installed and  working. Further configuration is required.</p>

  <p>For more Photon info such as Wiki's, guides and code itself - head to
  <a href="http://www.github.com/vmware/photon/">GitHub</a>.<br/>
  <img src="splash.jpg"/>

  <p>For online documentation and support for Nginx please refer to
  <a href="http://nginx.org/">nginx.org</a>.<br/>
  <p><em>Thank you for using trying nginx on Photon.</em></p>
 </body>
</html>

"/usr/share/nginx/html/index.html" 30L, 869C written
root@547e822003eb:/#

tak wygląda strona po modyfikacji

Powyższe kroki potarzamy na drugim serwerze.

Konfiguracja NSX Load Balancer

Logujemy się do naszego vCenter i przechodzimy do Network & Security a następnie do NSX Edges gdzie wybieramy nasze ESG

Gdzie przechodzimy do Manage –> Settings –> Interfaces

wybieramy nasz uplink i dodajemy secendary adres który posłuży nam jako VIP

po kliknięciu OK przechodzimy do zakładki Load Balancer

gdzie klikamy Edit w prawym rogu i włączamy funkcjonalność Load Balancera

następnie przechodzimy do Application Profiles, gdzie stworzymy profil aplikacji którą będziemy wystawiać przez nasz Load Balancer, nadajemy nazwę profilu oraz typ – naszym przypadku będzie HTTP a mamy do wyboru jeszcze HTTPS,  TCP oraz UDP

w kolejnym kroku przechodzimy do Pools gdzie konfigurujemy naszą pulę serwerów klikając zielony plusik

w nowym oknie nadajemy nazwę pooli, wybieramy Algorytm rozrzucania ruchu po nodach

klikając zaznaczony plusik dodajemy nasze nody do pooli – nadajemy nazwę nodowi, wpisujemy jego IP lub wybieramy obiekt z vCenter – zrobiłem błąd w nazwie i musiałem ją edytować

po edycji nazwy

i dodaniu obu nodów mamy zatwierdzamy naszą pulę serwerów

klikamy ok i przechodzimy do Virtual Servers, gdzie konfigurujemy naszego VIP’a

klikamy zaznaczony plusik, gdzie w nowym oknie

wybieramy nasz profil Application Profile, nadajemy nazwę naszemu profilowi a następnie wybieramy adres VIP klikając na Select IP Address lub wpisujemy go z palca (musi być to adres dodany jako secandary IP w Interfejsach)

w polu Default Pool wybieramy naszą zdefiniowaną wcześniej pulę serwerów

I to był nasz ostatni etap konfiguracji, klikamy OK i przechodzimy do weryfikacji

Weryfikacja

Otwieramy przeglądarkę i otwieramy adres naszego VIP’a -jeżeli wszystko działa powinna otworzyć się strona z któregoś z serwerów

Przechodząc w konsoli naszego ESG do Load Balancere –> Pools klikając na Show Pool Statistics następnie wybierając naszą pulę pojawią się nasze serwery – gdzie zobaczymy, że oba są UP

z poziomu CLI mamy dostępne komendy do weryfikacji naszego Load Balancera

  show configuration loadbalancer
  show configuration loadbalancer monitor
  show configuration loadbalancer monitor MONITOR_NAME
  show configuration loadbalancer pool
  show configuration loadbalancer pool POOL_NAME
  show configuration loadbalancer rule
  show configuration loadbalancer rule RULE_NAME
  show configuration loadbalancer virtual
  show configuration loadbalancer virtual VS_NAME
  show service loadbalancer
  show service loadbalancer error
  show service loadbalancer monitor
  show service loadbalancer pool
  show service loadbalancer pool NAME
  show service loadbalancer session
  show service loadbalancer session l4
  show service loadbalancer session l7
  show service loadbalancer table
  show service loadbalancer table NAME
  show service loadbalancer table NAME ARGS
  show service loadbalancer virtual
  show service loadbalancer virtual NAME
  show statistics loadbalancer pool POOL_NAME
  show statistics loadbalancer pool POOL_NAME MINUTES
  show statistics loadbalancer virtual VS_NAME
  show statistics loadbalancer virtual VS_NAME MINUTES

przykładowe wyniki CLI:

esg01-0> show configuration loadbalancer 
-----------------------------------------------------------------------
vShield Edge Loadbalancer Config:
{
   "monitorService" : {
      "logging" : {
         "logLevel" : "info",
         "enable" : true
      },
      "enable" : true,
      "healthMonitors" : [
         {
            "url" : null,
            "maxRetries" : 3,
            "name" : "default_tcp_monitor",
            "interval" : 5,
            "timeout" : 15,
            "method" : null,
            "type" : "tcp",
            "extension" : null,
            "expected" : null,
            "receive" : null,
            "send" : null
         },
         {
            "receive" : null,
            "send" : null,
            "type" : "http",
            "extension" : null,
            "expected" : null,
            "name" : "default_http_monitor",
            "interval" : 5,
            "timeout" : 15,
            "method" : "GET",
            "url" : "/",
            "maxRetries" : 3
         },
         {
            "maxRetries" : 3,
            "url" : "/",
            "timeout" : 15,
            "method" : "GET",
            "name" : "default_https_monitor",
            "interval" : 5,
            "type" : "https",
            "extension" : null,
            "expected" : null,
            "receive" : null,
            "send" : null
         }
      ]
   },
   "loadBalancer" : {
      "enable" : true,
      "vips" : [
         {
            "sessionPersistence" : null,
            "name" : "web01",
            "redirection" : null,
            "accelerationEnabled" : false,
            "applicationRules" : null,
            "insertXForwardedFor" : false,
            "defaultPool" : "Web-01",
            "mode" : "http",
            "serverSslEnabled" : false,
            "ipAddresses" : [
               "[10.20.200.10]:80"
            ],
            "maxConn" : 0,
            "rateLimit" : 0,
            "clientSsl" : null,
            "serverSsl" : null
         }
      ],
      "logging" : {
         "enable" : true,
         "logLevel" : "info"
      },
      "objectSet" : null,
      "accelerationEnabled" : false,
      "applicationRules" : null,
      "pools" : [
         {
            "name" : "Web-01",
            "applicationRules" : [],
            "algorithm" : {
               "urlParam" : null,
               "headerName" : null,
               "method" : "round-robin",
               "uriDepth" : null,
               "uriLength" : null
            },
            "members" : [
               {
                  "maxConn" : 0,
                  "weight" : 1,
                  "objectId" : null,
                  "ipAddress" : "172.16.11.11",
                  "minConn" : 0,
                  "condition" : "enabled",
                  "monitorPort" : 80,
                  "healthMonitors" : [
                     "default_http_monitor"
                  ],
                  "name" : "web01",
                  "port" : 80
               },
               {
                  "weight" : 1,
                  "objectId" : null,
                  "maxConn" : 0,
                  "minConn" : 0,
                  "ipAddress" : "172.16.11.12",
                  "condition" : "enabled",
                  "monitorPort" : 80,
                  "healthMonitors" : [
                     "default_http_monitor"
                  ],
                  "name" : "web02",
                  "port" : 80
               }
            ],
            "transparent" : {
               "enable" : false
            }
         }
      ]
   }
}

 

esg01-0> show service loadbalancer virtual 
-----------------------------------------------------------------------
Loadbalancer VirtualServer Statistics: 

VIRTUAL web01
|  ADDRESS [10.20.200.10]:80  
|  SESSION (cur, max, total) = (0, 4, 19)
|  RATE (cur, max, limit) = (0, 3, 0)
|  BYTES in = (79242), out = (262453)
   +->POOL Web-01
   |  LB METHOD round-robin
   |  LB PROTOCOL L7
   |  Transparent disabled 
   |  SESSION (cur, max, total) = (0, 1, 158)
   |  BYTES in = (79242), out = (260408)
      +->POOL MEMBER: Web-01/web01, STATUS: UP
      |  |  HEALTH MONITOR = BUILT-IN, default_http_monitor:L7OK
      |  |  |  LAST STATE CHANGE: 2017-06-21 09:02:39
      |  |  SESSION (cur, max, total) = (0, 1, 79)
      |  |  BYTES in = (39568), out = (87691)
      +->POOL MEMBER: Web-01/web02, STATUS: UP
      |  |  HEALTH MONITOR = BUILT-IN, default_http_monitor:L7OK
      |  |  |  LAST STATE CHANGE: 2017-06-21 09:02:39
      |  |  SESSION (cur, max, total) = (0, 1, 79)
      |  |  BYTES in = (39674), out = (172717)

 

esg01-0> show statistics loadbalancer virtual web01
TIMESTAMP                BYTESIN        SESSIONRATE    SESSIONS       BYTESOUT       HTTPREQS       
2017-06-21 15:42:20      00             00             00             00             168            
2017-06-21 15:42:00      00             00             00             00             168            
2017-06-21 15:41:40      00             00             00             00             168            
2017-06-21 15:41:20      00             00             00             00             168            
2017-06-21 15:41:00      00             00             00             00             168            
2017-06-21 15:40:40      00             00             00             00             168            
2017-06-21 15:40:20      00             00             00             00             168            
2017-06-21 15:40:00      00             00             00             00             168            
2017-06-21 15:39:40      00             00             00             00             168            
2017-06-21 15:39:20      00             00             00             00             168            
2017-06-21 15:39:00      12             00             00             28             168            
2017-06-21 15:38:40      537            00             00             1201           167            
2017-06-21 15:38:20      1579           00             01             3483           141            
2017-06-21 15:38:00      213            00             01             470            80             
2017-06-21 15:37:40      00             00             00             00             72

 

Pasjonat komputerowy od zawsze oraz maniak w zakresie sieci, wirtualizacji oraz bezpieczeństwa IT. Kompetentny inżynier z dużym doświadczeniem w realizacji projektów informatycznych i telekomunikacyjnych. Wieloletni administrator IT, który utrzymuje systemy informatyczne dostosowując je do wymogów biznesowych z zapewnieniem dostępności 24/7/365.
Posts created 126

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top