Monday, March 7, 2011

CentOS / Redhat Linux: Install Keepalived To Provide IP Failover For Web Cluster

— SkyHi @ Monday, March 07, 2011
Keepalived provides a strong and robust health checking for LVS clusters. It implements a framework of health checking on multiple layers for server failover, and VRRPv2 stack to handle director failover. How do I install and configure Keepalived for reverse proxy server such as nginx or lighttpd?

If your are using a LVS director to loadbalance a server pool in a production environment, you may want to have a robust solution for healthcheck & failover. This will also work with reverse proxy server such as nginx.

Our Sample Setup

Internet--
         |
    =============
    | ISP Router|
    =============
         |
         |
         |      |eth0 -> 192.168.1.11 (connected to lan)
         |-lb0==|
         |      |eth1 -> 202.54.1.1 (vip master)
         |
         |      |eth0 -> 192.168.1.10 (connected to lan)
         |-lb1==|
                |eth1 -> 202.54.1.1 (vip backup)
Where,
  • lb0 - Linux box directly connected to the Internet via eth1. This is master load balancer.
  • lb1 - Linux box directly connected to the Internet via eth1. This is backup load balancer. This will become active if master networking failed.
  • 202.54.1.1 - This ip moves between lb0 and lb1 server. It is called virtual IP address and it is managed by keepalived.
  • eth0 is connected to LAN and all other backend software such as Apache, MySQL and so on.
You need to install the following softwares on both lb0 and lb1:
  • keepalived for IP failover.
  • iptables to filter traffic
  • nginx or lighttpd revers proxy server.
DNS settings should be as follows:
  1. nixcraft.in - Our sample domain name.
  2. lb0.nixcraft.in - 202.54.1.11 (real ip assigned to eth1)
  3. lb1.nixcraft.in - 202.54.1.12 (real ip assigned to eth1)
  4. www.nixcraft.in - 202.54.1.1 (VIP for web server) do not assign this IP to any interface.

Install Keepalived

Visit keepalived.org to grab latest source code. You can use the wget command to download the same (you need to install keepalived on both lb0 and lb1):
# cd /opt
# wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz
# tar -zxvf keepalived-1.1.19.tar.gz
# cd keepalived-1.1.19

Install Kernel Headers

You need to install the following packages:
  1. Kernel-headers - includes the C header files that specify the interface between the Linux kernel and userspace libraries and programs. The header files define structures and constants that are needed for building most standard programs and are also needed for rebuilding the glibc package.
  2. kernel-devel - this package provides kernel headers and makefiles sufficient to build modules against the kernel package.
Make sure kernel-headers and kernel-devel packages are installed. If not type the following install the same:
# yum -y install kernel-headers kernel-devel

Compile keepalived

Type the following command:
# ./configure --with-kernel-dir=/lib/modules/$(uname -r)/build
Sample outputs:
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
...
.....
..
config.status: creating keepalived/check/Makefile
config.status: creating keepalived/libipvs-2.6/Makefile

Keepalived configuration
------------------------
Keepalived version       : 1.1.19
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lpopt -lssl -lcrypto
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
Use VRRP Framework       : Yes
Use Debug flags          : No
Compile and install the same:
# make && make install

Create Required Softlinks

Type the following commands to create service and run it at RHEL / CentOS run level #3 :
# cd /etc/sysconfig
# ln -s /usr/local/etc/sysconfig/keepalived .
# cd /etc/rc3.d/
# ln -s /usr/local/etc/rc.d/init.d/keepalived S100keepalived
# cd /etc/init.d/
# ln -s /usr/local/etc/rc.d/init.d/keepalived .

Configuration

Your main configuration directory is located at /usr/local/etc/keepalived and configuration file name is keepalived.conf. First, make backup of existing configuration:
# cd /usr/local/etc/keepalived
# cp keepalived.conf keepalived.conf.bak

Edit keepalived.conf as follows on lb0:
vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 101
        authentication {
            auth_type PASS
            auth_pass Add-Your-Password-Here
        }
        virtual_ipaddress {
                202.54.1.1/29 dev eth1
        }
}
Edit keepalived.conf as follows on lb1 (note priority set to 100 i.e. backup load balancer):
vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 100
        authentication {
            auth_type PASS
            auth_pass Add-Your-Password-Here
        }
        virtual_ipaddress {
                202.54.1.1/29 dev eth1
        }
}
Save and close the file. Finally start keepalived on both lb0 and lb1 as follows:
# /etc/init.d/keepalived start

