Thursday, May 28, 2015

          Enabling and configuring SAR in solaris -10 


SAR ( System Activity Report) is a tool which is very familiar for linux systems for performance analysis. Here i am giving the details for configuring the same in solaris -10

1. First we need to check whether sar is enabled in solaris system or not

#svcs -x system/sar

svc:/system/sar:default (system activity reporting package)
 State: disabled since Wed Apr 16 16:41:41 2014
Reason: Disabled by an administrator.
   See: http://sun.com/msg/SMF-8000-05
   See: sar(1M)
Impact: This service is not running.

2. Now we have to enable the sar in the system

#svcadm enable svc:/system/sar:default


3. Check the status again 

#svcs -x system/sar

svc:/system/sar:default (system activity reporting package)
 State: online since Fri May 15 13:34:38 2015
   See: sar(1M)
   See: /var/svc/log/system-sar:default.log
Impact: None.

4. Now we need to check the crontab entry for the sys

#crontab -l sys
crontab: you are not authorized to use cron.  Sorry.

(this is because sys don't have permission to access the crontab entry so we need to enable the same)

5. Enable the sys for crontab entry by adding sys in /etc/cron.d/cron.allow

6. Now we need to add the below lines in /var/spool/cron/crontabs/sys

0 * * * 0-6 /usr/lib/sa/sa1
20,40 8-17 * * 1-5 /usr/lib/sa/sa1
5 18 * * 1-5 /usr/lib/sa/sa2 -s 8:00 -e 18:01 -i 1200 -A

7. We can check the crontab entry 

#crontab -l sys
0 * * * 0-6 /usr/lib/sa/sa1
20,40 8-17 * * 1-5 /usr/lib/sa/sa1
5 18 * * 1-5 /usr/lib/sa/sa2 -s 8:00 -e 18:01 -i 1200 -A

That's it. Now the System Activity Reporter is running every 20 minutes,
and at 18:05 o'clock a daily report is created.



Wednesday, January 7, 2015

Solaris Zones

Solaris zones are a type of virtualization , where we can create isolated and secured environments for applications (for example if you want to configure a solaris 10 server as a DB server and web server you can create separate zones for each of them)  . For end user's these zones are look like separate machines . All these changes are in software level and default each solaris 10 machine is installing with global zone. We can access all other zones from the global zones .

Each zones has its own node name virtual network interfaces and storage assigned to it. The other benefits of the zones are it does not require dedicated memory,cpu and physical interface associated with it. It has a security boundary which will prevents interaction of  processes associated with one zone  with another, also you can configure separate user list for each zones.

A zone can be in one of the following states

1. Configured - configuration was completed and saved
2. Incomplete - State between install or uninstall
3. Installed-The packages are successfully installed.
4. Ready- The virtual platform has been installed.
5. Running- The zone is booted successfully and running
6.Shutting down - The zone is in the progress of shutting down.
7 Down- The zone has completed the shutdown process and down.

Here i am giving detailed steps for zone configuration for your reference

1. First we need to create a zone called testzone (this is an example , you can give any name)

bash-3.00# zonecfg -z testzone
testzone: No such zone configured
Use 'create' to begin configuring a new zone.
zonecfg:testzone> create
zonecfg:testzone> set zonepath=/zones/testzone
zonecfg:testzone> set autoboot=true
(where zonepath is the path where all the configuration files are installed and autoboot indicates zone need to be booted automatically with global or not)

2. You can see the configuration details using below command

onecfg:testzone> info
zonename: testzone
zonepath: /zones/testzone
brand: native
autoboot: true
bootargs:
pool:
limitpriv:
scheduling-class:
ip-type: shared
hostid:
inherit-pkg-dir:
        dir: /lib
inherit-pkg-dir:
        dir: /platform
inherit-pkg-dir:
        dir: /sbin
inherit-pkg-dir:
        dir: /usr
zonecfg:testzone> verify
zonecfg:testzone> commit
zonecfg:testzone>

3. Now we can see the zone is in configured status

bash-3.00# zoneadm list -cv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   - testzone         configured /zones/testzone                native   shared

4. Here i am installing the new zone

bash-3.00# zoneadm -z testzone install
Preparing to install zone <testzone>.
Creating list of files to copy from the global zone.
Copying <3022> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <1459> packages on the zone.
Initialized <1459> packages on zone.
Zone <testzone> is initialized.
The file </zones/testzone/root/var/sadm/system/logs/install_log> contains a log of the zone installation.

5. Now if we check the status we can see the zone is in installed status

bash-3.00# zoneadm list -cv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   - testzone         installed  /zones/testzone                native   shared

6. Now we can make the zone as ready status 

bash-3.00# zoneadm -z testzone ready
bash-3.00# zoneadm list -cv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   1 testzone         ready      /zones/testzone                native   shared

7. You can login to the zone using below command and during the initial login you have select the options as language/terminal etc

bash-3.00# zlogin -C testzone
[Connected to zone 'testzone' console]                                                                                                                           157/157
Reading ZFS config: done.
...............................................
Select a Language

  0. English
  1. Japanese
  2. Korean
  3. Simplified Chinese
  4. Traditional Chinese

Please make a choice (0 - 4), or press h or ? for help: 0
..........................................
select a Locale

   0. English (C - 7-bit ASCII)
   1. Bengali, India (UTF-8)
   2. Chinese, Singapore (UTF-8)
   3. English, India (UTF-8)
   4. English, Singapore (UTF-8)
   5. Gujarati, India (UTF-8)
   6. Hindi UTF-8
   7. Indonesian (UTF-8)
   8. Kannada, India (UTF-8)
   9. Malay, Malaysia (UTF-8)
  10. Marathi, India (UTF-8)
  11. Tamil, India (UTF-8)
  12. Telugu, India (UTF-8)
  13. Thai TIS620
  14. Thai UTF-8
  15. Go Back to Previous Screen

Please make a choice (0 - 15), or press h or ? for help: 0
..........................................................
What type of terminal are you using?
 1) ANSI Standard CRT
 2) DEC VT52
 3) DEC VT100
 4) Heathkit 19
 5) Lear Siegler ADM31
 6) PC Console
 7) Sun Command Tool
 8) Sun Workstation
 9) Televideo 910
 10) Televideo 925
 11) Wyse Model 50
 12) X Terminal Emulator (xterms)
 13) CDE Terminal Emulator (dtterm)
 14) Other
