Saturday, September 4, 2010

XEN operations

XEN List command
----------

xm list


to check if Xen has started. It should list Domain-0 (dom0):

[root@server1 ~]# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 350 1 r----- 94.4
[root@server1 ~]#
---------

Creating A Virtual Machine
--------------

CentOS comes with a nice tool called virt-install with which we can create virtual machines for Xen. To start it, we simply run

virt-install


The tools asks a few questions before it creates a virtual machine. I want to call my first virtual machine vm01, with 256MB RAM and a disk size of 4GB. I want to store it in the file /vm/vm01.img:

What is the name of your virtual machine? <-- vm01
How much RAM should be allocated (in megabytes)? <-- 256
What would you like to use as the disk (path)? <-- /vm/vm01.img
How large would you like the disk (/vm/vm01.img) to be (in gigabytes)? <-- 4
Would you like to enable graphics support? (yes or no) <-- no
What is the install location? <-- http://wftp.tu-chemnitz.de/pub/linux/centos/5.0/os/i386

The question about the graphics support refers to the installer, not the virtual machine itself! It is possible to start a graphical installer, but you'd have to connect to it via VNC. It's easier to use the text installer - it offers the same options, so I choose the text installer.

As install location, you should specify a mirror close to you where the installer can download all files needed for the installation of CentOS 5.0 in our virtual machine. You can find a list of CentOS mirrors here: http://www.centos.org/modules/tinycontent/index.php?id=13

After we have answered all questions, virt-install starts the normal CentOS 5.0 installer (in text mode) in our vm01 virtual machine. You already know the CentOS installer, so it should be no problem for you to finish the CentOS installation in vm01.

After the installation, we stay at the vm01 console. To leave it, type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY. You will then be back at the dom0 console.

virt-install has created the vm01 configuration file /etc/xen/vm01 for us (in dom0). It should look like this:

====================================================
cat /etc/xen/vm01

# Automatically generated xen config file
name = "vm01"
memory = "256"
disk = [ 'tap:aio:/vm/vm01.img,xvda,w', ]
vif = [ 'mac=00:16:3e:13:e4:81, bridge=xenbr0', ]

uuid = "5aafecf1-dd66-401d-69cc-151c1cb8ac9e"
bootloader="/usr/bin/pygrub"
vcpus=1
on_reboot = 'restart'
on_crash = 'restart'
====================================================

Run
-----------

xm console vm01

to log in on that virtual machine again (type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY to go back to dom0), or use an SSH client to connect to it.

To get a list of running virtual machines, type
---------------

xm list

The output should look like this:

[root@server1 xen]# xm list
Name ID Mem(MiB) VCPUs State Time(s)
Domain-0 0 259 1 r----- 1906.6
vm01 3 255 1 ------ 137.9
[root@server1 xen]#

To shut down vm01, do this:
--------------

xm shutdown vm01

To start vm01 again, run
---------------

xm create /etc/xen/vm01

If you want vm01 to start automatically at the next boot of the system, then do this:
------------------

ln -s /etc/xen/vm01 /etc/xen/auto

Here are the most important Xen commands:

xm create -c /path/to/config - Start a virtual machine.
xm shutdown - Stop a virtual machine.
xm destroy - Stop a virtual machine immediately without shutting it down. It's as if you switch off the power button.
xm list - List all running systems.
xm console - Log in on a virtual machine.
xm help - List of all commands.

Installing Xen On CentOS 5.2 (i386)

