Saturday, February 25, 2012

Basic OpenVz Commands

1] To Start the VPS.
[root@server ~]# vzctl start 101

2] To Stop the VPS.
[root@server ~]# vzctl stop 101

3] To stop the VPS quickly and forcefully.
[root@server ~]# vzctl stop 101 –fast

4] To restart the VPS.
[root@server ~]# vzctl restart 101

5] To destroy VPS.
[root@server ~]# vzctl destroy 101 (good idea to stop it first)

6] To enter into VPS.
[root@server ~]# vzctl enter 101

7] To logout from VPS.
[root@101 ~]# exit

8] To display the list of active VPS's.
[root@server ~]# vzlist

9] To display the list of all VPS.
[root@server ~]# vzlist -a

10] To check the status of a VPS.
[root@server ~]# vzctl status 101

11] To show resource usage on VPS.
[root@server ~]# vzcalc -v 101

12] Execute commands against the VPS.
[root@server ~]# vzctl exec 101 df -h

13] To set the Hostname of a VPS.
[root@server ~]# vzctl set 101 --hostname --save

14] To set new IP to the VPS.
[root@server ~]# vzctl set 101 --ipadd --save

15] To remove IP of VPS.
[root@server ~]# vzctl set 101 --ipdel --save

16] To set the nameserver for VPS.
[root@server ~]# vzctl set 101 --nameserver --save

17] To set root password of VPS.
[root@server ~]# vzctl set 101 --userpasswd root:test
18] To set boot status.
[root@server ~]# vzctl set 101 --onboot yes --save

19] To check CPU Power and Utilization.
[root@server ~]# vzcpucheck -v

20] To set the number of CPUs available to a VPS.
[root@server ~]# vzctl set 101 --cpus 2 --save

21] To set the minimum and maximum CPU limits.
[root@server ~]# vzctl set 101 --cpuunits 1500 --cpulimit 4 --save

22] To check Container's Resources Usage.
[root@server ~]# vzcalc -v 101

23] To set quota & hardisk space.
[root@server ~]# vzctl set 101 --diskspace 10G:11G --save

24] To check the disk quota of a VPS.
[root@server ~]# vzquota stat 101 -t

25] To check memory consumption.
[root@server ~]# vzmemcheck -v

26] To assign disk inodes.
[root@server ~]# vzctl set 101 --diskinodes 90000:91000 --save

27] To run yum update on VPS.
[root@server ~]# vzyum 101 -y update

28] To install package using yum on VPS.
[root@server ~]# vzyum 101 -y install vsftpd*

29] To install package using rpm on VPS.
[root@server ~]# vzrpm 101 -Uvh vsftpd*

30] To find out the templates installed on your system.
[root@server ~]# vzpkgls

Install OpenVz on RedHat

OpenVZ is a complete server automation and virtualization software. OpenVZ creates multiple isolated Virtual Private Servers (VPSs) on a single physical server to share hardware and management effort with maximum efficiency. Each VPS performs and executes exactly like a stand-alone server for its users and applications as it can be rebooted independently and has its own root access, users, IP addresses, memory, processes, files, applications, system libraries, and configuration files.

Note:- Following steps I have used to install OpenVz on Red Hat Enterprise Linux 5.4 [32 bit].

Per quest:-
  • Configure IP = & Hostname =
  • Create separate partition for container's private directories i.e. /vz.
  • Firewall and Selinux should be off.
  • Download Kernel and OpenVz Utilities from following link and save it on Desktop & also download precreate OS template.

Kernel Download link =
vzctl utility =
vzquota utility =
OS template =

Install OpenVz on redhat:-
1] Install kernel binary rpm.
[root@server ~]# cd Desktop
[root@server Desktop]# rpm -i ovzkernel-2.6.18-274.12.1.el5.028stab096.1.i686

2] There are a number of kernel limits that should be set for OpenVZ to work correctly.
Edit and append sysctl.conf file.
[root@server ~]# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
# Enables source route verification
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
# we do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

