30 Minute Deploy Session 1: CentOS 6.5 VM Template

By | March 11, 2014

centos

What It Is:

The Community Enterprise Operating System (CentOS) is a freely available Linux distribution that is fully binary compliant with the approximate version of Red Hat Enterprise Linux. This means that it is basically the same as RHEL, although there is no formal support.

The fact that it is fully binary compliant makes it the perfect platform to test the many Open Source enterprise applications that are extremely popular in the “devops” space. Also, skills learned using CentOS will be directly transferable to a Red Hat based environment.

Why Do It:

The 15 Minute Deploy series here at vByron.com is designed to give any sysadmin the basic knowledge to create a functional lab on which to learn both emerging and established Open Source applications that are rapidly changing the business of the data center.

You won’t find hype or buzzwords (other than devops, but I like that one). What you will find in well documented, streamlined tutorials made to get you up and running fast with a base knowledge and links to further reading.

In the spirit of speed 15MD-001 will be the base for all future installs. At the end of this tutorial you will have a template that you can rapidly deploy so you can get right to the apps.

How To Do It:

Create The Virtual Machine

1. Download CentOS-6.5-x86_64-bin-DVD1.iso a CentOS mirror.

2. Log into the vSphere Web Client

3. Navigate to Storage.

4. Click “Upload a file to the Datastore”.

001-Upload
5. Select the CentOS ISO image.

centos-image
6. Navigate to Virtual Machines

7. Right-click the Data Center and select “New Virtual Machine…” from the context menu.

001-new-vm

8. Leave the default “Create a new virtual machine” selected. Click Next.

001-NewVM1

9. Name the VM and select the folder to place it in. Click Next.

001-NewVM2

10. Select the compute resource. Click Next.

001-NewVM3

11. Select the Datastore. Click Next.

001-NewVM4

12. Select the compatibility level. This is the virtual hardware version (ESX 5.5 is version 10). Click Next.

001-NewVM5

13. Select “Linux” for the Guest OS Family. Select “Red Hat Enterprise Linux 6 (64-bit)” for the Guest OS Version. Click Next.

001-NewVM6

14. Change New CD/DVD Drive to “Datastore ISO File” Select the CentOS ISO that you uploaded and click OK.

001-NewVM7

15. Click “Connect At Power On”. Click Next.

001-NewVM8

16. Confirm the Settings. Click Finish.

001-NewVM9

17. Wait for the Virtual Machine to be provisioned.

Install CentOS

1. Navigate to the newly created VM. Click the “Actions” drop down menu. Click on “Power On”.

001-NewVM10

2. In the same menu select “Open Console”.

3. By the time the console opens you should see the media test screen below. If not just wait a few seconds. Since we are using an ISO file there is no need to test to click “Skip”.

001-NewVM11

4. This next screen is the Welcome splash screen. Nothing to do. Click Next.

001-NewVM12

5. Select the Language for the Install. Click Next.

001-NewVM14

6. Select the Keyboard type. Click Next.

001-NewVM13

7. Keep the default “Basic Storage Device”. Click Next.

001-NewVM15

8. Click “Yes Discard My Data”.

001-NewVM16

9. Because this is going to be a template leave the hostname as “localhost.localdomain”. Click “Configure Network”.

001-NewVM17

10. Select “System eth0” and click Edit.

001-NewVM18

11. Click “Connect Automatically”. Click the IPv4 tab.

001-NewVM19

12. Configure the IP Settings as needed. Click Apply.

001-NewVM20

13. Click Close. Click Next.

14. Select the timezone. Click Next.

001-NewVM21

15. Set and Confirm the Root Password. Click Next.

001-NewVM22

16. Select Use All Space. Click Next.

001-NewVM23

17. Click “Write Changes to Disk”.

001-NewVM24

18. Wait while the disk is created and formatted.

19. Select the “Basic Server” package. Click Next.

001-NewVM26

20. Wait for the Install to complete.

001-NewVM27

21. Click Reboot to Finish the Installation.

001-NewVM28

Configuring the CentOS Template

1. Wait for the Virtual Machine to reboot then close the console.

2. Download and run PuTTY. PuTTY is a lightweight terminal client used to connect to hosts with the SSH Protocol.

001-NewVM29

3. Click “Yes” to accept the unknown host key.

001-NewVM30

4. Login as root.

001-NewVM31

5. Update the with the following command:

Note: The Virtual Machine will need internet access and name resolution.

yum update --skip-broken

