Installing new versions of Java on RHEL

RHEL includes the alternatives command providing the ability to point your users to different versions of software while not changing their links to the command.  For example if you wanted a specific version of JAVA this can be done with PATH changes or alternatives

man alternatives

for exact info.

For Java

/usr/sbin/alternatives --install /usr/bin/java java /location_to_new_java

/usr/sbin/alternatives --config java

Repeat for javac

Finally, set the environment for everyone on the machine by creating a java.sh script in /etc/profile.d:

#!/bin/sh
export JAVA_HOME=/usr/java/jdk
export JRE_HOME=$JAVA_HOME/jre
export J2RE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$J2RE_HOME/bin:$PATH

Find HBA WWID in RHEL

Finding information about your fibre channel cards in RHEL is pretty easy with qlogic cards look at:

cat  /sys/class/fc_host/host*/

files in here provide a log of info WWID’s are stored in:


cat  /sys/class/fc_host/host*/port_name

Vmware ESX change service console memory

So everytime you setup ESX you need to max out your service console memory to 800MB’s this can be done two ways.. the service console or gui both require that you reboot the node after making the change.

Via Service console:

Log in via root and type

  1. vmkpcidivy -i
  2. Press enter when prompted for the boot image
  3. Press enter when prompted for the name of the configuration
  4. Type 800mb when asked about memory
  5. Press enter to accept defaults until you exit
  6. Reboot node

Via gui

  1. Goto Inventory
  2. Configuration
  3. Memory
  4. Enter 800mb
  5. reboot node

Backup and restore your mbr (master boot record)

In Linux making block level copies of area’s is easy with the magical dd utility.   So to backup the mbr (first 512 bytes)  use this command (assuming your boot drive is hda)

dd if=/dev/hda of=/root/mbr_backup bs=512 count=1

Now in /root/mbr_backup you have a complete copy of your mbr.   BS means byte size and count means only (once) first 512.

To delete the mbr (not the partition table):

dd if=/dev/zero of=/dev/hda bs=446 count=1

To delete the mbr and partition:

dd if=/dev/zero of=/dev/hda bs=512 count=1

Restore the mbr:

dd if=/root/mbr_backup of=/dev/hda bs=512 count=1


	

Locked file how to find

Well I run into this issue a lot.  I cannot unmount a partition.. or I cannot open a file because it’s locked and in use.  How do I see what has that file or mount locked?  Well since everything in Linux is a file you can list open files … which will show you what processes have certain files locked this is done with the lsof command.

For example on my Mythbox I want to see what has the /storage partition locked I would issue:

[root@linuxmonkey2 ~]# lsof | grep storage
mysqld     2285      mysql   13u      REG      253,0        124     325498 /var/lib/mysql/mythconverg/storagegroup.MYD
mysqld     2285      mysql   57u      REG      253,0       5120     325424 /var/lib/mysql/mythconverg/storagegroup.MYI
gnome-key  2887     mythtv  mem       REG      253,0      40808     502127 /usr/lib/libhal-storage.so.1.0.0
mythbacke  7126       root   18w      REG      253,2 1492874876    1523719 /storage/recordings/1007_20100421150000.mpg

From that you can see mysql, gnome-key and mythbackend all have open files inside storage I would have to kill them before unmounting.

Get LUN WWID on RHEL

Getting the LUN WWID on RHEL is critical when dealing with multiple different Storage systems.  You can use the scsi_id command to find a WWID

scsi_id -g -u -s /block/sdd

Will return the WWID of the devices.  In addition if you install device-mapper-multipath you can use the lssci tool to output all lun’s and what storage system they belong to.

How to Mount a logical volume

I have finally converted to logical volumes which leaves me learning a whole new world.  I was moving some data (500GB’s) between machines using a USB drive and found that the logical volume on the drive would not quickly mount via traditional mount /dev/sd… command.  So here is the process to mount a LVM.

1. Scan for the new volume (Assuming you added it after boot)

vgscan

2. Activate the volume

vgchange -a y VolumeName

3. Display the volume and confirm it’s active

lvdisplay

4. Mount the volume via it’s volume name

mount /dev/mapper/VolumeName /destination_mount_point

Postfix Hide hostnames and subdomains from your relay

So your setting up a mail relay or mail agent and your want to strip off the hostname or subdomain before the message gets to the internet:  for example your relay gets it as root@max.blog.jgriffiths.org but you want it to look like root@jgriffiths.org  well this is really simple with postfix.   Just load up your main.cf and add the following line

masquerade_domains = jgriffiths.org

This will strip off everything after jgriffiths.org.  You can add additional domain by placing spaces between hosts.

Block outgoing smtp except to an approved relay in iptables

Just like most sysadmins I have to deal with developers who want to zip off a quick email after their application finishes processing, sounds good right?  Yes it is… but the internet is not a happy place and spam is around every corner.  I avoid getting tagged as spam your systems email should really be sent via an internal relay.  The internal relay should be registered with an MX entry in DNS to get the clear from all SPAM applicances and filtering.   As such I want to use iptables to stop outgoing smtp requests unless they go to my central relay (123.123.123.123)

-A OUTPUT -p tcp -d 123.123.123.123 --dport 25 -m state --state NEW -j ACCEPT

-A OUTPUT -p tcp –dport 25 -m state —state NEW -j DROP

Works great… if you use a local mail programs you might want to add this line first

-A OUTPUT -p tcp -d 127.0.0.1 –dport 25 -m state –state NEW -j ACCEPT