Verify: Keepalived Working Or Not

/var/log/messages will keep track of VIP:
# tail -f /var/log/messages
Sample outputs:
Feb 21 04:06:15 lb0 Keepalived_vrrp: Netlink reflector reports IP 202.54.1.1 added
Feb 21 04:06:20 lb0 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 202.54.1.1
Verify that VIP assigned to eth1:
# ip addr show eth1
Sample outputs:
3: eth1:  mtu 1500 qdisc pfifo_fast qlen 10000
    link/ether 00:30:48:30:30:a3 brd ff:ff:ff:ff:ff:ff
    inet 202.54.1.11/29 brd 202.54.1.254 scope global eth1
    inet 202.54.1.1/29 scope global secondary eth1

ping failover test

Open UNIX / Linux / OS X desktop terminal and type the following command to ping to VIP:
# ping 202.54.1.1
Login to lb0 and halt the server or take down networking:
# halt
Within seconds VIP should move from lb0 to lb1 and you should not see any drops in ping. On lb1 you should get the following in /var/log/messages:
Feb 21 04:10:07 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) forcing a new MASTER election
Feb 21 04:10:08 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Feb 21 04:10:09 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Feb 21 04:10:09 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Feb 21 04:10:09 lb1 Keepalived_healthcheckers: Netlink reflector reports IP 202.54.1.1 added
Feb 21 04:10:09 lb1 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for 202.54.1.1

Conclusion

Your server is now configured with IP failover. However, you need to install and configure the following software in order to configure webserver and security:
  1. nginx or lighttpd
  2. iptables
Stay tuned, for more information on above configuration.
This FAQ entry is 1 of 7 in the "CentOS / RHEL nginx Reverse Proxy Tutorial" series. Keep reading the rest of the series:

REFERENCES
http://www.cyberciti.biz/faq/rhel-centos-fedora-keepalived-lvs-cluster-configuration/

Attachments not showing up correctly

— SkyHi @ Monday, March 07, 2011
ERROR:

Now when I add attachments to new emails that I'm creating (using Word as email editor), the attachments show up as icons in the
body of the message. When I send these to my wife at her office (she is not using Outlook--some other non-Microsoft email program),
she does not see the attachment in the message body. But she does see one of those "winmail.dat" attachments (I'm guessing
"winmail.dat" is because of my AutoArchive is turned on) in the message header that she can not open.

If I reply to one of her messages, then when I attach files they attach normally in the message header and my wife can open
attachments that way.

This is something new. It used to be every email I wrote added attachments in the message header and not in the body of the
message.

Is this a setting that I've changed? How can I get Outlook/Word to add attachments to the message header and not place them in the
message body?



SOLUTION:
You've changed your email format to Rich Text. (Whether intentionally or
unintentionally). Change it back to either Plain Text or HTML.....

Tools-Options-Mail Format


 This article describes how either an Exchange Server administrator or end users can prevent the Winmail.dat attachment from being sent to Internet users when using the Microsoft Exchange Internet Mail Connector (IMC).

When an end user sends mail to the Internet from an Exchange Windows or Outlook client, a file attachment called Winmail.dat may be automatically added to the end of the message if the recipient's client cannot receive messages in Rich Text Format (RTF). The Winmail.dat file contains Exchange Server RTF information for the message, and may appear to the recipient as a binary file. It is not useful to non-Exchange Server recipients.

=======================================================================

How to Prevent Winmail.dat Attachments from Being Sent in OutlookDo recipients of your emails, seemingly out of the blue, complain about a mysterious attachment called "winmail.dat" (of the even more mysterious content type "application/ms-tnef"), which they cannot open, no matter what they try? Do files you attach disappear in that winmail.dat moloch? Does winmail.dat show up for some but not all recipients of your messages?

When, How and Why Winmail.dat-Application/MS-Tnef is Created

It's Outlook's fault, in a way. Or the recipient's email client's. If Outlook sends a message using the RTF format (which is not very common outside Outlook) for bold text and other text enhancements, it includes the formatting commands in the winmail.dat file. Receiving email clients that do not understand the code therein display it as a stale attachment. To make matters worse, Outlook may also pack other, regular file attachments in the winmail.dat file.
Fortunately, you can get rid of winmail.dat altogether by making sure Outlook does not even try to send mail using RTF.

