This article describes a means by which vCommander® administrators can configure services to be load balanced by adding a Linux VM to a multi-node service, which acts as the load balancer. The example provided here will be deploying a load-balanced web server with two nodes, but you can update the solution as appropriate for your use.


Requirements



Scripts


Download and extract the script to your vCommander application server. Embotics recommends storing all scripts called by vCommander in a single location, using sub-folders to identify the functions of particular scripts. With the scripts extracted to C: on the vCommander server, the file system will look like this:


  • C:\scripts\lb\2node_LB_Setup.ps1


The script requires minor updates before it will work in your system.


Setting
Description
$vCommanderServer
The hostname or IP address of the vCommander server.
$CredFile
The credentials file which handles access to your vCommander. For more details, refer to this knowledgebase article.
$IPAttribute
The custom attribute used to capture addresses for the
$WebAttribute
The custom attribute used to indicate whether or not a component is a web server.
$LBAttribute
The custom attribute used to indicate whether or not a component is a load balancer.


Additionally, you can comment out the following lines to prevent creation of a text log in the specified directory. The logs are overwritten with each run of the script.creation of a text log in the specified directory. The logs are overwritten with each run of the script.



Creating the Custom Attributes


In order for this solution to work, you must first create three custom attributes. The first tracks whether or not a component is the load balancer:


  1. Under the Configuration menu, click Custom Attributes.
  2. Click Add.
  3. On the Define Attributes page, configure the options as follows and then click Next:

    Name: Load Balancer
    Description: Indicates whether or not the component is a load balancer.
    Type: List
    Applies To: All Types
    Edit in Service Portal: Disabled

  4. Add the values Yes and No to the list, and then click Finish.


The second custom attribute indicates whether or not a component is a node in the service:


  1. Click Add.
  2. On the Define Attributes page, configure the options as follows and then click Next:

    Name: Web Server
    Description: Indicates whether or not the component is a web server node.
    Type: List
    Applies To: All Types
    Edit in Service Portal: Disabled

  3. Add the values Yes and No to the list, and then click Finish.


The last custom attribute is used to capture the IP addresses for the components.for the components.


  1. Click Add.
  2. On the Define Attributes page, configure the options as follows and then click Next:

    Name: IP Address
    Description: Captures address for components.
    Type: Text
    Applies To: Services (Vms, Virtual Services, etc.)
    Edit in Service Portal: Disabled

  3. Choose Free Form and click Finish.



Creating the Service Catalog Entry


Next, create the Service Catalog entry for the load-balanced service. 


  1. Under the Configuration menu, choose Service Request Configuration.
  2. Switch to the Service Catalog tab, and click Add Service.
  3. Add a meaningful Name and Description and select an appropriate Icon and categories. Click Next.


  4. Click Add and choose a Linux VM or template to configure as the load balancer, and the two images to be the balanced web servers. Click Next.


  5. Configure the three service components as necessary for your environment. The load balancer component must be configured with the custom attribute Load Balancer set to yes.

    The web server components must be configured with the custom attribute Web Server set to yes, and the IP Address variable applied with no default value.

    Click Next.

  6. On the Deployment page, choose to Deploy Service As: Virtual Service and make sure the Deployment/Startup Order lists the two web servers in Group 1 and the load balancer in Group 2 as shown below. Check Start Deployed Components and click Next.


  7. Complete the wizard granting appropriate visibility and reviewing your choices.


Creating the Completion Workflows