3] To apply changes use following command.
[root@server ~]# sysctl -p

4] Make sure SELinux is disabled.
[root@server ~]# vi /etc/sysconfig/selinux
SELINUX = disabled

5] Now, you should reboot your computer and choose "OpenVZ" kernel from the boot loader menu.

[root@server ~]# reboot

6] Install opevz utilities.
[root@server ~]# cd Desktop
[root@server Desktop]# rpm -ivh vzctl-lib-
[root@server Desktop]# rpm -ivh vzctl-3.0.23-1.i386.rpm
[root@server Desktop]# rpm -ivh vzquota-3.0.12-1.i386.rpm

7] Start vz service.
[root@server ~]# service vz start
[root@server ~]# chkconfig –level 235 vz on

Creating New Virtual Private Server:-

1] Download the corresponding OS template and place it to the /vz/template/cache directory of the physical machine.

2] Create new VPS by using following command.
Syntax :- # vzctl create <Container ID> --ostemplate <templage name> --config basic
Example :-
[root@server ~]# vzctl create 101 --ostemplate centos-5-x86 --config basic

This will create a Virtual Private Server with ID 101, the private area based on

the centos-5-x86 OS template.

3] To check container is created or not.
[root@server ~]# vzlist -a

Monday, February 20, 2012

SSH Server Configuration with Advance Option

ssh is a program for logging into a remote machine and for executing commands on a remote machine. It is intended to replace rlogin and rsh, and provide secure encrypted communications between two untrusted hosts over an insecure network. The ssh client connects and logs into the specified host name. The user must provide his identity to the remote machine as specified in the sshd_config file, which can usually be found in /etc/ssh directory.

Per quest:-
  • Configure Server IP – & Hostname =
  • Configure Client IP – & Hostname =
  • Firewall should be off on server.
SSH Server Side Configuration:-
1] Three packages require to configure SSH server.
[root@server ~]# yum install openssh-server portmap xinetd

2] Now start the service sshd, xinetd, portmap
[root@server ~]# service sshd start
[root@server ~]# service xinetd start
[root@server ~]# service portmap start

3] Now make these service's on after reboot by using chkconfig command.
[root@server ~]# chkconfig –level 235 sshd on
[root@server ~]# chkconfig –level 235 xinetd on
[root@server ~]# chkconfig –level 235 portmap on

4] Create new user's.
[root@server ~]# useradd anup
[root@server ~]# passwd anup
[root@server ~]# useradd shubham
[root@server ~]# passwd shubham

SSH Client Side Configuration:-
1] Check communication with server.
[root@client ~]# ping

2] Now conncet SSH server using ssh command with root username & password.
[root@client ~]# ssh root@

Advace SSH Server Configuration:-
  • Block access to root user over ssh session, By default root user able to login through ssh.
1] Edit option from main configuration file.
[root@server ~]# vi /etc/ssh/sshd_config
From - #PermitRootLogin no --> PermitRootLogin yes
    • Save file and restart sshd service and try to login from client using root user.
2] Change default port no. (22) of ssh service.
[root@server ~]# vi /etc/ssh/sshd_config [ Remove port no. from following line & add new one.]
# What ports, IPs and protocols we listen for
From - Port 22 --> Port 2705
[root@server ~]# service sshd restart
    • To Login with new port number we have to use -p option with new port no.
[root@client ~]# ssh root@ -p 2705

3] SSH logins can be limited to only certain users who need remote access.
[root@server ~]# vi /etc/ssh/sshd_config [ Add following line at end of file. ]
AllowUsers anup shubham

4] Disconnect network after 3 invalid login attempt.
[root@server ~]# vi /etc/ssh/sshd_config [ Edit following line & Restart sshd service ]
From:- #MaxAuthTries = 6 To:- MaxAuthTries = 3