Xen lets you create guest operating systems (*nix operating systems like Linux and FreeBSD), so called "virtual machines" or domUs, under a host operating system (dom0). Using Xen you can separate your applications into different virtual machines that are totally independent from each other (e.g. a virtual machine for a mail server, a virtual machine for a high-traffic web site, another virtual machine that serves your customers' web sites, a virtual machine for DNS, etc.), but still use the same hardware. This saves money, and what is even more important, it's more secure. If the virtual machine of your DNS server gets hacked, it has no effect on your other virtual machines. Plus, you can move virtual machines from one Xen server to the next one.


If you want to save your virtual machines in /vm, too, but haven't created a partition for it of if the directory /vm doesn't exist on your system, you can create it like this:

----------------------------
mkdir /vm
----------------------------

Make sure that SELinux is disabled or permissive:

---------------------------
vi /etc/sysconfig/selinux
---------------------------

If you had to modify /etc/sysconfig/selinux, please reboot the system:
--------------------------
reboot
--------------------------

Installing Xen

To install Xen, we simply run

--------------------------
yum install kernel-xen xen
--------------------------

This installs Xen and a Xen kernel on our CentOS system.

Before we can boot the system with the Xen kernel, please check your GRUB bootloader configuration. We open /boot/grub/menu.lst:

----------------------
vi /boot/grub/menu.lst
----------------------

The first listed kernel should be the Xen kernel that you've just installed:

=============================================
[...]
title CentOS (2.6.18-92.1.13.el5xen)
root (hd0,0)
kernel /xen.gz-2.6.18-92.1.13.el5
module /vmlinuz-2.6.18-92.1.13.el5xen ro root=/dev/VolGroup00/LogVol00
module /initrd-2.6.18-92.1.13.el5xen.img
[...]
===============================================

Change the value of default to 0 (so that the first kernel (the Xen kernel) will be booted by default):

=================================
[...]
default=0
[...]
=================================

The complete /boot/grub/menu.lst should look something like this:

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

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-92.1.13.el5xen)
root (hd0,0)
kernel /xen.gz-2.6.18-92.1.13.el5
module /vmlinuz-2.6.18-92.1.13.el5xen ro root=/dev/VolGroup00/LogVol00
module /initrd-2.6.18-92.1.13.el5xen.img
title CentOS (2.6.18-92.1.1.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-92.1.1.el5 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-92.1.1.el5.img
title CentOS (2.6.18-92.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-92.el5.img
====================================

Afterwards, we reboot the system:

-----
reboot
--------

The system should now automatically boot the new Xen kernel. After the system has booted, we can check that by running

--------
uname -r
-------

Friday, September 3, 2010

Mod_GeoIP installation

Mod_GeoIP installation is easy. But in a cPanel server you need to follow some procedure for installing it.

Your cPanel server must have apache version 2.2.x installed.

Now proceed with the following steps to install it.

1) Download and install GeoIP database
# cd /usr/local/src/
# wget -c http://geolite.maxmind.com/download/geoip/api/c/GeoIP-1.4.6.tar.gz
# tar -xzf GeoIP-1.4.6.tar.gz
# cd GeoIP-1.4.6/
# ./configure
# make
# make install

2) Give apache user to read permission to that datbase file

# chown nobody.nobody /usr/local/share/GeoIP/GeoIP.dat
# echo '/usr/local/lib ' > /etc/ld.so.conf.d/geio.conf
# ldconfig

3) Download and install mod_geoip

# cd /usr/local/src/
# wget -c http://geolite.maxmind.com/download/geoip/api/mod_geoip2/mod_geoip2_1.2.5.tar.gz
# tar -xzf mod_geoip2_1.2.5.tar.gz
# cd mod_geoip2_1.2.5/
# /usr/local/apache/bin/apxs -lGeoIP -cia mod_geoip.c

4) Create a file called /usr/local/apache/conf/geoip.conf and add the following content

# cat >> /usr/local/apache/conf/geoip.conf << EOF
LoadModule geoip_module modules/mod_geoip.so

GeoIPEnable On
GeoIPDBFile /usr/local/share/GeoIP/GeoIP.dat MemoryCache

EOF

5) Add this file to apache included custom file list
echo 'Include "/usr/local/apache/conf/geoip.conf" ' >> /usr/local/apache/conf/includes/pre_main_global.conf

6) Rebuild httpd.conf and restart apache.

# /scripts/rebuildhttpdconf
# /scripts/restartsrv httpd

HyperVM XEN

HyperVM installation consists of downloading either the hypervm-install-master.sh or hypervm-install-slave.sh from download.lxlabs.com and executing them as root. They will download all the required files and do the complete installation on their own. You will need to disable selinux. edit /etc/sysconfig/selinux and then run setenforce 0.

Before you start to install there are several things need to be prepared:

* Make sure that you open the ports 8888 and 8887 in the firewall.
* The boot loader must be GRUB.
* There must be a separate /boot partition. You can assign it 200MB.
* You should use LVM.The recommended disk configuration is:/boot /dev/hda1 (500MB)
/ /dev/mapper/vol00-root (8GB)
swap /dev/mapper/vol00-swap (1GB)

Installation commands to execute:

1. setenforce 0
2. wget http://download.lxlabs.com/download/hypervm/production/hypervm-install-master.sh
3. sh ./hypervm-install-master.sh –virtualization-type=xen

After installation finished, you need to modify your /etc/grub.conf file so Linux will boot with xen kernel, most of the time you’ll need to change the ‘default=1? to ‘default=0?, and reboot the machine. Remember that the ordering on Linux is always started with 0 and the kernel you have to boot will always contain ‘xen’ in its naming.

Once the machine boots back, just make sure you have the Xen kernel by doing a ‘uname -a’, and after that you can connect to ‘http://machine-name:8888?, and you will be presented with a login screen – the password would be ‘admin’. Once you login, HyperVM will explicitly force you to change the password to something other than ‘admin’.

