Wednesday, November 24, 2010

How to install Oracle 10g from rpm in redhat enterprise linux rhel5


This document explains how to install the Oracle 10g database server on a redhat rhel5 linux
machine using rpm package. This steps will work in other redhat distros like Centos, Fedora etc.

System:
VMware VM
OS Redhat enterprise Linux 5.4
32 bit
IP: 192.168.0.56
RAM = 1700Mb
Host machine Dell inspiron 1545

Oracle software:
Oracle 10g
Version 10.2.0.1.0

Other Requirements:
Yum server

Installation:
Login as root user
login as: root
root@192.168.0.35's password:
Last login: Sat Nov 20 15:17:28 2010

Download the rpm from oracle.com:
[root@oracle /]# ls
bin dev home lost+found misc net oracle-xe-univ-10.2.0.1-1.0.i386.rpm root selinux sys tmp var boot etc lib media mnt opt proc sbin srv tftpboot usr

#Changing the version 5.4 to rhel4:
[root@oracle /]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 4 (Tikanga)installed #10g doesnt support rhel 5.4
[root@oracle /]#

Checking whether the dependencies are installed or not:
[root@oracle /]# rpm -r prm -q glibc libaio
libaio-0.3.106-3.2

Checking the swap space:
[root@oracle /]# swapon -s
FilenameTypeSizeUsedPriority
/dev/sda3 partition 23535120 -1

Checking the memory status:
[root@oracle /]# free -m
total used free shared buffers cached
Mem: 1685 654 1030 0 27 544
-/+ buffers/cache: 82 1602
Swap: 2298 0 2298

#Adding the kernel parameters to the sysctl.conf file:
[root@oracle /]# cat /etc/sysctl.conf

# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536
# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 4294967295
# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 268435456

#Parameters for Oracle installation
kernel.sem = 250 32000 100 128
kernel.shmmax =536870912
kernel.shmmni =4096
kernel.shmall =2097152
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
[root@oracle /]#

Reloading and checking for errors:
[root@oracle /]#
[root@oracle /]# sysctl -p > /dev/null
[root@oracle /]#

Installing the oracle rpm:
[root@oracle /]# rpm -ivh oracle-xe-univ-10.2.0.1-1.0.i386.rpm
Preparing... [100%]
1:oracle-xe-univ [100%]
Executing Post-install steps...
You must run '/etc/init.d/oracle-xe configure' as the root user to
configure the database.


You will be prompted to run the following command for configuring oracle:
[root@oracle /]# /etc/init.d/oracle-xe configure

Oracle Database 10g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 10g Express
Edition. The following questions will determine whether the database should
be starting upon system boot, the ports it will use, and the passwords that
will be used for database accounts. Press to accept the defaults.
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]: #Hit enter

Specify a port that will be used for the database listener [1521]: #Hit enter

Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration: #Give a password
Confirm the password: #Retype it

Do you want Oracle Database 10g Express Edition to be started on boot (y/n) [y]:y or #Hit enter

Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to "http://127.0.0.1:8080/apex"
[root@oracle /]#

[root@oracle /]# cd /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/

Run the following script for setting environment variables:
[root@oracle bin]# . oracle_env.sh
[root@oracle bin]# echo $?
0

Add the script in profile file for environment variables for oracle [To survive reboots]:
[root@oracle bin]# cat >> /etc/profile
. /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh

And source it to make effect:
[root@oracle bin]# . source /etc/profile
[root@oracle bin]# cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1

