Thursday, May 30, 2013

Enable EPEL Repo on CentOS 6.3



wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm


sudo rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm

Monday, May 27, 2013

KVM virtualization in CentOS 6.4 part1


First disable selinux

Then give a hostname such as server1.sourav.com and an IP Address to an adapter

if this command shows some output then your processor is ready

egrep '(vmx|svm)' --color=always /proc/cpuinfo

 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*



 yum install kvm libvirt python-virtinst qemu-kvm

Then start the libvirt daemon 

 /etc/init.d/libvirtd start

it will not start unless hosts is properly configured 

like the entry 127.0.0.1   localhost 

and

10.10.*.*  server1.sourav.com  server1

should be there

To check if KVM has successfully been installed

virsh -c qemu:///system list


It should display something like this:

[root@server1 ~]# virsh -c qemu:///system list
 Id Name                 State

Now set up network bridge

yum install bridge-utils

 vi /etc/sysconfig/network-scripts/ifcfg-br0

 DEVICE="br0"
NM_CONTROLLED="yes"
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=none
IPADDR=192.168.0.100
PREFIX=24
GATEWAY=192.168.0.1
DNS1=8.8.8.8
DNS2=8.8.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System br0"

Modify /etc/sysconfig/network-scripts/ifcfg-eth0 as
follows (comment out BOOTPROTO, IPADDR, PREFIX, GATEWAY, DNS1, and DNS2 and add BRIDGE=br0):

DEVICE="eth0"
#BOOTPROTO=none
NM_CONTROLLED="yes"
ONBOOT=yes
TYPE="Ethernet"
UUID="73cb0b12-1f42-49b0-ad69-731e888276ff"
HWADDR=00:1E:90:F3:F0:02
#IPADDR=192.168.0.100
#PREFIX=24
#GATEWAY=192.168.0.1
#DNS1=8.8.8.8
#DNS2=8.8.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
BRIDGE=br0


Now

/etc/init.d/network restart

 yum install virt-manager libvirt qemu-system-x86 openssh-askpass


 We will create our image-based virtual machines in the directory /var/lib/libvirt/images/ which was created automatically when we installed KVM in chapter two.

To create a Debian Squeeze guest (in bridging mode) with the name vm10, 512MB of RAM, two virtual CPUs, and the disk image /var/lib/libvirt/images/vm10.img (with a size of 12GB), insert the Debian Squeeze Netinstall CD into the CD drive and run

virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /dev/cdrom --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm



 Of course, you can also create an ISO image of the Debian Squeeze Netinstall CD (please create it in the /var/lib/libvirt/images/ directory because later on I will show how to create virtual machines through virt-manager from your Fedora desktop, and virt-manager will look for ISO images in the /var/lib/libvirt/images/ directory)...

dd if=/dev/cdrom of=/var/lib/libvirt/images/debian-6.0.5-amd64-netinst.iso

dd if=/dev/cdrom of=/var/lib/libvirt/images/debian-6.0.5-amd64-netinst.iso

... and use the ISO image in the virt-install command:

virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/debian-6.0.5-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm

The output is as follows:

[root@server1 ~]# virt-install --connect qemu:///system -n vm10 -r 512 --vcpus=2 --disk path=/var/lib/libvirt/images/vm10.img,size=12 -c /var/lib/libvirt/images/debian-6.0.5-amd64-netinst.iso --vnc --noautoconsole --os-type linux --os-variant debiansqueeze --accelerate --network=bridge:br0 --hvm


Starting install...
Allocating 'vm10.img'              |  12 GB     00:00
Creating domain...                 |    0 B     00:00
Domain installation still in progress. You can reconnect to
the console to complete the installation process.

Now go to Applications-System Tools-Virtual Machine Manager

There you will see the virtual machine running

click open

the virtual machine will start in GUI

When you start virt-manager for the first time, you will most likely see the message Unable to open a connection to the libvirt management daemon. You can ignore this because we don't want to connect to the local libvirt daemon, but to the one on our CentOS 6.4 KVM host. Click on Close and go to File > Add Connection... to connect to our CentOS 6.4 KVM host: 







Wednesday, May 22, 2013

Configuring DNS/Bind Server on RedHat 6



nano /etc/hosts


192.168.0.101 www.sourav.com
192.168.0.101 www.test.com
192.168.0.101 redhatserver.sourav.com
192.168.0.101 redhatserver.test.com
nano /etc/resolv.conf

search sourav.com

nano /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE="eth0"
HWADDR="00:0C:29:46:0C:5A"
NM_CONTROLLED="no"
BOOTPROTO="STATIC"
ONBOOT="yes"
IPADDR=192.168.0.101
NETMASK=255.255.255.0
BROADCAST=192.168.0.255
NETWORK=192.168.0.0
GATEWAY=192.168.0.201
DNS1=192.168.0.101
DOMAIN=sourav.com