Note: On fedora 6/centos 5, you will need to run the following commands for xen to work properly:

Fedora:

cd /usr/local/lxlabs/hypervm/httpdocs/

lphp.exe ../bin/misc/fixfc6xen.php

Centos:

cd /usr/local/lxlabs/hypervm/httpdocs/

lphp.exe ../bin/misc/fixcentos5xen.php

Note 2: If you update the kernel at any point later, you will have to run the above commands again
Bookmark and Share
Related Article

* Xen VPS can’t initialize iptables table ‘filter’ (0)
* Xen VPS “4gb seg fix up” Problem (4)
* Installing suPHP on Centos 5 (0)
* Installing libTorrent and rTorrent on Linux Centos (17)
* Installing Gnome and VNC Remote Desktop on Centos VPS (15)

Monday, June 14, 2010

Easy apache error( perl issues)

ERROR
-------
can't locate Curses.pm in @INC (@INC contains: /scripts/../lib /var/cpanel/easy/apache/custom_opt_mods /usr/local/cpanel /var/cpanel/perl/easy /scripts /usr/local/lib/perl5/5.8.8/i686-linux /usr/local/lib/perl5/5.8.8 /usr/local/lib/perl5/site_perl/5.8.8/i686-linux /usr/local/lib/perl5/site_perl/5.8.8 /usr/local/lib/perl5/site_perl .) at /usr/local/lib/perl5/site_perl/5.8.8/Curses/UI/Common.pm line 20.
BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5.8.8/Curses/UI/Common.pm line 20.
Compilation failed in require at (eval 2507) line 3.
...propagated at /usr/local/lib/perl5/5.8.8/base.pm line 85.
BEGIN failed--compilation aborted at /usr/local/lib/perl5/site_perl/5.8.8/Curses/UI.pm line 2.
Compilation failed in require at /var/cpanel/perl/easy/Cpanel/Easy/Apache/UI/CLI/Config.pm line 5.
BEGIN failed--compilation aborted at /var/cpanel/perl/easy/Cpanel/Easy/Apache/UI/CLI/Config.pm line 5.
Compilation failed in require at /var/cpanel/perl/easy/Cpanel/Easy/Apache/UI/CLI.pm line 404.
r------------------------------

Solution
------
root@cp [/home]# /scripts/realperlinstaller --force Curses::UI
---------------

Thursday, May 6, 2010

How to create a VPS with Open VZ

OpenVZ uses a Operating System template system, ie every single VPS created with OpenVZ can have its own Operating System template like Fedora Core, Debian,CentOS.

You can download OpenVZ Operating System templates from OpenVZ template website. Note that each OS templates has its own hardware version . Make sure that you are choosing the right OS template for your server hardware.

Installing a template for CentOS:
[root@test ~]#yum -y vztmpl-centos-5-2.0-2 //install the template for Centos 5
[root@test ~]#vzpkgcache //create the cache, a lot of packages will be installed
[root@test ~]#vzpkgls //check the templates installed

Now we can go ahead and create out first VPS:

[root@test ~]#vzctl create 101 --ostemplate centos-5-i386-default --config vps.basic //This will create a VPS with the ID 101 using the Centos 5 template

Now a few things will have to set for the VPS like to be started at boot server time, set the IP, hostname, password and such.


[root@test ~]#vzctl set 101 --onboot yes --save

[root@test ~]#vzctl set 101 --ipadd 192.168.0.3 --save

[root@test ~]#vzctl set 101 --hostname server.server-hostname.com --save

[root@test ~]#vzctl set 101 --nameserver 192.168.0.2 --save


[root@test ~]#vzctl set 101 --userpasswd root:password //This last command will set the password for user root on the VPS






IMPORTANT VPS COMMANDS

How Do We Stop / Start / Restart VPS Servers?
# vzctl start 101 // 101 means the VPS ID
# vzctl restart 101
# vzctl stop 101
Login Into VPS Server
vzctl enter 101



How Do We Set Disk Quota?
# vzctl set 101 --diskspace SoftLimitG:HardLimitG --save
# vzctl set 101 --diskspace 10G:12G –save

How Do We Run a Command For VPS?

# vzctl exec 101 w
# vzctl exec 101 df

Destroy VPS
# vzctl destroy 101 // destroy the vps having ID 101

Wednesday, March 31, 2010

DNS forwarding

for a in `grep /etc/trueuserowners | cut -d ':' -f1`; do for b in `grep $a /etc/userdomains | cut -d":" -f1`; do replace "66.7.213.144" "66.7.219.239" -- /var/named/$b.db ; done ; done;