Type the number of your choice and press Return:

You did not enter a selection.
What type of terminal are you using?
 1) ANSI Standard CRT
 2) DEC VT52
 3) DEC VT100
 4) Heathkit 19
 5) Lear Siegler ADM31
 6) PC Console
 7) Sun Command Tool
 8) Sun Workstation
 9) Televideo 910
 10) Televideo 925
 11) Wyse Model 50
 12) X Terminal Emulator (xterms)
 13) CDE Terminal Emulator (dtterm)
 14) Other
Type the number of your choice and press Return: 1
Creating new rsa public/private host key pair
Creating new dsa public/private host key pair
Configuring network interface addresses:.
- Host Name --------------------------------------------------------------------
                                                                                  Enter the host name which identifies this system on the network.  The name
  must be unique within your domain; creating a duplicate host name will cause
  problems on the network after you install Solaris.

  A host name must have at least one character; it can contain letters,
  digits, and minus signs (-).


                           Host name
                                     vm-testzone

........................................................................

--------------------------------------------------------------------------------    Esc-2_Continue    Esc-6_Help
    Esc-2_Continue    Esc-6_Help
- Confirm Information ----------------------------------------------------------
                                                                                  > Confirm the following information.  If it is correct, press F2;
    to change any information, press F4.



                          Host name: vm-testzone

   Esc-2_Continue    Esc-4_Change    Esc-6_Help
- Time Zone --------------------------------------------------------------------
                                                                                  On this screen you must specify your default time zone.  You can specify a
  time zone in three ways:  select one of the continents or oceans from the
  list, select other - offset from GMT, or other - specify time zone file.

  > To make a selection, use the arrow keys to highlight the option and
    press Return to mark it [X].



      Continents and Oceans
      ----------------------------------
  -   [ ] Africa
  |   [ ] Americas
  |   [ ] Antarctica
  |   [ ] Arctic Ocean
  |   [X] Asia
  |   [ ] Atlantic Ocean
  |   [ ] Australia
  |   [ ] Europe
  v   [ ] Indian Ocean

--------------------------------------------------------------------------------    Esc-2_Continue    Esc-6_Help
    Esc-2_Continue    Esc-6_Help
- Country or Region ------------------------------------------------------------
                                                                                  > To make a selection, use the arrow keys to highlight the option and
    press Return to mark it [X].



      Countries and Regions
      ------------------------
  ^   [ ] Armenia
  |   [ ] Azerbaijan
  |   [ ] Bahrain
  |   [ ] Bangladesh
  |   [ ] Bhutan
  |   [ ] Brunei
  |   [ ] Cambodia
  |   [ ] China
  |   [ ] Cyprus
  |   [ ] East Timor
  |   [ ] Georgia
  |   [ ] Hong Kong
  v   [X] India

--------------------------------------------------------------------------------    Esc-2_Continue    Esc-6_Help
    Esc-2_Continue    Esc-6_Help
- Confirm Information ----------------------------------------------------------
                                                                                  > Confirm the following information.  If it is correct, press F2;
    to change any information, press F4.



                          Time zone: Asia/Calcutta

..............................................
 Esc-2_Continue    Esc-4_Change    Esc-6_Help
- Root Password ----------------------------------------------------------------
                                                                                  Please enter the root password for this system.

  The root password may contain alphanumeric and special characters.  For
  security, the password will not be displayed on the screen as you type it.

  > If you do not want a root password, leave both entries blank.



                     Root password:  ********
                     Root password:  ********


--------------------------------------------------------------------------------    Esc-2_Continue    Esc-6_Help
    Esc-2_Continue    Esc-6_Help


rebooting system due to change(s) in /etc/default/init


[NOTICE: Zone rebooting]


SunOS Release 5.10 Version Generic_142910-17 32-bit
Copyright (c) 1983, 2010, Oracle and/or its affiliates. All rights reserved.
Hostname: vm-testzone
Reading ZFS config: done.

8. Now we have to assign the IP to the particular zone 

bash-3.00# zonecfg -z testzone
zonecfg:testzone> add net
zonecfg:testzone:net> set address=192.168.1.12
zonecfg:testzone:net> set physical=e1000g0
zonecfg:testzone:net> export
zonecfg:testzone:net> end

zonecfg:testzone> export
create -b
set zonepath=/zones/testzone
set autoboot=true
set ip-type=shared
add inherit-pkg-dir
set dir=/lib
end
add inherit-pkg-dir
set dir=/platform
end
add inherit-pkg-dir
set dir=/sbin
end
add inherit-pkg-dir
set dir=/usr
end
add net
set address=192.168.1.12
set physical=e1000g0
end

Now we can see the ip details from global zone 

bash-3.00# ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000
lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        zone testzone
        inet 127.0.0.1 netmask ff000000
