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
- Embotics® vCommander 5.7.9 or later
- vCommander REST API PowerShell libraries
- vCommander PowerShell client 2.7
- PowerShell v4 installed on the vCommander application server
- vCommander script
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:
- Under the Configuration menu, click Custom Attributes.
- Click Add.
- 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 - 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:
- Click Add.
- 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 - 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.
- Click Add.
- 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 - Choose Free Form and click Finish.
Creating the Service Catalog Entry
Next, create the Service Catalog entry for the load-balanced service.
- Under the Configuration menu, choose Service Request Configuration.
- Switch to the Service Catalog tab, and click Add Service.
- Add a meaningful Name and Description and select an appropriate Icon and categories. Click Next.
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.
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.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.
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.
- Under the Configuration menu, choose Service Request Configuration.
- Switch to the Completion Workflow tab. Click Add.
- Provide a Name and choose to Apply this workflow after a VM is deployed. Click Next.
- 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 - 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} - 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}
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: EnabledClick 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
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 infoOn the Assigned Components page select the load balancer component then click Next.
Review your choices on the Summary page and click Finish.
Next, create the completion workflow for the web servers.
- Under the Configuration menu, choose Service Request Configuration.
- Switch to the Completion Workflow tab. Click Add.
- Provide a Name and choose to Apply this workflow after a VM is deployed. Click Next.
- 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 - 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 - 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.
- Review your choices and click Finish.