Prevent Winmail.dat Attachments from Being Sent in Outlook

To prevent Outlook from attaching winmail.dat when you send an email:
  • Select Tools | Options... from the menu.
  • Go to the Mail Format tab.
  • Under Compose in this message format:, make sure either HTML or Plain Text is selected.
  • Click Internet Format.
  • Make sure either Convert to Plain Text format or Convert to HTML format is selected under When sending Outlook Rich Text messages to Internet recipients, use this format:
  • Click OK.
  • Click OK again.

Disabe Winmail.dat Stubbornly Going to Particular Recipients No Matter the Default

The standard settings for outgoing mail formats in Outlook can be overridden per email address. So, on a per case basis — when somebody complains about an inexplicable "Winmail.dat" attachment after you have made all the right settings changes —, you may have to reset the format for individual addresses:
  • Search for the desired contact in your Outlook Contacts.
  • Double-click the contact's email address.
    • Alternatively, click on the desired email address with the right mouse button and select Outlook Properties... from the menu.
  • Make sure either Let Outlook decide the best sending format or Send Plain Text only is selected under Internet format:.
  • Click OK.

Extract Files from Winmail.dat without Outlook

If you receive winmail.dat attachments with embedded files, you can extract them using a winmail.dat decoder on Windows or Mac OS X.


REFERENCES
http://www.office-outlook.com/outlook-forum/index.php/m/43551/
http://support.microsoft.com/kb/138053 
http://email.about.com/od/outlooktips/qt/Prevent_Winmail_dat_Attachments_from_Being_Sent_in_Outlook.htm

Saturday, March 5, 2011

the specified key name or identifier already exists

— SkyHi @ Saturday, March 05, 2011
ERROR:
  • a virtual machine or a template having the same name is already registered
  • the specified key name or identifier already exists
Solution:
HOME->Inventory->REMOVE the old VM or template from inventory

Friday, March 4, 2011

Ubuntu: Sending command line mail

— SkyHi @ Friday, March 04, 2011
user@Januty:~/BashTuts$ mail -s "user1" user1@gmail.com
The program 'mail' can be found in the following packages:
 * heirloom-mailx
 * mailutils
Try: sudo apt-get install

user@Januty:~/BashTuts$ sudo apt-get install mailutils
didn't configure postfix


Mar  4 15:26:22 Januty postfix/error[10911]: 8226929760: to=, relay=none, delay=2.1, delays=2/0.01/0/0.09, dsn=5.0.0, status=bounced (gmail.com)

ERROR:
fatal: open /etc/postfix/main.cf: No such file or directory

Solution:
user@Januty:~/BashTuts$ sudo dpkg-reconfigure postfix





Please select the mail server configuration type that best meets your needs.
            â
            â  No configuration:
            â   Should be chosen to leave the current configuration unchanged.
            â  Internet site:
            â   Mail is sent and received directly using SMTP.
            â  Internet with smarthost:
            â   Mail is received directly using SMTP or by running a utility such
            â   as fetchmail. Outgoing mail is sent using a smarthost.
            â  Satellite system:
            â   All mail is sent to another machine, called a 'smarthost', for delivery.
            â
            â          



=======================================================================
Ubuntu: Sending command line mail
I needed to send email from the command line, specifically for cron jobs, and there are many programs which can do this. I'm going to use the gnu mailutils package so first off let's install the mailutils package:
# apt-get install mailutils

This will add a few extra packages, then bring us up into an exim4 configuration screen. My systems are behind a dsl router, and I'm not going to route the mail through any relay host, I just want everything sent direct (for some sendmail agents this might cause problems, but you'll have to look at your logfiles). In the exim4 config screen I pick "internet site... mail is sent and receieved directly using SMTP". On edgy you might have to answer a few more questions, but I had to run a dpkg-reconfigure.

At this point we have exim4 listening on port 25 and I don't need that, so I need to stop the daemon and remove the startup links:
# /etc/init.d/exim4 stop
# update-rc.d -f exim4 remove


The update-rc.d command removes inits startup/shutdown links, but unfortunately if the exim4 packages get updated the links will be back so we need to run that command again.

Now lets try sending a test mail:
# echo testing | mail -s Bla myemail@somewhere.com

and take a look at /var/log/exim4/mainlog. You should be good to go!

REFERENCES
http://www.quietearth.us/articles/2006/09/25/Ubuntu-Sending-command-line-mail                      