e1000g0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
        inet 192.168.1.11 netmask ffffff00 broadcast 192.168.1.255
        ether 8:0:27:fd:ad:b8
e1000g0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
        zone testzone
        inet 192.168.1.12 netmask ffffff00 broadcast 192.168.1.255


Hope you got a brief idea about zones..

Thank you..






















Monday, December 22, 2014

              Procedure to add a new disk in DM multipath 


Multipathing (Device Mapper Multipath) is a technology which is available from RHEL 5 for providing redundancy in I/O paths from storage devices .  Multiple paths are configured from your server to storage and these physical paths are include HBA,cables and switches.
















DM multipath have following capabilities 

1. Redundancy 

Two types of multipath are available active/active and active/passive . In first case both paths are accessible, but in second case only 1 path is accessible at a time. 

2. Improved Performance 

DM multipath can detect loading of the I/O paths and dynamically balance the load.

Almost all of the SAN devices are supported in multpathing. The details of the supported devices are given in multipath.conf.defaults file and when ever we need to change we will add the devices in /etc/multipath.conf file 


Components which is required for multipathing

Kernel components

dm-multipath module - This particular component reroutes the I/O and supports failover for the paths and groups 

multipathd daemon- Monitors the path and takes the action when ever necessary (like failed paths and restored paths)

.Configuration file details 

/etc/multipath.conf - Main configuration file and it is located at /etc

multipath.conf.defaults - This is the default file which contains all the supported SAN devices. The location of the file is /usr/share/device-mapper-multipath 

kpartx command - This tool is derived from util linux partx package . It is used to set up device mapping for the partitions for any partitioned block device . This tool can be used for non linux partitions which is need to be added with DM-MP.

So now i think you got an idea about the DM multipath architecture, Now let us go for adding a new device to DM setup .

 1. First we have to scan the new physical disk

echo "- - -" > /sys/class/scsi_host/host3/scan
echo "- - -" > /sys/class/scsi_host/host4/scan

2. Some times new physical disk will not be visible initially, so need to restart multipath daemon

#service multipathd restart

3. Make alias of the new disk in /etc/multipath.conf file (in this case i have given silverdisk08)

multipath {
                wwid                    put the new uuid no. here
                alias                   silverdisk08
                  }

* you will get the wwid details of the new disk once you restart the multipath service

4. Now add the disk in multipath

#multipath -f silverdisk08

5. Again restart the multipath daemon

#service multipathd restart

6.Now create a physical disk

#pvcreate /dev/mpath/silverdisk08

7. Extend the file system (you can also go for creating new LVM setup as per your requirement)

#vgextend datavg /dev/silverdisk08
#lvextend -L +94G /dev/mapper/datavg-u2ecllv
#resize2fs  /dev/mapper/datavg-u2ecllv





  




Wednesday, December 17, 2014

root mirroring in solaris-10 using SVM

                      Root mirroring in solaris-10 using SVM


Root mirroring is a useful method in solaris 10 for redundancy and this is a very useful method for live upgrade , where patches are applied in root environment and if any issue is faced system will be booted from mirrored environment. 

Detailed steps
*************
1. First we need to identify the disks attached for mirroring this can be done using format command , in below case c0d0 and c0d1 are available disks
***********************************************
bash-3.00# format


Searching for disks...done


AVAILABLE DISK SELECTIONS:
       0. c0d0 <DEFAULT cyl 2085 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0
       1. c0d1 <DEFAULT cyl 2086 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@1,1/ide@0/cmdk@1,0


Specify disk (enter its number): 0
selecting c0d0
Controller working list found
[disk formatted, defect list found]
Warning: Current Disk has mounted partitions.
/dev/dsk/c0d0s0 is currently mounted on /. Please see umount(1M).
/dev/dsk/c0d0s1 is currently used by swap. Please see swap(1M).


FORMAT MENU:
        disk       - select a disk
        type       - select (define) a disk type
        partition  - select (define) a partition table
        current    - describe the current disk
        format     - format and analyze the disk
        fdisk      - run the fdisk program
        repair     - repair a defective sector
        show       - translate a disk address
        label      - write label to the disk
        analyze    - surface analysis
        defect     - defect list management
        backup     - search for backup labels
        verify     - read and display labels
        save       - save new disk/partition definitions
        volname    - set 8-character volume name
        !<cmd>     - execute <cmd>, then return
        quit
format> p (press p)


PARTITION MENU:
        0      - change `0' partition
        1      - change `1' partition
        2      - change `2' partition
        3      - change `3' partition
        4      - change `4' partition
        5      - change `5' partition
        6      - change `6' partition
        7      - change `7' partition
        select - select a predefined table
        modify - modify a predefined partition table
        name   - name the current table
        print  - display the current table
        label  - write partition map and label to the disk
        !<cmd> - execute <cmd>, then return
        quit
partition> p (press p)
Current partition table (original):
Total disk cylinders available: 2085 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders        Size            Blocks
  0       root    wm     820 - 2084        9.69GB    (1265/0/0) 20322225
  1       swap    wu       3 -  133        1.00GB    (131/0/0)   2104515
  2     backup    wm       0 - 2084       15.97GB    (2085/0/0) 33495525
  3 unassigned    wm       0               0         (0/0/0)           0
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6 unassigned    wm       0               0         (0/0/0)           0
  7 unassigned    wm       0               0         (0/0/0)           0
  8       boot    wu       0 -    0        7.84MB    (1/0/0)       16065
  9 alternates    wu       1 -    2       15.69MB    (2/0/0)       32130

In above partition table we can see that 3,4,5,6 are unassigned partitions with in that we can select any partition (in this case i am selecting partition 3)