Distinct completion workflows are required for both the load balancer and the web servers. First, create the completion workflow for the load balancer.


  1. Under the Configuration menu, choose Service Request Configuration.
  2. Switch to the Completion Workflow tab. Click Add.
  3. Provide a Name and choose to Apply this workflow after a VM is deployed. Click Next.

  4. On the Steps page, click Add > Wait for Event and configure the step as follows:

    Step Name: Wait for IP and DNS
    Step Execution: Always Execute
    Wait For: Service to obtain IP address and DNS name
    Wait Time: 200 seconds
    Wait Time Exceeded: Mark workflow step as failed: do not proceed

  5. Click Add > Lifecycle Management > Set Custom Attribute and configure the step as follows.:

    Step Name: Set Custom Attribute
    Step Execution: Alwways Execute
    IP Address: #{target.ipv4Address}

  6. Click Add > Execute Script and configure the step as follows:

    Step Name: Setup Load Balancer Config
    Step Execution: Always Execute
    Timeout: 300 seconds
    Script Output: Capture script output as comment
    When Step Fails: Mark workflow step as failed: do not proceed
    Command Line:

    powershell.exe c:\scripts\loadbalancer\2node_LB_Setup.ps1 #{request.id}


  7. Click Add > Guest OS > Create File and configure the step as follows:

    Step Name: Create File
    Step Execution: Always Execute
    When Step Fails: Mark workflow step as failed: do not proceed
    Credentials: (Use appropriate root access to the OS)
    Contents:

    ProxyRequests off
    SSLProxyEngine on
    SSLProxyVerify none
    SSLProxyCheckPeerCN off
    SSLProxyCheckPeerName off
    SSLProxyCheckPeerExpire off
    SSLVerifyClient optional
    SSLCertificateFile "/etc/httpd/ssl/apache.crt"
    SSLCertificateKeyFile "/etc/httpd/ssl/apache.key"
    
    <Proxy *>
      Order deny,allow
      Allow from all
    </Proxy>
    
    Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
    <Proxy balancer://webfarm >
      BalancerMember http://#{target.customAttribute['LBWebServer']} route=1 loadfactor=1 connectiontimeout=10 retry=600 timeout=30
      BalancerMember http://#{target.customAttribute['LBWebServer1']} route=2 loadfactor=1 connectiontimeout=10 retry=600 timeout=30
      ProxySet lbmethod=byrequests
      ProxySet stickysession=ROUTEID
    </Proxy>
    
    <Location /balancer-manager>
      SetHandler balancer-manager
    </Location>
    
    ProxyPass /balancer-manager !
    ProxyPass / balancer://webfarm/
    ProxyPassReverse / balancer://webfarm



    Destination: /etc/httpd/conf.d/loadbalancer.conf
    Overwrite: Enabled


  8. Click Add > Guest OS > Run Program and configure the step as follows:

    Step Name: Restart Service
    Step Execution: Always execute
    Timeout: 400 seconds
    Credentials: (use credentials with root access on image)
    Program Output: Capture program output as comment
    When Program Fails: Mark workflow step as failed: do not proceed
    Command Line: 

    /bin/systemctl restart httpd.service



  9. Click Add > Send Email and configure the step as follows, then click Next:

    Step Name: Send Email
    Step Execution: Always execute
    Address List: #{request.requester.email}
    Email Subject: Load Balanced configuration is complete
    Email Body: 

    #{request.requester.name},
    
    Your load balanced web-app has been deployed, to check the load balancer status please navigate to http://#{target.ipv4Addresses}/balancer-manager
    
    Web server IP addresses are #{target.settings.customAttribute['LBWebServer']} and #{target.settings.customAttribute['LBWebServer1']}. 
    
    Cheers, 
    
    vCommander Admin. 


    Email Format: HTML, include standard request info


  10. On the Assigned Components page select the load balancer component then click Next.

  11. Review your choices on the Summary page and click Finish.


Next, create the completion workflow for the web servers.


  1. Under the Configuration menu, choose Service Request Configuration.
  2. Switch to the Completion Workflow tab. Click Add.
  3. Provide a Name and choose to Apply this workflow after a VM is deployed. Click Next.

  4. Click Add > Wait for Event and configure the step as follows:

    Step Name: Wait For IP and DNS
    Step Execution:  Always execute
    Wait For:  Service to obtain IP address and DNS name
    Wait Time: 400 seconds
    Wait Time Exceeded : Mark workflow step as failed: do not proceed

  5.  Click Add > Lifecycle Management > Set Custom Attribute and configure the step as follows, then click Next:

    Step Name: Set Custom Attribute
    Step Execution: Always Execute
    IP Address: #{target.ipv4Addresses}
    Web Server: Yes

  6. On the Assigned Components page, choose Apply this workflow to the selected components, and check the two web servers in the service created prior. Click Next.

  7. Review your choices and click Finish.