HAProxy Load balancer on Virtual IP

This would be the micro post!

Requirement:

I have configured 2 HAProxy load balancer which sends request to 3 different backends. But I wanted to make both HAProxy load balancer to be Highly Available. So I was looking for solution approach to assign Virtual IP address which keeps floating between two HAProxy nodes based on their availability. So I found "ucarp" package. Quite simple and 4 lines configuration makes your thing work.

So I did below mentioned changes in /etc/ucarp/vip-001.conf file of ucarp.

VIP_ADDRESS="192.168.133.250"
PASSWORD="simple_password"
BIND_INTERFACE="eth0"
OPTIONS="--shutdown --preempt"
SOURCE_ADDRESS="192.168.133.130"

Here, 
VIP_ADDRESS is the IP address which you want to assign as Virtual IP. 
PASSWORD parameters needs to be same in both HAProxy load balancer to make sure that both ucarp are sharing same information.
BIND_INTERFACE is the network interface you have in your server
SOURCE_ADDRESS is the Local Static/Dynamic IP addres associated with machine. You need to set this address according to the server's IP address.

Once you make above mentioned you can save and make "ucarp" service running by giving below command.

service ucarp start

And make it running at startup by below command.

chkconfig ucarp on

Using Gmail ID for sending Emails in Centos

Long story in short. 

Follow below steps.

1. Install "ssmtp" package in Centos.

yum install ssmtp

2. Now open /etc/ssmtp/ssmtp.conf file and change below mentioned details.

mailhub=smtp.gmail.com:587
Hostname=host@example.com #not sure if this really matters
FromLineOverride=YES
UseSTARTTLS=YES
AuthUser=test@gmail.com
AuthPass=Th!sP@ssword!
TLS_CA_File=/etc/pki/tls/certs/ca-bundle.crt

3. Now open "/etc/ssmtp/revaliases" file and add below line.

root:test@gmail.com:smtp.gmail.com:587

4. Now run alternatives command and select sendmail.ssmtp as a default mta

alternatives --config mta

5. Now you can test mail using mutt.

Disable Email notification in Magento Test Environment

After a long time I got something to post in this blog. Today I was setting up test magento instance and I took replica of the production system and installed and configured in my local VirtualMachine. My intention was to do some load testing and some RnD on test magento instance. But as I have Production data in my test machine, I thought to disable all email notification, so that in any case no email should be fired from my test machine.

So below steps I followed to stop mail functionality in magento.

1. You need to login into magento admin panel. In the admin panel go to "System" => "Configuration" => "System" and then in "Disable Email Communications" select "Yes". Then click on "Save Config" button on upper right side in Admin panel to save changes.


2. I had configured AWS SES for Email notification so I used another module called "SMTP Pro". So again go to "System" => "Configuration" => "SMTP Pro". Now in "Email Connection" select "Disabled" and save config.

3. Third option, I thought to turn off from the Server it self. To be at safer side, its good to disable local smtp. I used below command to turn off SMTP in my server.

/etc/init.d/postfix stop
chkconfig postfix off

I don't think anything else we can do to turn off Email Notification.

Using Webinject with Nagios to check site's availability and responsetime

There are couple of plugins available to check website response time and availability but lets check how webinject checks can be helpful.

Installing Webinject
1. Download webinject source and extract it in your Nagios plugins directory.
http://www.webinject.org/download.html

2. After you extract, you may need to install perl modules. I had to install below mentioned modules. I used "cpan" command to install modules. You may need to install additional modules according to your server setup.

cpan
> install Crypt::SSLeay

Note: You can identify which modules needs to be install by running below command.
[root@ip-10-126-117-63 webinject]# ./webinject.pl -c testcases.xml
Can't locate Crypt/SSLeay.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./webinject.pl line 27.
BEGIN failed--compilation aborted at ./webinject.pl line 27.

Look at text marked in bold. This shows missing perl modules. So you can simply run below cpan command.

[root@ip-10-126-117-63 webinject]#cpan
cpan[1]> install Crypt::SSLeay

3. Now you can check if webinject script will work or not using below command. Once you are done with verification, you can start creating webinject script.

[root@ip-10-126-117-63 webinject]# ./webinject.pl -c testcases.xml

You should not see any perl modules errors in above command's output. If everything goes fine, you will see result of testcase execution.

Creating Webinject Test script

In this example we will create script to check availability of www.sysadminhub.in and we will check if "System Administrator's Hub" text is available or not. If that text is not present then we can send generate error.

<testcases repeat="1">
<case
id="1"
description1="Check if www.sysadminhub.in is available"
description2="This will check response code. If it is not 200 then it will show error"
method="get"
url="http://www.sysadminhub.in"
verifyresponsecode="200"
/>
<case
id="2"
description1="In this case we will check for text 'System Administrator's Hub'"
description2="If that text is missing in page then it will generate error"
method="get"
url="http://www.sysadminhub.in"
verifypositive="System Administrator's Hub"
/>
</testcases>
In above script we have used "get" method and verifyresponsecode & verifypositive are to check response code of site and check text from site respectively.

How to use with Nagios

Here apart from testcase we will have to create config file for each testcase. You can specify different globaltimeout option for different testcase. I have set below content for my script.
<testcasefile>testcase.xml</testcasefile>
<useragent>WebInject Application Tester</useragent>
<timeout>10</timeout>
<globaltimeout>20</globaltimeout>
<reporttype>nagios</reporttype>
Here "reporttype" is the important factor. This will produce output which Nagios can use to parse performance data. So after creating your testcase and config xml, you can use below mentioned command.

[root@ip-10-126-117-63 webinject]# ./webinject.pl -c config.xml testcases.xml WebInject OK - All tests passed successfully in 3.237 seconds |time=3.237;;;0

Using Amazon EC2 command line interface

You can easily manage your Amazon AWS resource like Amazon EC2 instances, EBS volumes & VPC, etc.. through command line tools.

Before you start using these tools, it needs dependency softwares to run.

In this example, I am going to show you AWS command line tool configuration on Linux.

Prerequisites:
This tools requires Java 1.6 or later. Also we need to make sure that JAVA_HOME is set. You can refer this link to install/configure JAVA on linux.

Download and Install AWS command line tools.

1. Download AWS tools using below URL.

wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip

2. Extract it at some location. For example, I will extract these tools at /home/ec2 directory.

3. Once you extract zip file at /home/ec2 folder, you need to set EC2_HOME variable now. You can set this variable in bashrc or in /etc/profile file.

export EC2_HOME=/home/ec2
export PATH=$PATH:$EC2_HOME/bin

4. Now you should be able to use tools. But its good to configure access_key and secret_key before we use these tools. As these tools requires them to authenticate. So you can include them in bashrc or /etc/profile.

export AWS_ACCESS_KEY=your-aws-access-key-id
export AWS_SECRET_KEY=your-aws-secret-key

5. Once you are done with all above command, you can check "ec2-describe-regions". This command will show you one or more region which are available to you.

Note: You need to have proper privileges associated with Access key to perform action on resources.

Enable JMX access in Alfresco to monitor JVM memory usage through VisualVM or Jconsle

One small post but useful for those who wants to monitor Alfresco's JVM memory usage through VisualVM.

To enable connection through JMX, first you need to enable it in setenv.sh file. Simply add below line and restart Alfresco. You should be able to connect to JMX.

Linux:
export JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote -Djava.net.preferIPv4Stack=true"

Winodws:
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote -Djava.net.preferIPv4Stack=true

In VisulVM, you can connect using below string. Please select "Add JMX connection".