partition> 3
Part      Tag    Flag     Cylinders        Size            Blocks
  3 unassigned    wm       0               0         (0/0/0)           0

Enter partition id tag[unassigned]:
Enter partition permission flags[wm]:
Enter new starting cyl[0]: 134
Enter partition size[0b, 0c, 134e, 0.00mb, 0.00gb]: 3gb
partition> l
Ready to label disk, continue? yes

partition> p
Current partition table (unnamed):
Total disk cylinders available: 2085 + 2 (reserved cylinders)

Part      Tag    Flag     Cylinders        Size            Blocks
  0       root    wm     820 - 2084        9.69GB    (1265/0/0) 20322225
  1       swap    wu       3 -  133        1.00GB    (131/0/0)   2104515
  2     backup    wm       0 - 2084       15.97GB    (2085/0/0) 33495525
  3 unassigned    wm     134 -  525        3.00GB    (392/0/0)   6297480-------- ( newly created slice) 
  4 unassigned    wm       0               0         (0/0/0)           0
  5 unassigned    wm       0               0         (0/0/0)           0
  6 unassigned    wm       0               0         (0/0/0)           0
  7 unassigned    wm       0               0         (0/0/0)           0
  8       boot    wu       0 -    0        7.84MB    (1/0/0)       16065
  9 alternates    wu       1 -    2       15.69MB    (2/0/0)       32130

2. Secondly we have to create HDD1 partition table same as HDD0
******************************************************
#prtvtoc /dev/rdsk/c0d0s2 | fmthard -s - /dev/rdsk/c0d1s2

(here from partition table we can see that partition 2 contains full back up of the entire disk and same will be copied to new disk HDD1)

3. create the state database in each disk (here i have choose slice no 7 )
*******************************************************
metadb -afc 3 c0d0s7 c0d1s7