emacs /etc/named.conf


options {
# make it comment ( listen all interfaces on the server )
#listen-on port 53 { 127.0.0.1; };
#change ( if not use IPv6 )
listen-on-v6 { none; };
directory "/var/named";
forwarders { 8.8.8.8;4.2.2.2; };
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
# query range ( set internal server and so on )
allow-query {
localhost;
192.168.0.0/24;
};
# transfer range ( set it if you have secondary DNS )
#allow-transfer { localhost; 192.168.0.0/24; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

# change all from here

view "internal" {
        match-clients {
                localhost;
                192.168.0.0/24;
        };
        zone "." IN {
                type hint;
                file "named.ca";
        };
        zone "sourav.com" IN {
                type master;
                file "sourav.com.fwd";
                allow-update { none; };
        };
        zone "0.0.10.in-addr.arpa" IN {
                type master;
                file "0.168.192.rev";
                allow-update { none; };
        };
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
};




nano /var/named/sourav.com.fwd



$TTL 86400
@   IN  SOA     redhatserver.sourav.com. root.sourav.com. (
        2013051001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)



    IN         NS        redhatserver.sourav.com.


    IN         A         192.168.0.101



    IN       MX    10      redhatserver.sourav.com.



redhatserver       IN      A          192.168.0.101


emacs /var/named/0.168.192.rev


$TTL 86400
@   IN  SOA     redhatserver.sourav.com. root.sourav.com. (
        2013051001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)



     IN      NS        redhatserver.sourav.com.



     IN      PTR       sourav.com.
     IN       A       255.255.255.0



    101        IN      PTR       redhatserver.sourav.com.




/etc/rc.d/init.d/named restart

Apache Server Configuration with Name Based Hosting in RedHat Linux 6

My Configuration,

Operating System  :  redhat 6.3 32bit server
Hostname          :  redhatserver.sourav.com
IP Address        :  192.168.0.101
Client Details:

Operating System  :  redhat 6.3 32bit Desktop
Hostname          :  client.sourav.com
IP Address        :  192.168.0.10


Prerequisites:

1. Set the hostname of redhatserver server

[root@redhatserver ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=redhatserver.sourav.com
2. Add the redhatserverserver hostname in ‘etc/hosts’ file

[root@redhatserver ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.250   redhatserver.sourav.com
192.168.1.250   www.sourav.com
3. Install Apache

Check and remove any previously installed packages
[root@redhatserver ~]# rpm -qa | grep httpd
or
[root@redhatserver ~]# yum list installed | grep httpd
Now install the ‘httpd’ package
[root@redhatserver ~]# yum install httpd* -y
4. Configure Apache

[root@redhatserver ~]# vi /etc/httpd/conf/httpd.conf
## line no 262 - Set the server admin mail id which is used to receive mail generated by apache ##
ServerAdmin root@sourav.com
## line no 276 - Set the redhatserversite name ##
ServerName www.sourav.com:80
## line no 292 - Set the redhatserver pages folder ##
DocumentRoot "/var/www/html"
## line no 402 - Sent the index or home page of the redhatserversite ##
DirectoryIndex sourav.html
5. Create a sample index or home page

Create the index or home page html file in the ‘/var/www/html/’ directory
[root@redhatserver ~]# vi /var/www/html/sourav.html


 Welcome to sourav redhatserversite 

6. Allow redhatserverserver through firewall

[root@redhatserver ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
Restart iptables to save changes
[root@redhatserver ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]
7. Start Apache redhatserver server

[root@redhatserver ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@redhatserver ~]# chkconfig httpd on
Client side Configuration

1. Add the redhatserverserver and client ip address and hostname in the ‘/etc/hosts’ file

[root@client ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.251   client.sourav.com
192.168.1.250   www.sourav.com
 for name based hosting

VirtualHost *:80
    # This first-listed virtual host is also the default for *:80
    ServerName www.example.com
    ServerAlias example.com
    DocumentRoot /www/domain
/VirtualHost

VirtualHost *:80
    ServerName other.example.com
    DocumentRoot /www/otherdomain
/VirtualHost

You can alternatively specify an explicit IP address in place of the * in VirtualHost directives. For example, you might want to do this in order to run some name-based virtual hosts on one IP address, and either IP-based, or another set of name-based virtual hosts on another address.

Many servers want to be accessible by more than one name. This is possible with the ServerAlias directive, placed inside the VirtualHost section. For example in the first VirtualHost block above, the ServerAlias directive indicates that the listed names are other names which people can use to see that same redhatserver site:

ServerAlias example.com *.example.com

use name based hosting

uncomment the next line

NameVirtualHost *:80


install elinks browser

rpm -ivh elinks*

then from terminal

elinks www.sourav.com
elinks www.test.com