How to Control a Mac From a Windows PC With TightVNC(RealVNC)

— SkyHi @ Friday, March 04, 2011
VNC, short for "Virtual Network Computing," is a graphical way of remotely controlling another computer. When you're connected to another computer with VNC, you see that computer's desktop as if you were right in front of it. You control that computer's mouse with your mouse, keyboard with your keyboard, and see exactly what's on the other computer's display on your monitor.

Because VNC is cross-platform, meaning it can be used on Windows, Mac and Linux computers, you can control a Windows PC from a Mac, Linux PC from a Windows PC and all other variations you can think of.

The controlled computer is called the Server and the controlling computer is called the Client.

Here is how it works.

Instruction 

How to Set Up the Server

1.Click on the blue Apple logo on the top left of your screen and select "System Preferences."

2.Select "Sharing" in the Internet & Network section, the third down from the top.

3.Click on the check box next to "Apple Remote Desktop" to activate it. In Mac OSX Leopard, this will be "Remote Mangement."

4.Click the "Access Privileges" button to the right of the "Services" box. In Mac OS X Leopard, click on the "Computer Settings" button.

5.Check "VNC viewers may control screen with password" and enter a secure password. Strong, secure passwords are a combination of numbers and letters with the occasional symbol thrown in. Remember your password.

6.Type in your Mac password in the "Authentication" dialog box that pops up on your screen. This will allow System Preferences to set the password for VNC users.

7.Write down the IP address of the Server Mac, which is located under the "Services" box of the "Sharing" preferences window.

How to Set Up the Client and Control the Server

8.Download and install TightVNC. See Resources below to download.

9.Uncheck "TightVNC Server" and "Web pages and documentation" on the "Select Components" part of the TightVNC install. Leave "TightVNC Viewer" checked.
Run TightVNC after installation is complete.

10.Enter the Mac Server's IP Address and hit "OK"

Enter the Mac Server's password that you set up in Section 1. A window should pop up with the Mac desktop.

 

REFERENCES: 

http://www.ehow.com/how_2193968_mac-windows-pc-using-tightvnc.html 

Mac Screen sharing with Windows: Server did not offer supported security type

— SkyHi @ Friday, March 04, 2011
Mac screen sharing from a windows machine using tightvnc(realVNC).
Mac to Mac, go->vnc://ip

ERROR:
I'm getting the error
"Server did not offer supported security type"

SOLUTION:
in System Preferences, Sharing, Screen Sharing, Computer Settings: you have "VNC viewers may control screen with password:" checked. And a password filled in.

realvnc setting:
[Options]
UseLocalCursor=0
UseDesktopResize=1
FullScreen=1
FullColour=1
LowColourLevel=1
PreferredEncoding=ZRLE
AutoSelect=1
Shared=1
SendPtrEvents=1
SendKeyEvents=1
SendCutText=1
AcceptCutText=1
DisableWinKeys=1
Emulate3=0
PointerEventInterval=0
Monitor=
MenuKey=F8
AutoReconnect=1


REFERENCES

http://apple.stackexchange.com/questions/6362/connect-to-vnc-from-windows
http://www.ehow.com/how_2193968_mac-windows-pc-using-tightvnc.html
http://forums.macrumors.com/archive/index.php/t-380251.html
http://shebangme.blogspot.com/2010/11/mac-remote-control-options-screen.html

Thursday, March 3, 2011

Password protect GNU screen sessions

— SkyHi @ Thursday, March 03, 2011
Or, How do i get a crypted password for .screenrc ?
Here is a quick tip, hopefully it helps someone, I struggled with this for some time…
I have been using GNU screen program since a long time. This program is like a window manager for terminals and is especially useful for ISP and home shell accounts. You can have multiple shells running under the same session and can easily detach the sessions and reattach them from a different computer later etc.
I usually password protect my sessions by using the password command (ctrl A :password). But I had a hard time figuring out how to set that password in .screenrc file. The file obviously does not store it in plaintext and uses a crypted version of password. To get the crypted password, simply set your password in the screen session (ctrl A :password and then enter the password twice), then the crypted version gets automatically saved to screen’s copy buffer! All you need to do is have a line in your .screenrc which looks like this
password DTWxS2voQWkgI
After this all your new screen sessions will be automatically password protected (meaning you will need the password to reattach a session.)


REFERENCES
http://amit.chakradeo.net/2009/02/04/password-protect-gnu-screen-sessions/