21 September 2014

Create Redhat Enterprise Linux Template VM in VMware vCenter

You can create a RHEL template VM in your VMware ESXi environment in order to make new VM deployment easier and faster.

You fisrt need to create a normal VM and install your RHEL inside it. You can also install other applications that you may need to have them in all your new VM employments.

After You are done with your installation and configuration of the VM that suppose to be used as Template, we need to carry following task inside guest OS before proceed to convert it to a VMware Template.

1. Flag the system for reconfiguration:

# touch /.unconfigured 

2. Deactivate all the network cards of your VM: 

example for eth0:

# ifdown eth0

Remove the HWADDR entry from the ifcfg-eth* files:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0


and activate you network cards again:

# ifup eth0

3. You need to delete entries regarding the network cards from 70-persistent-net.rules file as well:

# vi /etc/udev/rules.d/70-persistent-net.rules

# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:b7:3b:f7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

Remove the lines started with SUBSYSTEM, save and exit the file. 

4. Delete any SSH host keys:

# rm -rf /etc/ssh/ssh_host_*

And that's it, just remember to Shutdown or power off your VM immediately before you change any settings. It is now ready to be converted to a Template. 

Note: If you happen to reboot your system, you need to repeat the step 3 and power off your VM, 

Now, from the vCenter, right click on your VM and go to Template > Convert to Template.

Once it's ready, you can right click on your newly created Template and choose Deploy Virtual Machine from This Template. Follow on screen dialogues, give hostname and choose the location for your new VM. 

And there you go, you have your  new VM created without hassle of installing and configuring OS and applications each time you want a new server. 

9 September 2014

Change a Linux hostname boot persistent

Q: How to change your linux box hostname after you have installed your OS:

A: You can change your hostname temporarily by hostname command.

Getting current hostname:
# hostname

Change it to desired name:
# hostname test2

# hostname

But if it is not boot persistant and after reboot it goes back to previous hostname. To make it boot persistent we need to change it in the network config file: 

# vi /etc/sysconfig/network


And after reboot we have the new hostname permanently.