3/11/09

bonding two NICs, on CentOS

vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.1.20
NETWORK=192.168.1.0
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes


vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none


vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

vi /etc/modprobe.conf
alias bond0 bonding
options bond0 mode=balance-alb miimon=100


modprobe bonding

service network restart

less /proc/net/bonding/bond0

vmware kernel for kernel clock issue, and preformance

#Issue is basically... " In 2.4 kernels the system timer was normally clocked at 100 Hz, while in 2.6 the default system timer is set to 1000 Hz (some other distros are not following these "rules", and USER_HZ is still 100). 1000 Hz is definitely a good thing for desktop computers requiring fast interactive responses, but there are environments where this causes bad side effects."
#This caused the time to drift on the guest, which would mean problems with files and timestamps. This will fix that, as well as preformance gains.


#Get the kernel repo

cd /etc/yum.repos.d/
sudo wget http://vmware.xaox.net/centos/5.2/VMware.repo

#Install yum-protect and yum-priorties
sudo yum install yum-protect-packages
sudo yum install yum-priorities

#Set up the priorties, you want the Vmware.repo to be 1 higher then all the others. an example:

name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=2


#Then setup the VMware.repo to look similar to this: and enable protect so that it won't touch these packages from any other repos
[vmware]
name=VMware - Centos $releasever - $basearch
baseurl=http://vmware.xaox.net/centos/$releasever/$basearch/
gpgcheck=1
gpgkey=http://vmware.xaox.net/centos/$releasever/RPM-GPG-KEY
priority=1
protect=1

#wget the kernel packages.
wget http://vmware.xaox.net/centos/5.2/x86_64/kernel-2.6.18-92.1.10.el5.centos.plus.VMware.x86_64.rpm
wget http://vmware.xaox.net/centos/5.2/x86_64/kernel-devel-2.6.18-92.1.10.el5.centos.plus.VMware.x86_64.rpm
wget http://vmware.xaox.net/centos/5.2/x86_64/kernel-headers-2.6.18-92.1.10.el5.centos.plus.VMware.x86_64.rpm

#install the kernel, devel, and header packages
sudo rpm -ivh kernel-2.6.18-92.1.10.el5.centos.plus.VMware.x86_64.rpm kernel-devel-2.6.18-92.1.10.el5.centos.plus.VMware.x86_64.rpm kernel-headers-2.6.18-92.1.10.el5.centos.plus.VMware.x86_64.rpm

reboot, and your done :-)

Setting up keepalived for use with haproxy

This is for a 2 box load balancer:

keepalived:

download install keepalived:
wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
tar -zxvf keepalived-1.1.15.tar.gz && cd keepalived-1.1.15.tar.gz && ./configure --prefix=/usr --sysconfdir=/etc && make && sudo make install

sudo vi /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind=1 <--- have to do this to enable it to bind to a non local ip
sudo sysctl -p



lb1:
vi /etc/keepalived/keepalived.conf

vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101 # 101 on master, 100 on backup
virtual_ipaddress {
192.168.0.99
}
track_script {
chk_haproxy
}
}




lb2:
vi /etc/keepalived/keepalived.conf
vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}

vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 100 # 101 on master, 100 on backup
virtual_ipaddress {
192.168.0.99
}
track_script {
chk_haproxy
}
}

I found some of the configs off a HOWTO forge and tweaked a little to suit my configurations, thank you to whomever.

Bundeling an existing linux server into a new AMI

Requirements:
- A running server to bundle
- Ec2 ami/api tools installed
- Amazon ec2 account

First you need to setup the amazon ec2 tools, follow the directions here:

http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/setting-up-your-tools.html


Some notes that I have for my local setup that may be useful:

sudo yum install ruby


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

go to http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=88 for the API tools
go to http://java.sun.com/j2se/1.4.2/download.html to download and install the jre enviroment


---- tools ----
export EC2_HOME=/home/kylec/ec2-api-tools-1.3-26369
export EC2_AMITOOL_HOME=/home/kylec/ec2-ami-tools-1.3-26357

---- keys -----
export EC2_PRIVATE_KEY=~/.ec2/pk-$keynumber.pem #set $keynumber
export EC2_CERT=~/.ec2/cert-$keynumber.pem #set $keynumber

---- example .bash_profile -----
PATH=$PATH:$HOME/bin:/usr/bin/:/home/kylec/ec2-api-tools-1.3-26369/bin/:/usr/sbin:/usr/local/sbin

