Monday, December 23, 2013

Adding new service to chkconfig

Adding new script to managed by chkconfig

We had a request to put a job to start at run level 3 but when we copied the script to the /etc/init.d directory ( which is a link from /etc/rc.d/init.d/ ) but chkconfig did not recognize.
# chkconfig --add  mlabpadm  # returned
Service does not support chkconfig
The script looks,
[root@hostlnx init.d]# more mlabpadm
#!/bin/sh
case $1 in
   "start") /opt/matlab/etc/lmstart 2>/dev/null;;
   "stop") /opt/matlab/etc/lmdown 2>/dev/null;;
esac

To add this script to run automatically to run level 3, I can create S script on rc3.d but it should be managed by chkconfig.
To make it work, we have to supply the chkconfig values, like what run level you want to display and what priority you want to start/shutdown.

[root@hostlnx init.d]# more mlabpadm
#!/bin/sh
# chkconfig: 345 98 15
# description: This script will stop and starts the metlab
# processname: It starts the lm process
case $1 in
   "start") /opt/matlab/etc/lmstart 2>/dev/null;;
   "stop") /opt/matlab/etc/lmdown 2>/dev/null;;
esac



# chkconfig --list | grep mlabpadm
mlabpadm 0:off 1:off 2:off 3:off 4:off 5:off 6:off

# chkconfig --list mlabpadm
mlabpadm        0:off   1:off   2:off   3:on    4:on    5:on    6:off


To remove a service from chkconfig management
# chkconfig --del servicename


Source: http://linux.about.com/library/cmd/blcmdl8_chkconfig.htm
RUNLEVEL FILES
 Each service which should be manageable by chkconfig needs two or more commented lines added to its init.d script. The first line tells chkconfig what runlevels the service should be started in by default, as well as the start and stop priority levels. If the service should not, by default, be started in any runlevels, a - should be used in place of the runlevels list. The second line contains a description for the service, and may be extended across multiple lines with backslash continuation.

For example, random.init has these three lines:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
#              higher quality random number generation.
 This says that the random script should be started in levels 2, 3, 4, and 5, that its start priority should be 20, and that its stop priority should be 80. You should be able to figure out what the description says; the \ causes the line to be continued. The extra space in front of the line is ignored.

http://serverfault.com/questions/384556/whats-the-difference-between-chkconfig-on-vs-chkconfig-add

Wednesday, December 18, 2013

Set up LDAP client and autofs

 LDAP - Light Weight Directory Access Protocol

Package Name:  Directory Client and openldap-clients

a. It provides centralized authentication for user
b. It uses TCP/IP Port 389
c. Service it starts is: sssd

How to set up client
Note: Make sure to set up yum repo.

# yum groupinstall "Directory Client" -y
# yum install openldap-clients -y
# authconfig-gtk (GUI)
  ldap :// sama.expanor.local
  Certificate: http://sama.expanor.local/yum/CA/ca.crt
  Auth : LDAP Password
  Apply
# chkconf sssd on
# ldapsearch -x -ZZ        -    to search for LDAP users
# getent passwd ldapuser       - to get details of LDAP user
# su - ldapuser10            - Switch to LDAP user

Set up autofs

# yum install autofs -y
# vi /etc/auto.master
  Insert mode
  /lhome    /etc/auto.ldap       

Note: /lhome=predefined directory avilable in LDAP server

# vi /etc/auto.ldap
  ldapuser    -rw    host.domain.com:/lhome/ldapuser
        OR
  *        -rw   host.domain.com:/lhome/&          
Note: & at the end mean to share everything in /lhomedirectory

Restart the autofs
# service autofs stop
# service autofs start
# chkconf autofs on

LVM: how to know if a logical volume is striped, linear or mirrored


How do you find if a volume is linear , striped or mirrored?”
[root@centos ~]# lvs -a -o segtype,devices,lv_name,vg_name
Type Devices LV VG
linear /dev/sda2(0) rootvol rootvg
linear /dev/sda2(5825) swapvol rootvg
linear /dev/sdc1(128) alevol testvg
striped /dev/sdc1(0),/dev/sdb2(0) testvol testvg

Cron job and Crontab entry

Crontab.

- It is used for job Scheduling
- Service name - crond

To disable user using the crontab, add entry to /etc/cron.deny file.
# vi /etc/cron.deny
  username

# service crond restart

To test if user is denied, switch to that user
# su - user
$ crontab -e
 Error is displayed [Not allowed]


Run a job at cron. Schedule to run at 10 PM for user jay
Note: either become user jay or do as root.

$ crontab -e
or
# crontab -e -u jay
  [*=mm, *=hh, *=dd, *=mm, *=Week]
00 22 * * * /bin/echo "Hello World"  >>/var/tmp/mycron
01 22 * * * /bin/date  >>/var/tmp/mycron  
  :wq

Create a cron job that restarts the server at 11:58 PM

# crontab -e
  58 23 * * * /sbin/init 6
  :wq
# service crond restart (in case to verify)

Tuesday, December 10, 2013

Find active ip address on the networ..

 I thought nmap will give you all the active hosts on the network but it was not working. I tried it but finally found it that the host I was working was natted.. lol...