001-NewVM32

6. Type “y” and “enter”.

001-NewVM33

7. Type “y” and “enter”.

001-NewVM34

8. The update is now complete.

001-NewVM35

9. Install git. We will need this in the future.

yum install git

001-NewVM36

10. Open the vSphere Web Client and navigate to the Virtual Machine that is being configured. On the Summary Screen click “Install VMware Tools”. Click “Mount” on the pop-up window.

001-NewVM37

11. Return to PuTTY.

12. Mount the VMware Tools ISO, copy the archive to HOME and extract the archive:

mount -t iso9660 /dev/dvd /mnt
cp /mnt/VMwareTools-9.4.0-1280544.tar.gz ~
tar -zxf VMwareTools-9.4.0-1280544.tar.gz

001-NewVM38

13. Unmount ISO and delete the archive:

umount /mnt
rm VMwareTools-9.4.0-1280544.tar.gz

001-NewVM39

14. Change Directory to vmware-tools-distrib/. Execute ./vmware-install.pl. When prompted press “enter” to accept all defaults.

cd ~/vmware-tools-distrib/
/vmware-install.pl

001-NewVM40

15. Create the initial firewall ruleset. This script will change the default to ACCEPT. This will make testing new apps much easier However it should not be used in production.

git clone https://github.com/byronschaller/deploy-devops.git
cd deploy-devops/
chmod +x firewall.sh
./firewall.sh

001-NewVM41

16. Open the /etc/udev/rules.d/70-persistent-net.rules for editing, add a “#” to the begining of every line.

nano /etc/udev/rules.d/70-persistent-net.rules

001-NewVM52

17. Save the file by typing “Control” and “o” together. Type “Enter” to verify the save.

18. Exit the program by typing “Control” and “x” together

19. Make the file read only.

chattr +i /etc/udev/rules.d/70-persistent-net.rules

001-NewVM53

20. Shutdown the virtual machine with the command:

shutdown -P now

21. The template preparation is now complete.

Create The Template

1. Open the vSphere Web Client and navigate to the CentOS Virtual Machine.

2. Right Click the Machine and select All vCenter Actions > Convert to Template.

001-NewVM44

Deploying a Virtual Machine from the Template

1. Right-click the template and choose “Deploy VM from this Template” from the context menu.

001-NewVM45

2. Name it and choose a folder. Click Next.

001-NewVM46

3. Select the Cluster for the Compute Resource. Click Next.

001-NewVM47

4. Select the Datastore. Click Next.

001-NewVM48

5. Select all three Check Boxes. Click Next
001-NewVM54

6. Click “New Guest Customization Spec”. Name it. Click Next.

001-NewVM55

7. Enter a Hostname and a Domain Name. Click Next.

001-NewVM56

8. Set the timezone. Click Next.

001-NewVM57

9. Select NIC1 and click the Edit (pencil) icon.

001-NewVM58

10. Manually assign the new IP address. Click OK. Click Next.

001-NewVM59

11. Enter the Domain and DNS Settings. Click Finish.

001-NewVM60

12. Select the newly created Spec. Click Next.

001-NewVM61

13. Delete the existing Network Adapter and create a new one. Click Next.

001-NewVM62

14. Review and Click Finish.

001-NewVM51

15. Wait for the new Machine to Deploy then Open the Console.

16. Login and verify your hostname and IP setting with the command ifconfig

17. Congratulations the new machine has been deployed!

  • bookmark54

    Byron – I am using VMWare Player to install the .iso. I can’t see the “Back” and “Next ” buttons. I have to guess by using tabs – frustrating. How do I enlarge the VMWare Player install screen so I can see the entire CentOS splash screen for the install?

  • zetret

    I want to clone a VMware VM (RHEL6.5), export it as an OVF and when
    someone deploys it again, I want them to enter custom information like
    IP, DNS, VM name in the vSphere Deploy wizard. How do I make this
    happen? (I’ve deleted the persistent net rules file) When I exported
    this template (created as you said) as OVF and tried to deploy from it,
    the customization wizard does not come up !

  • Brandt Tullis

    Thanks for the great write-up. I altered one detail. I removed the network adapter from the VM before powering it on. I followed your guide except for altering the file in /etc/rules.d, and I didn’t install updates. Then, I powered off the VM, added a network adapter, and converted it to a template. This way, my VMs deployed from this template will have eth0 as their ethernet adapter.

    Altering the file in /etc/rules.d wasn’t achieving the desired results.