a= add the state database 
f=force (this is needed for HDD0 which is mounted 
c=number of state database in each slice

We can see 3 slices of each disk using below command

bash-3.00# metadb
        flags           first blk       block count
     a m  p  luo        16              8192            /dev/dsk/c0d0s7
     a    p  luo        8208            8192            /dev/dsk/c0d0s7
     a    p  luo        16400           8192            /dev/dsk/c0d0s7
     a    p  luo        16              8192            /dev/dsk/c0d1s7
     a    p  luo        8208            8192            /dev/dsk/c0d1s7
     a    p  luo        16400           8192            /dev/dsk/c0d1s7

4. Initialize each disk
**********************************
HDD0

  metainit -f d100 1 1 c0d0s0
  metainit -f d101 1 1 c0d0s1
  metainit -f d103 1 1 c0d0s3

HDD1


  metainit d200 1 1 c0d1s0
  metainit d201 1 1 c0d1s1
  metainit d203 1 1 c0d1s3

5. Initialize the mirrors
****************************
  metainit d0 -m d100
  metainit d1 -m d101
  metainit d3 -m d103

6.Metaroot and editing of /etc/vfstab to boot to our mirror.
********************************************************

 metaroot d0

bash-3.00# cat /etc/vfstab
#device         device          mount           FS      fsck    mount   mount
#to mount       to fsck         point           type    pass    at boot options
#
fd      -       /dev/fd fd      -       no      -
/proc   -       /proc   proc    -       no      -
/dev/md/dsk/d1  -       -       swap    -       no      -
/dev/md/dsk/d0  /dev/md/rdsk/d0 /       ufs     1       no      -
/devices        -       /devices        devfs   -       no      -
sharefs -       /etc/dfs/sharetab       sharefs -       no      -
ctfs    -       /system/contract        ctfs    -       no      -
objfs   -       /system/object  objfs   -       no      -
swap    -       /tmp    tmpfs   -       yes     -
/dev/md/dsk/d3  /dev/md/rdsk/d3 /test1  ufs     2       yes     -


7.Reboot the server

8. Attach the mirror disk using below command

bash-3.00# metattach d0 d200
d0: submirror d200 is attached
bash-3.00# metattach d1 d201
d1: submirror d201 is attached
bash-3.00# metattach d3 d203

(we have to wait till the completion of the sync it is purely depends upon the size of the file system)

d3: submirror d203 is attached

9. Next is we will install the grub in mirrored disk as redundant ( in this case c0d1 is our mirrored disk)

bash-3.00# format
Searching for disks...done


AVAILABLE DISK SELECTIONS:
       0. c0d0 <DEFAULT cyl 2085 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0
       1. c0d1 <DEFAULT cyl 2085 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@1,1/ide@0/cmdk@1,0


bash-3.00# installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c0d1s0
stage1 written to partition 0 sector 0 (abs 16065)
stage2 written to partition 0, 273 sectors starting at 50 (abs 16115)

10. We can boot from c0d1 and check the status














Monday, October 21, 2013

Changing the HDD in netapp and assign the same as spare




Some times we used to face HDD failure in netapp and the role of the failed HDD will be taken care by the spare HDD(Raid 4 setup). So the system will throw the error as "Not enough spare disk" So in this case we have to change the failed HDD with a new one ( should be same size and make with the parent one).


If we check the ONTAP gui the failed HDD will show as broken state (0c.00.6)
 





So first we need to remove the faulty HDD using below mentioned command


#Remove –w 0c.00.06


Then identify the physical disk in the netapp mounted rack which have lights off and remove the HDD physically from the controller .


Insert the new HDD in the same location and wait till the light become green.


Then run the below commands through console ( ssh or telnet)


#priv set advanced


# disk assign 0c.00.06 -s unowned -f


So disk will become orphan state , and next we have to assign the same as spare


#disk unfail -s 0c.00.06


So once we check in GUI we can see that the disk which was in orphan state was assigned as spare to the same controller .


(below case it was 0c.00.2)






 







































Tuesday, April 9, 2013

                         MySQL hardening script 


The MySQL database has become the world's most popular open source database because of its
consistent fast performance, high reliability and ease of use.This script gives some of the
best pracise steps to secure your database from attacks and vulnurabilities for improved
performance .
******************************************************************************
#!/bin/bash

#########################Mysqlhardeningscript################################################################Author:ratheeshvasudevan########################################
read -p "Enter mysql root password" mysqlpass

# Setting password for users 
a=`mysql -uroot -p$mysqlpass -Dmysql --execute "select User from mysql.user where length(password) = 0
or password is null;"`

if [ -z "$a" ]; then

echo "Already password is configured for all users" >> /tmp/mysqlhardening.txt

else

for i in $a

do

`mysql -uroot -p$mysqlpass -Dmysql --execute "UPDATE mysql.user SET password=PASSWORD('onmobile')  WHERE user='${i}'and length(password) = 0;"`

`mysql -uroot -p$mysqlpass -Dmysql --execute "flush privileges;"`

echo "password is set to 'onmobile'" >> /tmp/mysqlhardening.txt

done

fi
#Remove Anonymous account

`mysql -uroot -p$mysqlpass -Dmysql --execute "delete from mysql.user where user = '';"`

if [ $? -eq 0 ]; then

echo "Anonymous account is removed" >> /tmp/mysqlhardening.txt

fi
#Remove shutdown privilege for non root users 

b=`mysql -uroot -p$mysqlpass -Dmysql --execute "select user from mysql.user where Shutdown_priv = 'Y';" |grep -v "user" |grep -v "host" |grep -v "root"`

if [ -z "$b" ]; then

echo "No non admin users with shutdown privileges" >> /tmp/mysqlhardening.txt

else

for i in $b

do

mysql -uroot -p$mysqlpass -Dmysql --execute "update mysql.user set Shutdown_priv = 'N' where user='${i}';"

done

echo "removed the shutdown privileges for non admin users" >> /tmp/mysqlhardening.txt

fi

#Remove Create user privilege for non root users

c=`mysql -uroot -p$mysqlpass -Dmysql --execute "select user from mysql.user where Create_user_priv= 'Y';" |grep -v "user" |grep -v "host" |grep -v "root"`

if [ -z "$c" ]; then

echo "No non admin users with create user privileges" >> /tmp/mysqlhardening.txt

else

for i in $c

do

mysql -uroot -p$mysqlpass -Dmysql --execute "update mysql.user set Create_user_priv='N' where user='${i}';"

done
echo "Removed create user priv for non admin users" >> /tmp/mysqlhardening.txt

fi

#Remove Reload privilege for non admin users

d=`mysql -uroot -p$mysqlpass -Dmysql --execute "select user from mysql.user where Reload_priv = 'Y';" |grep -v "user" |grep -v "root"`

if [ -z "$d" ]; then

echo "No non admin users with reload privileges" >> /tmp/mysqlhardening.txt

else

for i in $d

do

mysql -uroot -p$mysqlpass -Dmysql --execute "update mysql.user set Reload_priv='N' where user='${i}';"

done

echo "Removed Reload privileges for non admin users" >> /tmp/mysqlhardening.txt

fi

#Remove GRANT Privileges for non admin users

e=`mysql -uroot -p$mysqlpass -Dmysql --execute "select user from mysql.user where Grant_priv = 'Y';" |grep -v "user" |grep -v "root"`

if [ -z "$e" ]; then

echo "No non admin users with GRANT privileges" >> /tmp/mysqlhardening.txt

else 

for i in $e

do

mysql -uroot -p$mysqlpass -Dmysql --execute "update mysql.user set Grant_priv = 'N' where user='${i}';"

done

echo "Removed non admin users with GRANT privileges" >> /tmp/mysqlhardening.txt

fi

#Old password hashing

f=`mysql -uroot -p$mysqlpass -Dmysql --execute "show variables like 'old_passwords';" |grep -v "Variable_name" |grep -v "Value" |awk -F " " '{print $2}'`

if [ `echo "$f" |grep -c "OFF"` -eq 1 ]; then

echo "Old password hashing is disabled already" >> /tmp/mysqlhardening.txt

else

mysql -uroot -p$mysqlpass -Dmysql --execute "set old_passwords = 'OFF';"

echo "old_password is set to OFF" >> /tmp/mysqlhardening.txt

fi

#Remove show database privilege for all non admin users 

g=`mysql -uroot -p$mysqlpass -Dmysql --execute "select user from mysql.user where Show_db_priv='Y';" |grep -v "user" |grep -v "root"`

if [ -z "$g" ]; then

echo "No non admin users with Show_db_priv" >> /tmp/mysqlhardening.txt

else

for i in $g 

do

mysql -uroot -p$mysqlpass -Dmysql --execute "update mysql.user set Show_db_priv='N' where user='${i}';"

done

fi

#Adding Secure auth in myql config

h=`mysql -uroot -p$mysqlpass -Dmysql --execute "show variables like 'secure_auth';" | grep -v "Variable_name" |grep -v "Value" |awk -F " " '{print $2}'`

if [ `echo "$h" |grep -c "OFF"` -eq 1 ]; then

sed -i "/^\[mysqld\]/ a\\secure_auth" /etc/my.cnf

else

echo "secure_auth is already configured in this DB" >> /tmp/mysqlhardening.txt
fi

#Removing grant tables option in mysql config 

j=`mysql -uroot -p$mysqlpass -Dmysql --execute "show variables like 'skip_grant_tables'" |grep -v "Variable_name" |grep "Value" |awk -F " " '{print $2}'`

if [ `echo "$j" |grep -c "OFF"` -eq 1 ]; then

echo "Grant tables option is already disabled in this DB" >> /tmp/mysqlhardening.txt

elif [ `echo "$j" |grep -c "ON"` -eq 1 ]; then

sed -i 's/skip_grant_tables/#skip_grant_tables/g' /etc/my.cnf

else

echo "Grant tables option is not avilable in this DB" >> /tmp/mysqlhardening.txt

fi

#Removing skip merge option from mysql

k=`mysql -uroot -p$mysqlpass -Dmysql --execute "show variables like 'have_merge_engine'" |grep -v "Variable_name" |grep "Value" |awk -F " " '{print $2}'`

if [ `echo "$k" |grep -c "DISABLED"` -eq 1 ]; then

echo "merge option is already disabled in this DB" >> /tmp/mysqlhardening.txt

elif [ `echo "$k" |grep -c "ENABLED"` -eq 1 ]; then

sed -i 's/skip_merge/#skip_merge/g' /etc/my.cnf

else

echo "merge option is not avilable in this DB" >> /tmp/mysqlhardening.txt

fi

#Removing client password from mysql config

r=`cat /etc/my.cnf |grep -A 4 "\[client\]"|grep "#password"`

cl_en=1


if [ `echo "$r" |grep -c "#password"` -eq 1 ]; then

echo "Client password is not enabled in this DB" >> /tmp/mysqlhardening.txt

else

sed -i 's/password/#password/' /etc/my.cnf

fi


#Disable interactive login

l=`cat /etc/passwd |grep mysql | awk -F ":" '{print $7}'`

if [ `echo "$l" |grep -c "/bin/bash"` -eq 1 ]; then 

usermod -s /sbin/nologin mysql

echo "interactive login is disabled for mysql user" >> /tmp/mysqlhardening.txt

else

echo "interactive login is already disabled" >> /tmp/mysqlhardening.txt

fi

#Check file system permissions 

m=`mysql -uroot -p$mysqlpass -Dmysql --execute "show variables like 'datadir';" |grep -v "variable_name" |grep -v "Value" |awk -F " " '{print $2}'`

n=`stat --format '%a' $m`

if [ `echo "$n" |grep -c "755"` -eq 1 ]; then 

echo "permission is already set for datadir" >> /tmp/mysqlhardening.txt

else 

chmod 755 $m

echo "permission is reseted for datadir" >> /tmp/mysqlhardening.txt

fi

#Configuration file permission 

o=`stat --format '%a' /etc/my.cnf`

if [ `echo "$o" |grep -c "644"` -eq 1 ]; then

echo "configuration file permission is already set for this DB" >> /tmp/mysqlhardening.txt

else

chmod 644 /etc/my.cnf

echo "Configuration file permisison is set to 644" >> /tmp/mysqlhardening.txt

fi
#Removing test database
p=`mysql -uroot -p$mysqlpass --execute "show databases;" |grep "test"`

if [ -z "$p" ]; then

echo "test database is not available in this DB" >> /tmp/mysqlhardening.txt

else

mysql -uroot -p$mysqlpass --execute "drop database test;"

echo "test database is succesfully removed" >> /tmp/mysqlhardening.txt

fi

echo "Hardening of MysqlDB is completed for this server. Please check /tmp/mysqlhardening.txt for details"


Thursday, January 17, 2013

                               Oracle Start up script 


Usually oracle database can be started or stopped by  logging in to the DB as sysdba and applying "startup" and "shutdown immediate" commands. Here i am providing you a script to configure the same in /etc/init.d/ and we can start, stop and check the status of the oracle with PID details .

Sample script 
*********************************************************************************
#!/bin/bash
# chkconfig: 35 95 1
# description: init script to start/stop oracle database 10g, TNS listener
#
#
# match these values to your environment:
export ORACLE_BASE=/oracle
export ORACLE_HOME=/oracle/product/11.2.0/dbhome_1
export OH=$ORACLE_HOME
export JAVA_HOME=$OH/jdk
export PATH=$OH/bin:$JAVA_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export ORACLE_SID=MBDB
export ORACLE_USER=oracle
# see how we are called:
case $1 in
    start)
    echo "Starting Oracle database ..."
    su - "$ORACLE_USER" <<EOO
    lsnrctl start
    sqlplus /nolog <<EOS
    connect / as sysdba
    startup