else
PATH=$1:$PATH
fi
fi
}
# ksh workaround
if [ -z "$EUID" -a -x /usr/bin/id ]; then
EUID=`id -u`
UID=`id -ru`
fi
# Path manipulation
if [ "$EUID" = "0" ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
if [ -x /usr/bin/id ]; then
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
fi
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. $i
else
. $i >/dev/null 2>&1
fi
fi
done
unset i
unset pathmunge
. /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh
[root@oracle bin]#

Checking oracle from Command line:
[root@oracle bin]# sqlplus system

SQL*Plus: Release 10.2.0.1.0 - Production on Sat Nov 20 16:58:56 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

SQL> exit
Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
[root@oracle bin]# cd

Checking the user list:
SQL> select * from all_users;

USERNAME USER_ID CREATED
------------------------------ ---------- ------------------
FLOWS_020100 35 31-JAN-06
FLOWS_FILES 34 31-JAN-06
HR 33 31-JAN-06
MDSYS 32 31-JAN-06
ANONYMOUS 28 31-JAN-06
XDB 27 31-JAN-06
CTXSYS 25 31-JAN-06
DBSNMP 23 31-JAN-06
TSMSYS 20 31-JAN-06
DIP 18 31-JAN-06
OUTLN 11 31-JAN-06

USERNAME USER_ID CREATED
------------------------------ ---------- ------------------
SYSTEM5 31-JAN-06
SYS0 31-JAN-06

13 rows selected.

Listing the DBA users:
SQL> select username from dba_users;

USERNAME
------------------------------
TSMSYS
XDB
HR
FLOWS_020100
DBSNMP
DIP
OUTLN
CTXSYS
MDSYS
FLOWS_FILES
SYSTEM

USERNAME
------------------------------
SYS
ANONYMOUS
13 rows selected

Licence:
.

Login:
Databse:


Http Access:


Tuesday, November 16, 2010

Process states in linux systems

There are many states for processes in linux environment. You can see the process states using the following commands.

#ps
#ps -ax       -From all users and terminals.
#ps -aux     -Shows Process owner also.

For the dynamic details:

#top
#top -c      -Sorts according to CPU usage.
#top   and pressing M(shift+m)  - sorts according to memory usage.

Main process states are as follows:


             D       Marks a process in disk (or other short term, uninterruptible) wait.
             I       Marks a process that is idle (sleeping for longer than about 20 seconds).
             R       Marks a runnable process.
             S       Marks a process that is sleeping for less than about 20 seconds.

             T       Marks a stopped process.
             Z       Marks a dead process (a ``zombie'').

Additional characters after these, indicates additional state information:

             +       The process is in the foreground process group of its control terminal.
             <       The process has raised CPU scheduling priority.
             >       The process has specified a soft limit on memory requirements and is currently exceeding that limit; such a process is (necessarily) not swapped.
             E       The process is trying to exit.
             L       The process has pages locked in core (for example, for raw I/O).
             N       The process has reduced CPU scheduling priority (see setpriority(2)).
             s       The process is a session leader.
             V       The process is suspended during a vfork(2).
             W       The process is swapped out.
             X       The process is being traced or debugged.

How to install and configure oracle 10g standalone database server in redhat rhel5 linux

Oracle 10g installation on RHEL5 ( Standalone Server)

This document explains how to install and configure the Oracle 10g database server on a redhat rhel5 linux machine. This steps will work in other redhat distros like Centos, Fedora etc.

System:
VMware VM
OS Redhat enterprise Linux 5.4
32 bit
IP: 192.168.0.56
RAM = 1700Mb
Host machine Dell inspiron 1545

Oracle software:
Oracle 10g
Version 10.2.0.1.0

Other Requirements:
Yum server

Pre - Installation steps:

Setting the hostname:
[root@oracle ~]# hostname
oracle.lap.work

Resolving the hostname:
[root@oracle ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1oracle.lap.work oracle localhost.localdomain localhost
::1localhost6.localdomain6 localhost6
192.168.0.35 oracle.lap.work oracle

Making the hostname permenant:
[root@oracle ~]# cat s/etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=oracle.lap.work

Changing the OS Name:
Oracle 10g does not support the rhel 5.4. So we've tochange it to rhel4

[root@oracle ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 4 (Tikanga)

Installation:
Installing dependancies:

[root@oracle ~]# yum install compat-db compat-gcc* compat-libstdc++* openmotif* sysstat telnet-server libaio* gcc*

Now creating groups and users for oracle installation:
[root@oracle ~]# [root@oracle ~]# groupadd -g 200 oinstall
[root@oracle ~]# groupadd -g 200 oinstall1 dba
[root@oracle ~]# useradd -g oinstall -G dba oracle-u 200
[root@oracle ~]# passwd oracle
Changing password for user oracle.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Creating home directories for oracle:
Crs home:
[root@oracle ~]# mkdir -p /u01/app/oracle/product/10.2.0/crs
Oracle home:
[root@oracle ~]# mkdir -p /u01/app/oracle/product/10.2.0/db_1

Setting Kernel & other parameters for Oracle installation in /etc/sysctl.conf file
[root@oracle ~]# cat >> /etc/sysctl.conf
#Oracle installation parameters
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_fin_timeout = 5
net.ipv4.tcp_keepalive_intvl = 5
net.ipv4.tcp_keepalive_time = 3
net.ipv4.tcp_keepalive_probes = 9
net.ipv4.tcp_orphan_retries = 2
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144^[[A 4
kernel.domainname = lap.work #change the domain name as you wish
[root@oracle ~]#

Reloading the sysctl.conf to make effect the above parameters:
[root@oracle ~]# sysctl -p

You can check the errors using
[root@oracle ~]# sysctl -p > /dev/null

Settings for limiting the resource usage of oracle user:
[root@oracle ~]# cat >> /etc/security/limits.conf << EOF
> oracle soft nproc 4096
> oracle hard nproc 16384
> oracle soft nofile 2048
> oracle hard nofile 65536
> EOF

[root@oracle ~]# cat >> /etc/pam.d/login << EOF
> session required /lib/security/pam_limits.so
> EOF

[root@oracle ~]# [root@oracle ~]# cat >> /etc/pam.d/su << EOF
> session required /lib/security/pam_limits.so
> EOF

[root@oracle ~]# cat >> /etc/pam.d/sshd << EOF
> session required /lib/security/pam_limits.so
> EOF

Adding the variables and functions needed for oracle installation into /etc/profile file:

[root@oracle ~]# cat >> /etc/profile
#oracle installation variavl bles and functions
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
CRS_HOME=$ORACLE_BASE/product/10.2.0/crs
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
if [ $USER = .oracle. ]; then
ulimit .u 16384 .n 65536
fi

Sourcing it to make effect:
[root@oracle ~]# source /etc/profile

Adding the variables and functions needed for oracle installation into user oracle's profile file:

cat >> ~oracle/.bash_profile
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
CRS_HOME=$ORACLE_BASE/product/10.2.0/crs
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORACLE_SID=orcl; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH


Sourcing it to make effect. Or you can logout and log in.

[oracle@oracle ~]$ sourse .bash_profile

Hang Checker Timer:

[root@oracle ~]# cat >> /etc/modprobe.conf
options hangcheck-timer hangcheck_tick=30 hangcheck_margin=180

Starting the hangcheck driver using the following command

[root@oracle ~]# modprobe hangcheck-timer

Now mount the cd to /media and copy the oracle database directory to /u01/app/oracle:

Now we have :
[root@oracle ~]# cd /u01/app/oracle/
[root@oracle oracle]# ls
database product

Changing the ownership and permissions of oracle files and directories:

[root@oracle oracle]# chown -R oracle:dba /u01/app/oracle/
[root@oracle oracle]# chmod -R 775 /u01/app/oracle/

Now we can start the installation:

You have to do this in runlevel 5, ie graphical mode:
You have to run the command xhost + as root user. As shown below.



Then only you will get access to oracle's graphical installation tool.

Starting the installation:

First we have to switch as user oracle and goto the directory /u01/app/oracle/database.
There you can see a script runInstaller. Execute it. See the pic below.


And you will get the following window.


Set the database password in that. And click next.
Note: It will be the password for the users SYS,SYSTEM,SYSMAN and DBSNMP

Now you will get the next window as follows:


Check the oracle group name is oinstall and click next.

Here you will get the prerequisite check results. There may be some errors. We are lacking enough swap memory here. And network script is not executed. [Its because we have static ip not dhcp]


Creating swap memory:

Sometimes there wont be enough swap memory in your system. So you have to create swap area either by partition or file.

Here we create swap using file.

[root@oracle oracle]# touch /swapfile

Using dd command and dumping zeros to the file:

[root@oracle oracle]# dd if=/dev/zero of=/swapfile bs=1024 count=500000
500000+0 records in
500000+0 records out
512000000 bytes (512 MB) copied, 71.4932 seconds, 7.2 MB/s

Making swap filesystem:

[root@oracle oracle]# mswkswap -v1 /swapfile
Setting up swapspace version 1, size = 511995 kB

Creating entry in fstab:

[root@oracle oracle]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda3 swap swap defaults 0 0
/swapfile swap swap defaults 0 0

Mounting and enabling it:

[root@oracle oracle]# mount -a
[root@oracle oracle]# swapon -a

Checking the swap status:

[root@oracle oracle]# swapon -s
FilenameTypeSizeUsedPriority
/dev/sda3 partition23535120-1
/swapfile file4999920-2

Now rechecking and continuing installation:



Now Pre-checks are over:


If there was errors, it'll be listed in red color so check for errors.

Now Click on install.


It may take some time.

Some configuration scripts will run during installation:




At the end of installation we have to run two scripts manually as root user:


1st script:

[root@oracle db_1]# ./root.sh

Running Oracle10 root.sh script...

The following environment variables are set as:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/10.2.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]:
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...

Creating /etc/oratab file...

Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
[root@oracle db_1]# cd ../../../oraior

2nd script:

[root@oracle oraInventory]# ./orainstRoot.sh
Changing permissions of /u01/app/oracle/oraInventory to 770.
Changing groupname of /u01/app/oracle/oraInventory to oinstall.
The execution of the script is complete
[root@oracle oraInventory]#


For using the EM you have to run this command as user oracle:
Switching user as oracle:
[root@oracle oraInventory]# su - oracle

Running the command:
[oracle@oracle ~]$ emctl start dbconsole
TZ set to Asia/Calcutta
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.0
Copyright (c) 1996, 2005 Oracle Corporation. All rights reserved.
http://oracle.lap.work:1158/em/console/aboutApplication
  • An instance of Oracle Enterprise Manager 10g Database Control is already running.
Now installation is over:

Now login using web access:
http://192.168.0.35/em



user :sys
password: same you've given during oracle installation

Accepting the license:


Thats it



Using the command prompt:

Login as user oracle:
[oracle@oracle ~]$ sqlplus / as stysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Tue Nov 16 12:48:40 2010

Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> select * from all_users;

USERNAME USER_ID CREATED
------------------------------ ---------- ---------
BI 60 16-NOV-10
PM 59 16-NOV-10
SH 58 16-NOV-10
IX 57 16-NOV-10
OE 56 16-NOV-10
HR 55 16-NOV-10
SCOTT 54 30-JUN-05
****** Output truncated *********


SQL> shutdown
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Thats it. Leave a comment if you like. Enjoy.

Friday, October 29, 2010

Usage of find command in redhat linux rhel5


Usage of find command in linux and Unix:

Find command is used to search dynamically in Linux systems. In this tutorial  we'll see various practical usage examples of find command. This examples are shown in a redhat enterprise Linux system. Same commands will work with other redhat distributions like Centos, Fedora etc and other distributions like ubuntu, debian as well.

The general syntax of find command is as follows.
#find [Directory] [criteria]

Directory is where we want to search
Criteria is what we are giving to search. Eg file name, user name, Inode number etc.

The following command will search a file with file name file_name in current working directory.
#find -name file_name

Thursday, October 21, 2010

What is the difference between hard boot and cold boot in linux

A hard boot (also known as cold boot) involves turning on the power with the on/off switch [Manually],

A soft boot ( also known as warm boot) involves using the operating system to reboot.

Friday, October 15, 2010

How to configure syslog server or a centralized log server in redhat linux rhel5 or centos

This article will explain installing and configuring a syslog log server in redhat enterprise linux. It'll work in other redhat distributions like centos, fedora etc.
Centralized log server (syslog server)
Suppose we have a server and 5 client machines. And we want to monitor the logs of all those client machines. In situations like this, we will use centralized server as a log server. Whatever events are happening in client machines, the logs will be sent to the server. So that we can monitor all the logs from a centralized server. We make use of syslog service for this. You can also check out another log server like syslog-ng
Features of syslog:
1. Logs the daemon information to localhost
2. Logs the daemon information to Remote host
3. Logs the daemon information to List of users
4. Logs the daemon information to console

Thursday, October 14, 2010

How to install and configure Nagios Monitoring tool in redhat linux rhel5 or centos

This article will help you to install and configure Nagios monitoring tool in redhat linux or other redhat distributions like fedora, centos etc.
Nagios Installation :
Installing packages. Apache, PHP, GCC & GD

Installing Apache web server:
#yum -y install httpd*
set hostname in FQDN
#service httpd on


Installing PHP, GCC and GD:
#yum -y install php*
#yum -y install gcc*
#yum -y install gd*

Linux boot process in redhat enterprise linux rhel5

This post explains about the linux boot process and important scripts participating in it. The paper is based on the booting of Redhat Enterprice Linux machines. Version 5.4

Roadmap
Power Cycle -> CPU Reset -> BIOS -> Boot Device -> MBR -> IPL ->/ boot/grub/grub.conf -> /etc/inittab -> /etc/rc.d/rcX.d -> /etc/rc.local -> /etc/isuue -> /etc/motd

Power Cycle
When we power on the system, it'll go to SMPS and will reset chips in CPU.

Power On Self Test (POST)
The computer power-on self-test tests the computer to make sure it meets the necessary system requirements and that all hardware is working properly before starting the remainder of the boot process. If the computer passes the POST, the computer may have a single beep as the computer starts and the computer will continue to start normally, Passing the control to the BIOS.

BIOS [Basic Input Output System]
The BIOS is the first code run by a PC when powered on. The primary function of the BIOS is to load and start an operating system. When the PC starts up, the first job for the BIOS is to initialize and identify system devices such as the video display card, keyboard and mouse, hard disk, CD/DVD drive and other hardware. The BIOS then locates boot device such as a hard disk or a CD, and loads and executes that software, giving it control of the PC.

Thursday, October 7, 2010

What is a sticky bit and how to set a sticky bit on a directory on redhat linux

Users with write permission in a directory can delete the files created by other users. This lets users to destroy the data created by other users.
But with sticky bit set on a directory one can only delete the files created by him.

Setting sticky bit on a directory

By symbolic method:
#chmod o+t directory_path
eg:
#chmod o+t /resumes

By numeric method:
If the current permission of the directory is 664, then
#chmod 1664 /resumes

1 on the left end of the permission sets the sticky bit.

Now on the file can be deleted only by the owner of the file.

User administration in redhat linux

User administration in Linux
In Linux there are three type of users.
1. Super user or root user
Super user or the root user is the most powerful user. He is the administrator user.
2. System users
System users are the users created by the softwares or applications. For example if we install Apache it will create a user apache. This kind of users are
known as system users.
3. Normal users
Normal users are the users created by root user. They are normal users like John, Ramu etc. Only the root user has the permission to create or remove a user.

Thursday, September 16, 2010

Configuring software raid in centos linux

This article explains  what is Raid, what are important levels and how to install and configure a raid device in a centos or redhat linux system using the software mdadm. This is tested in Redhat rhel5 and also works with other distributions as fedora, centos etc.

What is RAID?
RAID is redundant array of independent or inexpensive disks. Raid is a storage technology that combines multiple disk drive components into a logical unit. Data is distributed across the drives in one of several ways called "RAID levels", depending on what level of redundancy and performance is required. It is mainly used for data protection. It protects our data storage from failures and data loss. All storage units now use  raid technology.

It has following uses.
1. Data protection
2. Increasing performance

Types of RAIDs:
There are alot of levels of RAIDs. But the main levels are
1. Level 0 or Striping
2. Level 1 or Mirroring
3. Level 5 or Striping + Parity

Level 0:
It is also known as striping. You know hard disk is a block device. Datas are read and written from/to it by blocks.
Suppose we have data block as below
1 0 1 1
Suppose each bit takes one cpu clock cycles for writing  into a disk. Total, it will take 4 cpu clock cycles.

With stripping:
In striping we use "N" number of hard disks. RAID devides the data block by "N" and writes each part to each disk in parallel.

If we have 4 hard disks, It'll take only one cpu clock  cycle if we use Level 0 RAID.
Raid 0 is best for where more writing take place than reading. But is insecure as there is no recovery mechanisms.

Level 1:
Also known as Mirroring. One is the exact replica of other. Whatever writing to master disk will be written in to mirror disk also. Reading can be performed fro each disk simultaneously, thus increasing the read performance.
But can be utilize only 50% of the total size.

Level 5:
It is a combination of striping and parity. Need at least three hard disks. Both parity and data are distributed in all. If one hard disk fails, data on that can be regenerated by the data and parity information in the other two hard disks.

Disk or Partition requirement
Raid 5 :need 3 disks
Raid 0 :need 2 disks
Raid 1 :need 2 disks

Implementation of raid level 5
Here we'll show how to create a Level 5 raid device. Here we use three partitions /dev/sdb /dev/sdc /dev/sdd. Keep in mind that, in real industry it'll be three different hard disks.

This following command will create a raid device /dev/md0 with level 5
#mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sd{b,c,d}
mdadm: array /dev/md0 started.

If we run the command "watch cat /proc/mdstat" while executing the above command, we can see the status of the process of creating md raid device. Output will be as given below

[root@server ~]# watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat                                                                      Sat Mar  3 19:21:31 2012
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd[3] sdc[1] sdb[0]
      10485632 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]
      [======>..............]  recovery = 33.5% (1759128/5242816) finish=1.4min speed=39024K/sec
unused devices: <none>

Status when finished.
[root@server ~]# watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat                                                                      Sat Mar  3 19:23:27 2012
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd[2] sdc[1] sdb[0]
      10485632 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
unused devices: <none>

To see the details of the created raid device.
[root@server ~]# mdadm --detail /dev/md0
 /dev/md0:
 Version    : 00.90.03
 Creation Time : Sat Mar  3 19:20:43 2012
 Raid Level : raid5
 Array Size : 10485632 (10.00 GiB 10.74 GB)
 Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
 Raid Devices : 3
 Total Devices : 3
 Preferred Minor : 0
 Persistence : Superblock is persistent
 Update Time : Sat Mar  3 19:23:18 2012
 State : clean
 Active Devices : 3
 Working Devices : 3
  Failed Devices : 0
  Spare Devices : 0
  Layout : left-symmetric
  Chunk Size : 64K
  UUID : 4e4f2828:3bbe8227:61435180:8ac962cf
  Events : 0.2
  Number   Major   Minor   RaidDevice State
      0       8       16        0      active sync   /dev/sdb
      1       8       32        1      active sync   /dev/sdc
      2       8       48        2      active sync   /dev/sdd
[root@server ~]#

You have to create one configuration file for the raid device created by mdadm. Else it wont be able to survive a reboot.
[root@server ~]# mdadm --detail --verbose --scan >> /etc/mdadm.conf
[root@server ~]# cat  /etc/mdadm.conf
ARRAY /dev/md0 level=raid5 num-devices=3 UUID=4e4f2828:3bbe8227:61435180:8ac962cf
   devices=/dev/sdb,/dev/sdc,/dev/sdd
[root@server ~]#

Formatting the raid device
[root@server ~]# mke2fs -j /dev/md0
or
[root@server ~]# mkfs.ext3  /dev/md0

Creating mount point
#mkdir /data

Mounting the raid device to the created mount point
#mount /dev/md0 /data

Making the mount permanent by adding it in fstab
#vi /etc/fstab
/dev/md0 /data ext3 defaults 0 0
:wq
#mount -a

Now we will create a file of size 100mb in /data
[root@server data]# dd if=/dev/zero of=bf bs=1024 count=100000
100000+0 records in
100000+0 records out
102400000 bytes (102 MB) copied, 1.85005 seconds, 55.3 MB/s
[root@server data]#

Now we will check the raid by failing one partition/disk.
[root@server data]# mdadm /dev/md0 --fail /dev/sdc
mdadm: set /dev/sdc faulty in /dev/md0
[root@server data]#

Now the status is 
root@server ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sat Mar  3 19:20:43 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Mar  3 19:56:08 2012
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 64K
UUID : 4e4f2828:3bbe8227:61435180:8ac962cf
Events : 0.6
Number   Major   Minor   RaidDevice State
   0       8       16        0      active sync   /dev/sdb
   1       0        0        1      removed
   2       8       48        2      active sync   /dev/sdd
   3       8       32        -      faulty spare   /dev/sdc
[root@server ~]#

Now we can remove the faulty one by
[root@server data]# mdadm /dev/md0 --remove /dev/sdc
mdadm: hot removed /dev/sdc
[root@server data]#

Now the status is 
[root@server ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sat Mar  3 19:20:43 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 2
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Mar  3 20:04:16 2012
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 64K
UUID : 4e4f2828:3bbe8227:61435180:8ac962cf
Events : 0.8
Number   Major   Minor   RaidDevice State
   0       8       16        0      active sync   /dev/sdb
   1       0        0        1      removed
   2       8       48        2      active sync   /dev/sdd
[root@server ~]#

Now we add a new disk replacement for the one we removed.
[root@server data]# mdadm /dev/md0 --add /dev/sde
mdadm: added /dev/sde
[root@server data]#

See the data is rebuilding using the data and parity information from the other two disk. 
[root@server ~]# watch cat /proc/mdstat
Every 2.0s: cat /proc/mdstat                                                                      Sat Mar  3 20:08:19 2012
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sde[3] sdd[2] sdb[0]
      10485632 blocks level 5, 64k chunk, algorithm 2 [3/2] [U_U]
      [===>.................]  recovery = 18.9% (994220/5242816) finish=1.8min speed=38239K/sec
unused devices: <none>

Also check
[root@server data]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sat Mar  3 19:20:43 2012
Raid Level : raid5
Array Size : 10485632 (10.00 GiB 10.74 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 3
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Mar  3 20:04:16 2012
State : clean, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
Rebuild Status : 77% complete
UUID : 4e4f2828:3bbe8227:61435180:8ac962cf
Events : 0.8
Number   Major   Minor   RaidDevice State
   0       8       16        0      active sync   /dev/sdb
   3       8       64        1      spare rebuilding   /dev/sde
   2       8       48        2      active sync   /dev/sdd
[root@server data]#

This is how we can create a Raid device with level 1
#mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda{5,6}

This is how we can create a Raid device with level 0
#mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sda{5,6}

Stopping mdadm
*Unmount the md0 before stopping mdadm
[root@server ~]# umount /data/
[root@server ~]# mdadm --stop /dev/md0
mdadm: stopped /dev/md0
[root@server ~]#

If you want to create additional devices[ie there exists a /dev/md0] you may need to add an "-a yes" option to the mdadm command.

For example,
#mdadm --create /dev/md1 -a yes --level=0 --raid-devices=2 /dev/sda{5,6}

Adding Spare disk
We can also specify the spare device at the time of creating the raid array.

[root@server ~]# mdadm --create /dev/md0 --level=1 --raid-devices=2 --spare-devices=1 /dev/sd{b,c,d}

See
[root@server ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 00.90.03
Creation Time : Sat Mar  3 20:36:58 2012
Raid Level : raid1
Array Size : 5242816 (5.00 GiB 5.37 GB)
Used Dev Size : 5242816 (5.00 GiB 5.37 GB)
Raid Devices : 2
Total Devices : 3
Preferred Minor : 0
Persistence : Superblock is persistent
Update Time : Sat Mar  3 20:37:25 2012
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
UUID : 17b820a4:61fc941e:267bf6c8:8adff61a
Events : 0.2
Number   Major   Minor   RaidDevice State
   0       8       16        0      active sync   /dev/sdb
   1       8       32        1      active sync   /dev/sdc
   2       8       48        -      spare   /dev/sdd
[root@server ~]#

For configuring lvm in centos kindly check the following post
Configuring lvm in Linux