[devi@localhost ~]$ for i in `seq 0  256`
> do
> ping 192.168.10. $i
> done







[devi@localhost ~]$ for i in `seq 2 256`; do ping 192.168.10.$i ; done
PING 192.168.10.2 (192.168.10.2) 56(84) bytes of data.
64 bytes from 192.168.10.2: icmp_seq=1 ttl=128 time=7.40 ms
64 bytes from 192.168.10.2: icmp_seq=2 ttl=128 time=0.800 ms
64 bytes from 192.168.10.2: icmp_seq=3 ttl=128 time=0.903 ms






[devi@localhost ~]$ for i in `seq 1 256`
> do
> echo $i
> done
1
2
3
4



[root@localhost ~]# nmap
-bash: nmap: command not found
[root@localhost ~]# yum search nmap
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel-repository                        

[root@localhost ~]# yum install nmap
Loaded plugins: product-id,


Resolving Dependencies
--> Running transaction check
---> Package nmap.i686 2:5.51-2.el6 will be installed
--> Finished Dependency Resolution

[root@localhost ~]# more /etc/yum.repos.d/file.repo
##!/bin/bash
[rhel-repository]
name=rhel.myrepo
#baseurl=http://192.168.10.32/yum
baseurl=file:///opt/OS_Image
enabled=1
gpgcheck=0

[root@localhost ~]# nmap -sP 192.168.10.1/24

Starting Nmap 5.51 ( http://nmap.org ) at 2013-12-10 19:52 PST
Nmap scan report for 192.168.10.0
Host is up (0.013s latency).
Nmap scan report for 192.168.10.1
Host is up (0.0023s latency).
Nmap scan report for 192.168.10.2


[root@localhost ~]# arp -an
? (192.168.179.254) at 00:50:56:f8:39:53 [ether] on eth0
? (192.168.179.1) at 00:50:56:c0:00:08 [ether] on eth0
? (192.168.179.2) at 00:50:56:f9:55:21 [ether] on eth0
[root@localhost ~]#

Thursday, December 5, 2013

Checking the HBA card on the server if it is communicating with storage device.


Q. Following complain got from storage team.
HBA cards on the Hosts dcapplx202 is not logged in to the switch dc2sansw55. Looks like either cable or card has a problem.
The WWN of the HBA card that's not logged in is 10000000c99eab1c.

Solution,
Run the systool command and see if the link shows down. If it is down, go to datacenter if you can easily access or ask someone on remote site to check it for you.
Check the value of port_state, if you see port_state = "Linkdown" then cable might be loose or might not be connected correctly.

[root@dcapplx202 ~]# systool -c fc_host -v
Class = "fc_host"
  Class Device = "host3"
  Class Device path = "/sys/class/fc_host/host3"
    active_fc4s         = "0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x0                                                                                                                     0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0                                                                                                                     0 0x00 0x00 0x00 0x00 0x00 "
    fabric_name         = "0x0"
    issue_lip           = <store method only>
    maxframe_size       = "2048 bytes"
    node_name           = "0x20000000c99eab1c"
    port_id             = "0x019000"
    port_name           = "0x10000000c99eab1c"
    port_state          = "Linkdown"
    port_type           = "Unknown"
    speed               = "unknown"
    supported_classes   = "Class 3"
    supported_fc4s      = "0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x0                                                                                                                     0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0                                                                                                                     0 0x00 0x00 0x00 0x00 0x00 "
    supported_speeds    = "2 Gbit, 4 Gbit, 8 Gbit"
    tgtid_bind_type     = "wwpn (World Wide Port Name)"
    uevent              = <store method only>
    Device = "host3"
    Device path = "/sys/devices/pci0000:00/0000:00:04.0/0000:17:00.0/0000:18:02.                                                                                                                     0/0000:22:00.0/host3"
      uevent              = <store method only>

  Class Device = "host4"
  Class Device path = "/sys/class/fc_host/host4"
    active_fc4s         = "0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x0                                                                                                                     0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0                                                                                                                     0 0x00 0x00 0x00 0x00 0x00 "
    fabric_name         = "0x100000051eb60f80"
    issue_lip           = <store method only>
    maxframe_size       = "2048 bytes"
    node_name           = "0x20000000c99e1c96"
    port_id             = "0x019000"
    port_name           = "0x10000000c99e1c96"
    port_state          = "Online"
    port_type           = "NPort (fabric via point-to-point)"
    speed               = "8 Gbit"
    supported_classes   = "Class 3"
    supported_fc4s      = "0x00 0x00 0x01 0x00 0x00 0x00 0x00 0x01 0x00 0x00 0x0                                                                                                                     0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x0                                                                                                                     0 0x00 0x00 0x00 0x00 0x00 "
    supported_speeds    = "2 Gbit, 4 Gbit, 8 Gbit"
    tgtid_bind_type     = "wwpn (World Wide Port Name)"
    uevent              = <store method only>
    Device = "host4"
    Device path = "/sys/devices/pci0000:00/0000:00:04.0/0000:17:00.0/0000:18:01.                                                                                                                     0/0000:25:00.0/host4"
      uevent              = <store method only>

[root@dcapplx202 ~]#