EOS
    emctl start dbconsole
EOO
    ;;
        
   stop)
    echo "Stopping Oracle database ..."
    su - "$ORACLE_USER" <<EOO
    emctl stop dbconsole
    sqlplus /nolog <<EOS 
    connect / as sysdba
    shutdown immediate
EOS 
    lsnrctl stop
EOO
;;


    restart){
 $0 stop
 $0 start
}
    ;;

   status)
  a=`ps -ef |grep oracle |grep LISTENER |awk -F " " '{print $2}'|head -1`
  if [ "$a" > 0 ];then
  echo "Oracle is working fine with pid $a"
  else
  echo "Oracle is not working"
  fi
   ;;

    *)
    echo "Usage: $0 {start|stop|restart|status}"
    ;;
esac
*********************************************************************************

Startup output 














stop output














status 




This script will be useful while configuring oracle in HA ( High Availability ) setups 

Sunday, December 23, 2012

                                  Linux Booting Procedure 


Here I am giving you a detailed view about linux booting procedure. As we know linux booting involves multiple steps and stages . Here it the brief  diagram for better understanding. 






















As per the diagram i will explain each and every process as detail.

1. The initial process is called POST ( Power On Self Test) where the bios will start addressing from a particular location (0xFFFF0). The function of the bios in this stage is to perform hardware check and device initialization . Basically BIOS contain two processes one is for POST and other one will initialize the necessary hardware. To boot the operating system BIOS will search the bootable device where the preference  is defined in the CMOS chip of the system. Bootable devices may be a partition of harddisk, CD-ROM, USB flash drive, a network device etc.