5] Restrict SSH access by IP address/hostname.
[root@server ~]# vi /etc/hosts.deny [ Insert the following line at end of file ]
sshd: OR
[root@server ~]# service sshd restart

Wednesday, February 08, 2012

Apache with DNS Server

The DNS translates Internet domain and host names to IP addresses. DNS automatically converts the names we type in our Web browser address bar to the IP addresses of Web servers hosting those sites. Domain Name System to determine the IP address associated with a domain name. This process is also known as forward DNS resolution. Reverse DNS lookup is the inverse process, the resolution of an IP address to its designated domain name.

  • Package = bind, caching, httpd
  • Service = named, httpd
  • Port no. = 53 – DNS, 80 – HTTP
  • Configuration file = /etc/named.caching-nameserver.conf
Per quest:-
  • Configure Server IP -
  • Configure Virtual IP – &
  • Configure Server Hostname –
Configure DNS Server:-
1] Install required packages for DNS.
[root@server ~]# yum install bind* caching* -y

2] Edit main configuration file of DNS.
[root@server ~]# vi /etc/named.caching-nameserver.conf
listen-on port 53 {;;};
allow-query { none;;};
match-clients { none;;};

3] Add the website zone in rfc1912.zones file.
[root@server ~]# vi /etc/named.rfc1912.zones
#Go to end of the file and type as follows.
zone “” IN {
type master;
file “”;
allow-update { none; };
zone “” IN {
type master;
file “”;
allow-update { none; };
zone “” IN {
type master;
file “”;
allow-update { none; };
zone “” IN {
type master;
file “named.local”;
allow-update { none; };

4] Now configure zone files.
[root@server ~]# cd /var/named/chroot/var/named
[root@server named]# cp
[root@server named]# vi
$TTL 86400
@          SOA       root (
                                              42 ; serial
                                              3H ; refresh
                                              15M ; retry
                                              1W ; expiry
                                              1D ) ; minimum
                                 IN NS               IN A         IN A  IN A

[root@server named]# cp named.local named.local.backup
[root@server named]# vi named.local
$TTL 86400
@          SOA      root.localhost. (
                                            1997022700 ; Serial
                                            28800 ; Refresh
                                            14400 ; Retry
                                            3600000 ; Expiry
                                            86400 ) ; Minimum
             IN NS
1           IN PTR
10         IN PTR
20         IN PTR

[root@server named]# cd

5] Set primary DNS server.
[root@server ~]# vi /etc/resolv.conf

6] Start named service.
[root@server ~]# service named start
[root@server ~]# chkconfig named on

7] Use following command to test DNS server.
[root@server ~]# dig
[root@server ~]# dig
[root@server ~]# dig
[root@server ~]# nslookup
[root@server ~]# nslookup

Configure Aapche Web Server:-
8] Now install packeges for apache web server.
[root@server ~]# yum install http* -y

9] Edit & Append the following line in httpd.conf file.
[root@server ~]# vi /etc/httpd/conf/httpd.conf
#Name VirtualHosts *:80 --> Name VirtualHosts

#Go to end of file.
DocumentRoot /var/www/html/
DirectoryIndex index.html

DocumentRoot /var/www/html/
DirectoryIndex index.html

DocumentRoot /var/www/html/
DirectoryIndex index.html

10] Create web pages for website.
[root@server ~]# cd /var/www/html
[root@server html]# mkdir
[root@server ~]# cd
[root@server]# cat > index.html
<b><font size=15 color=orange><center>This is</center></font></b>

[root@server]# cd ..
[root@server html]# cd
[root@server]# cat > index.html
<b><font size=15 color=blue><center>This is</center></font></b>

[root@server]# cd ..
[root@server html]# cd
[root@server]# cat > index.html
<b><font size=15 color=green><center>This is</center></font></b>
[root@server]# cd

11] Start httpd service.
[root@server ~]# service httpd start
[root@server ~]# chkconfig httpd on

12] Point your Web Browser to following URL.