export PATH
unset USERNAME

export EC2_AMITOOL_HOME=/home/kylec/ec2-ami-tools-1.3-26357
export EC2_HOME=/home/kylec/ec2-api-tools-1.3-26369
export EC2_PRIVATE_KEY=~/.ec2/pk-*************.pem
export EC2_CERT=~/.ec2/cert-**************.pem
export JAVA_HOME=/usr
-------------------------------

----------------------------
There are a few things you want to do before you bundle your image, get it to how you want it as far as applications installed, updates applied, configurations set etc... After all the things kept on / are non-persistant after reboots.


#Once everything is setup for the tools, you can bundle the running physical machine with the following.

./ec2-bundle-vol -p amazonami1 -d /ami -c ~/.ec2/cert-*****.pem -k ~/.ec2/pk-******.pem -u 123456789 -s 10240 --no-inherit --generate-fstab -e /ami --kernel aki-9800e5f1 --ramdisk ari-a23adfcb

This will create a new image named "amazonami1", and will put it in /xen, at the max size of 10240, and will not inherit its meta data from the instance (duh), and will generate an ec2 fstab file... (note the exclude -e /ami)

Also a good idea is to specify the kernel you want to start the AMI with, as it will default to the oldest one. aki-9800e5f1 = 2.6.18-xenU-ec2-v1.0

So this should take a little while, it will mount a loop0 interface and write/compress and encrypt your instance into the specified /ami folder.

Now the next part is easy, all that is left is to upload your newly bundled image.

ec2-upload-bundle -b bucketname -m /ami/imageprefixname.manifest.xml -a ************ -s ********************

Pretty straight forward, just need to specify the bucket to upload to, and the path to the ami manifest.xml file. Just sit back and let it upload.

Once its compete all thats left is to register the AMI,

ec2-register /bucket/aminame.manifest.xml

Then, just login to the console and start your new AMI,

https://console.aws.amazon.com/

doing a yum update broke backuppc "backup failed (can't find Compress::Zlib)"

Centos's yum perl package doesn't include XS support, causing the error in backuppc "backup failed (can't find Compress::Zlib)"

Issue was with, /usr/lib/perl5/site_perl/5.8.8/Compress/Zlib.pm
use Scalar::Util qw(dualvar);

Test with:

[root@]# perl -W
use Scalar::Util qw(dualvar);
Use of uninitialized value in concatenation (.) or string at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/Scalar/Util.pm line 30.
is only avaliable with the XS version at - line 1
BEGIN failed--compilation aborted at - line 1.

To Fix:

cpan: install xs
cpan: force install Scalar::Util

rerun

[root@wailord log]# perl -W
use Scalar::Util qw(dualvar);

and you should see no error messages. Rerun an update on a host in backuppc and it should succeed.

......

ADDED NOTES! --

The next day, for some reason the backups where corrupt, it seems that the zlib package that I downgraded to caused some issues as well!

These were the packages that were updated that seemed to break something:
Mar 10 09:55:34 Updated: perl - 4:5.8.8-15.el5_2.1.x86_64
Mar 10 09:55:37 Updated: perl-Compress-Raw-Zlib - 2.015-1.el5.rf.x86_64
Mar 10 09:55:38 Updated: perl-DBI - 1.607-1.el5.rf.x86_64
Mar 10 09:55:39 Updated: perl-IO-Compress-Base - 2.015-1.el5.rf.noarch
Mar 10 09:55:45 Updated: perl-IO-Compress-Zlib - 2.015-1.el5.rf.noarch

And I downgraded zlib thinking that could fix it to:

Mar 11 11:35:52 Installed: perl-Compress-Zlib - 1.42-1.fc6.x86_64

Ended up upgrading back to the following:

Mar 12 10:42:29 Installed: perl-Compress-Raw-Zlib - 2.015-1.el5.rf.x86_64
Mar 12 10:42:29 Installed: perl-IO-Compress-Base - 2.015-1.el5.rf.noarch
Mar 12 10:42:29 Installed: perl-DBD-mysql - 4.010-1.el5.rf.x86_64
Mar 12 10:42:29 Installed: perl-IO-Compress-Zlib - 2.015-1.el5.rf.noarch
Mar 12 10:42:29 Updated: perl-Compress-Zlib - 2.015-1.el5.rf.noarch

This fixed the corrupt backups issue.