2. Commonly linux is booting from HDD, where the Master Boot Record (MBR) contains the primary boot loader. MBR is the 512 byte size where the first 446 byte contains the boot loader (executable code and error text) , 64 byte contains the partition table details of 4 partitions and next 2 byte is the magic number (0xAA55). The magic number serves as a validation code for MBR. The primary function of the primary boot loader is to identify the secondary boot loader (in stage 2) by looking in the  MBR . It will check the active partition and remaining partitions also will be validated by cross checking with MBR and add the details to RAM for execution.

3. The second boot loader is called as kernel loader and the task of this stage is to load the linux kernel with RAM disk. The boot loader for this stage is called as GRUB ( previously LILO also available). GRUB stands for Grant Unified Boot loader and the major difference between GRUB and LILO is GRUB can recognize the file systems. GRUB can load the linux kernel from ext2 or ext3 file systems and this will be accomplished by making the normal 2 stage boot process in to 3 stage boot process.  Stage 1 (MBR) will load the stage 1.g boot loader which will understand the file system where the linux kernel belongs. For example reiserfs_stage1_5 (for loading Reiser journeling file systems) and e2fs_stage1_5 ( for loading ext2 and ext3 file systems) . In stage 2 GRUB will list the avilable kernel modules and as per the default configuration mentioned in /etc/grub.conf (soft links to /boot/grub/grub.conf) it will load the kernel image and default initrd image to the memory .

                                                                                                          GRUB boot loader
















                                                                                                 


                                                           /etc/grub.conf (/boot/grub/grub.conf)











1. default=0
As default first kernel entry will be get loaded in the system and if you have multiple kernel entries you have to change the default value according to that.
2.timeout=5
While system will boot it will wait 5mins for user selecting the kernel
3.SplashImage
It will load the image while you booting the OS. The default location of the image is mentioned in the line. ( you can change the back ground image to your own by following method
#convert image.png -resize 640x480 -colors 14 splash.xpm
#gzip splash.xpm)
4.hiddenmenu
This will hide the boot menu as default and you can see the boot menu once you press e in grub. ( if  you want to see the boot menu as default you can comment this option)
5.title
This will set the title for kernel lebel as "CentOS (2.6.18-128.el5)
6.root (hd0,0)
This indicates hard drive and partition details
7.kernel
This settings will load the kernel image and mount the root file system in /dev/VolGroup00/LogVol00 and kernel will execute /sbin/init with a process id of 1
8.initrd
Initrd has executable driver modules and it will load the RAM disk.

Kernel 


Kernel is the executable program with compressed stage ( size of 512 KB approximately ) . Kernel will be loaded in RAM disk for execution purpose . This execution will happen trough 3 stages.

a. Assembly routine - Initial stage system will invoke ./arch/i386/boot/head.s and function of this stage is to check basic hardware setup for kernel and it will invoke startup_32 function.

b.Startup_32 - This function will be called from ./arch/i386/boot/compressed/head.c and this function will set up basic environment (stack etc) for kernel booting.

c. decompress_kernel- This function will decompress the kernel and load to the memory and same will be loaded from ./arch/i386/boot/compressed/misc.c

Along with these three functions one more startup_32 function also will be called and this function will do the memory allocation by initializing page tables and enabling memory paging. Once the initrd function is enabled it will act as a RAM disk and allows the kernel to mount the /root file system temporarily also this will allows to detect the file real file systems and network to mount the original file systems for booting process.

Init process 

After the kernel boots init process (/sbin/init)will be started according to the configuration in /etc/inittab

Sample inittab file 


Also you can see this script will call the system initialization script called /etc/rc.d/rc.sysinit which have following functions 

  • run /sbin/initlog - To log the init process 
  • run devfs to manage and run devices 
  • run network scripts /etc/sysconfig/network
  • start graphical boot if configured (RHGB)
  • start console terminals,load keymap,systemfonts - /sbin/mingetty & /sbin/setsysfont
  • mount /proc for starting device controllers 
  • unmount initrd which was mounted in /root for inital booting procedure 
  • mount the /root as RW mode
  • Direct the kernel to load kernel parameters and modules - sysctl,depmod,modprobe
  • set up the clock - /etc/sysconfig/clock
  • perform disk operations as per /sbin/fsck configuration 
  • check mount quatos in non root file systems - fsck,mount,quotacheck,quotaon
  • initialize logical volume - vgscan,/etc/lvmtab
  • activate syslog , write to log files - dmesg 
  • configure sound - sndconfig
  • activate PAM module 
  • activate swapping - swapon 
system will boot as per the run level mentioned in the /etc/initab :initdefault 

Login Process 

The first process which includes in login process in /sbin/mingetty as per the configuration mentioned in  /etc/inittab file (1:2345:respawn:/sbin/mingetty tty1).These lines cause init to spawn mingetty process on run level 2 to 5 . To do this it will use the fork function to make a copy of itself and use the exec function to run the mingetty program .  Once the mingetty is loaded it will execute the login prompt and waits till user enter the user name.If the user enter the user name it will prompt the password and password will be cross checked along with /etc/passwd entry . If the credentials are correct respective shell is logged for the user as per the configuration in /etc/passwd .

I am mentioning the files which involve in login process and its respective roles 

/etc/nologin- This file prevents from user's who are not root from login to the system
/etc/usertty - User to impose special access restriction to user's
/etc/securetty- controls the terminals that the root user can login
.hushlogin - When this file exists in the user home directory , it will prevents the user to check the mail, view the last login and motd message.
/var/log/lastlog- contains the information about the last login details of the user.
/etcpasswd - contains the information about the user UID, password in encripted format and its respective shell details.













Tuesday, December 18, 2012

OSPF - A detailed review and configuration

          OSPF ( Open Shortest Path First) - A detailed review and configuration .


Open Shortest Path First is a routing protocol which is using in bigger networks (mainly ISP's & Telecom networks) in now a days . It is based on link state advertisements and currently OSPF V2 is running which is developed in 1991 as per RFC 1247. The major advantages of OSPF are
1. Classless protocol
2.Supports VLSM (Variable Length Subnet Mask)
3.Using Multicast address to advertise link updates (224.0.0.4 - SPF routers & 224.0.0.5-DR routers )
4. Supports Plain text and MD5 authentication Mechanism
5. Works as per Dijkstra algorithm.

OSPF packet details 

OSPF is using different types of packets for its communication, and the details are mentioned below 

OSPF Packet types
Type Description Functionality
1 Hello To discover neighbors and selects DR&BDR* routers to exchange capabilitis
2 Database Description To elect master/slave for router database exchange process to exchange the LSA headres
3 Link-State-Request To request specefic LSA (Link State Advertisements )
4 Link-State-Update To send entire to the neighbor who requested the particular LSA through the LSR packet
5 Link-State-Acknowledge To acknowledge and recept LSU packet
(* DR- Designated Router is the router an OSPF area where all other router's will send their Link State Advertisements.
BDR- Backup Designated Router - This will take the responsibility of the DR if the DR is failed in an area)

Sample OSPF Packet 

OSPF – Packet details
32 bit
version type packet length
router ID
area ID
        checksum                                    |                                        Autype
Authentication
Authentication


A sample OSPF packet is 32 bit length and its details are given below

Version - This mainly indicates what version of the OSPF is running. Currently OSPF V2 is running.

Type- Indicates the OSPF packet type ( details are given above)

Packet Length- Total length of the OSPF packet

Router ID- This indicates ip address of the router . For cisco router highest ip address will take as the router ID. If loop back ip is configured highest loop back will take as router ID

Area ID- This filed checks the area of the packet belongs to. This is a 4 byte number and both routers should have same area ID to form neighbor relation ship.

Check Sum - This part will check the status of the entire OSPF packet.

Autype- Autype filed will check the respective authentication type configured for OSPF.
different Autypes are
1. 0 indicates no authentication
2. 1 indicates plain text authentication
3. 2 indicates MD5 authentication

Authentication - Indicates the authentication key for plain text authentication type.

Sample OSPF configuration



          router 1 configuration








                                                               router 2 configuration


















                                                               router 3 configuration

















                                                               router 4 configuration

















                                               Testing the connectivity from work stations


                  PC1








                                                                          PC2









                                                                   OSPF Neighbor states 

1. Down 

This is the first stage of OSPF neighbor . If a neighbor is on down stage hello packet is not received from this particular neighbor, but packets can send to the neighbor .

2. Attempt

In this state router will send unicast hello packets to the neighbors in poll intervals . But as mentioned above these neighbors will not send hello packets in down state.

3. Init

Router will receive a valid hello packets from the neighbor, but receiving router id will not be added in the packets. 

4.  2-way

This state indicates the bi directional communication between two neighbor routers .The router's will share each others router ID in hello packets and as per that it will decide, need to become neighbor with this router or not. In OSPF network DR/BDR selection will happen as per the 2 way link with the neighbors.

5. Exstart

Once the DR/BDR selection is happened router's will start exchanging information by creating a virtual link inside the network (like a master/slave). Router's with higher router ID will became the master . 

6. Exchange

In this stage OSPF router's will exchange database descriptor (DBD) packets and this packet will contain LSA (Link State Advertisements) header's which will contain the details of entire LSA updates.
The contents of the DBD updates are cross checked with router LSA updates to make sure that information is passed to all neighbor's.

7.Loading

As per the DBD information and LSR (Link State Requests)router's will share the LSA , and this is the actual information share  happening stage.

8. Full

This is the fully synchronized state with all the router's database is updated with proper LSA updates. This is the normal state of a OSPF router.  If any of the router is not became full state , we can conclude that there will be an issue for forming adjacency  .

Multi Area OSPF configuration 

In larger networks we can find multiple area's in OSPF configuration than a single one . In multi area OSPF different kinds of router's are involved than single area OSPF

a. Internal router         - Router involves in a single area
b. Back born router   -   Router where atleast one onterface is in area 0
c. Area Border Router (ABR) - Router attached to multiple areas
d. Autonomous System Boundary Router - At least one interface connected to another AS.

Sample multi area OSPF network













configurations is almost same except loop back configuration in MOSPF.

OSPF treats Loopback interfaces as STUB NETWORKS and advertise them as HOST ROUTES (with mask /32) regardless of their configured/native mask.According to RFC 2328, Host routes are considered to be subnets whose mask is "all ones (0xffffffff)". In this state, the router's interface is looped back to the network in hardware or software. In this state, the interface is unavailable for regular data traffic. However, it is still available for testing like ICMP pings and BERT. For this reason, IP packets may still be addressed to an interface in Loopback state. Such interfaces are advertised in router-LSA as single host routes, whose destination IP address is the interface address.