21
How to install a virtual machine martes 17 de agosto de 2010

Installation vm

  • Upload
    kiwimjg

  • View
    692

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Installation vm

How to install a virtual machine

martes 17 de agosto de 2010

Page 2: Installation vm

• Introduction

• Install JDK

• Install RPM packages

• How to create a virtual machine host

martes 17 de agosto de 2010

Page 3: Installation vm

• docs: http://en.wikipedia.org/wiki/Virtual_machine

• acces to root, need the key: su

• installation virtual machine yum install virt-manager

• installation libraries yum install kvm qemu libvirt python-virtinst

• To check if KVM has successfully been installed, run virsh -c qemu:///system list

• It should display something like this:

virsh -c qemu:///system list Id Name State ----------------------------------

Introduction

martes 17 de agosto de 2010

Page 4: Installation vm

Install JDK• Browse to http://download.java.net/jdk6/ and

select the relevant link. In this case .I wanted a .bin file for fedora 12 so I selected it under the Linux heading

• Got the url path (right-click select properties) and in the terminal I entered the command sudo wget <url path> This then download the .bin file to the directory I was in.

• I then changed the permissions on the file using chmod a+x to make it executable.

• I the ran the file and it installed to a java folder I had created in /usr/bin/.

• When I do an ls it shows me the JDK folder.

• I have to also set JAVA_HOME to point to the jdk so I look for the .batch_profile file and edit it. And add the entry export JAVA_HOME=/usr/java/jdk1.6.0_21. Save and then logout and then login.

• ensure that the path is correct by running echo $JAVA_HOME and it returns the correct location. Then launch JBoss without any errors!!!!

martes 17 de agosto de 2010

Page 5: Installation vm

Install RPM packages

• docs: http://en.wikipedia.org/wiki/Logical_Volume_Manager_%28Linux%29

• Installation de LVM in the Virtual machine like root sudo yum install system-config-lvm

• Restart the virtual machine, and connect again ( -X option is for see the window with the information about the partitions) reboot ssh test@tst01 -X

• When you have this, you can see the window with all the information about the LVM volumes, using this command sudo system-config-lvm

martes 17 de agosto de 2010

Page 6: Installation vm

How to create a virtual machine host

Prerequisites:

You need kvm up and running

If you don't want to run as root, the user you want to use needs to have rw access to /dev/kvm

If you want to be able to access the internet or a local network, your host system must be able to access the internet or the local network

• To install KVM and virtinst (a tool to create virtual machines), we run yum install kvm qemu libvirt python-virtinst qemu-kvm

• Then start the libvirt daemon: /etc/init.d/libvirtd start

• To check if KVM has successfully been installed, run virsh

• It should display something like this:

virsh # net-list --all

• If it displays an error instead, then something went wrong.

• Next we need to set up a network bridge on our server so that our virtual machines can be accessed from other hosts as if they were physical systems in the network.

• To do this, we install the package bridge-utils... yum install bridge-utils

• ... and configure a bridge.

martes 17 de agosto de 2010

Page 7: Installation vm

Starting to testVM, JBoss, Harmony, Apache

martes 17 de agosto de 2010

Page 8: Installation vm

• Introduction

• Expanding the disk capacity

• Creating the load balancer and the nodes

• Run JBoss with Harmony

martes 17 de agosto de 2010

Page 9: Installation vm

Introduction

• docs: software testing http://en.wikipedia.org/wiki/Software_testing

• We have a server, where we installation the S.O. In this case I install ubuntu. A when I have installed i do the following (my host machine called test02):

• To see the directory where I stay pwd

• Go inside like a root user sudo -i ls -al

• Go to the other server were I have the interface that I need use. And copy the files.

• ssh test@test02 • less /etc/network/interfaces • sudo -i • ls -al • ifconfig | less • shutdown sudo /etc/init.d/networking restart

martes 17 de agosto de 2010

Page 10: Installation vm

Expanding the disk capacity

• We have two hard Drives, when we have the files, we need put together and start the other hard drive.

• To see the disk on your computer root@test02:~# fdisk -l

Disk /dev/sda: 80.0 GB, 80000000000 bytes 255 heads, 63 sectors/track, 9726 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000080

Device Boot Start End Blocks Id System /dev/sda1 * 1 9695 77875056 8e Linux LVM /dev/sda2 9696 9726 249007+ 5 Extended /dev/sda5 9696 9726 248976 83 Linux

Disk /dev/sdb: 80.0 GB, 80000000000 bytes 255 heads, 63 sectors/track, 9726 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x00000080

Device Boot Start End Blocks Id System /dev/sdb1 1 9726 78124063+ 5 Extended /dev/sdb5 1 12 96327 83 Linux /dev/sdb6 13 559 4393746 82 Linux swap / Solaris /dev/sdb7 560 9726 73633896 83 Linux

You can verify this situation with the df -k command's output, which also shows that the other partitions are too full to accept any more data.

root@test02:~# df -k

Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/test02-root 73444600 1147652 68566108 2% / tmpfs 2032640 0 2032640 0% /lib/init/rw varrun 2032640 112 2032528 1% /var/run varlock 2032640 0 2032640 0% /var/lock udev 2032640 160 2032480 1% /dev tmpfs 2032640 0 2032640 0% /dev/shm lrm 2032640 2760 2029880 1% /lib/modules/2.6.28-11-server/volatile /dev/sda5 233335 14320 206567 7% /boot

martes 17 de agosto de 2010

Page 11: Installation vm

• Linux stores the names of all known disk partitions in the /proc/partitions file. The entire hard disk is represented by an entry with a minor number of 0, and all the partitions on the drive are sequentially numbered after that.

• •root@test02:~# cat /proc/partitions

major minor #blocks name

8 0 78125000 sda 8 1 77875056 sda1 8 2 1 sda2 8 5 248976 sda5 8 16 78125000 sdb 8 17 1 sdb1 8 21 96327 sdb5 8 22 4393746 sdb6 8 23 73633896 sdb7 252 0 74616832 dm-0 252 1 3211264 dm-1

The first Linux step in adding a new disk is to partition it in preparation of adding a filesystem to it. Type the fdisk command followed by the name of the disk. You want to run fdisk on the /dev/sdb disk, so the command is:

• root@test02:~# fdisk /dev/sdb

The number of cylinders for this disk is set to 9726.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

(e.g., DOS FDISK, OS/2 FDISK)

martes 17 de agosto de 2010

Page 12: Installation vm

• Just to make sure you're on the correct device, issue the p command to print all the known partitions on the disk. In this case, there are none which is good.

• Command (m for help): p

Command (m for help): p

Disk /dev/sdb: 80.0 GB, 80000000000 bytes

255 heads, 63 sectors/track, 9726 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Disk identifier: 0x00000080

Device Boot Start End Blocks Id System

/dev/sdb1 1 9726 78124063+ 5 Extended

/dev/sdb5 1 12 96327 83 Linux

/dev/sdb6 13 559 4393746 82 Linux

dev/sdb7 560 9726 73633896 83 Linux

The fdisk m command prints a small help manual of valid commands. You will see that n is the command to add a new partition. Add a new primary partition, number 1, and use the defaults to make the partition occupy the entire disk.

•Command (m for help): n Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) p Partition number (1-4): 1 Partition 1 is already defined. Delete it before re-adding it.

martes 17 de agosto de 2010

Page 13: Installation vm

• Run the print (p) command to confirm that you successfully created the partition partition.

•Command (m for help): p

• To save the changes. Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.

• You can take a look at the /proc/partitions file or use the fdisk -l command to see the changes to the disk partition structure of your system:

root@test02:~# cat /proc/partitions

• You now need to format the partition, giving it a new directory structure by using the mkfs command. The Fedora installation procedure defaults to an ext3 type, which is what you should use here.

root@test02:~# mkfs -t ext3 /dev/sdb1

•root@test02:/# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created •root@test02:/# vgextend test02 /dev/sdb1 Volume group "test02" successfully extended •root@test02:/# vgdisplay --- Volume group --- VG Name test02 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 148.77 GB PE Size 4.00 MB Total PE 38085 Alloc PE / Size 19001 / 74.22 GB Free PE / Size 19084 / 74.55 GB VG UUID 9nQQaX-dvOr-1xuf-KkFr-A5jz-Fg0h-

martes 17 de agosto de 2010

Page 14: Installation vm

• Create LVM volume for boot partition

• sudo lvcreate -L 1GM -n jboss_boot test02 (where test02 is your volume group name)

• Create LVM volume for root partition

• sudo lvcreate -L 11GM -n jboss_ctrl test02  (where test02 is your volume group name)

• Create Swap

• sudo lvcreate -L 1GM -n jboss_ctrl_swap test02  (where test02 is your volume group name)

• Mount vm-share

• sudo mount build:/nfs/vm-share /mnt/vm-share (maybe already mounted)

Creating the load balancer and the nodes

martes 17 de agosto de 2010

Page 15: Installation vm

• Copy boot system

• sudo dd if=/mnt/vm-share/images/fedora-12-dev/fedora-boot.img of=/dev/test02/jboss_boot

• Copy root system

• sudo dd if=/mnt/vm-share/images/jboss/jboss_ctrl_root.img of=/dev/test02/jboss_ctrl

• Copy the node xml file

• sudo cp /mnt/vm-share/images/jboss/jboss_ctrl.xml /etc/libvirt/qemu/jboss_ctrl.xml

• Edit jboss-ctrl.xml and change the name and update the drive locations to the lvm volumes

• Also change the network source to point at the new network create above ( in mnt/vm-share/images/jboss and in /etc/libvirt/qemu), change the name for the file too,and delete the uuid.(the machine generate another one new for each node.

• <domain type='kvm'> <name>jboss_ctrl</name> <uuid>8d695160-06e3-6af1-03b7-05d368c54aa8</uuid> <memory>10485764</memory> <currentMemory>1048576</currentMemory> <vcpu>2</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='disk'> <source file='/dev/test02/jboss_boot'/> <target dev='sda' bus='ide'/> </disk> <disk type='file' device='disk'> <source file='/dev/test02/jboss_root'/> <target dev='sdb' bus='ide'/> </disk> <disk type='file' device='disk'> <source file='/dev/test02/jboss_swap'/> <target dev='sdc' bus='ide'/> </disk> <disk type='block' device='cdrom'> <target dev='hdc' bus='ide'/> <readonly/> </disk> <interface type='network'> <source network='default'/> </interface> <serial type='pty'> <source path='/dev/pts/1'/> <target port='0'/> </serial> <console type='pty' tty='/dev/pts/1'> <source path='/dev/pts/1'/> <target port='0'/> </console> <input type='mouse' bus='ps2'/>

• <domain type='kvm'> <name>jboss_ctrl02</name> <uuid></uuid> <memory>10485764</memory> <currentMemory>1048576</currentMemory> <vcpu>2</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='disk'> <source file='/dev/test02/jboss_boot'/> <target dev='sda' bus='ide'/> </disk> <disk type='file' device='disk'> <source file='/dev/test02/jboss_ctrl'/> <target dev='sdb' bus='ide'/> </disk> <disk type='file' device='disk'> <source file='/dev/test02/jboss_ctrl_swap'/> <target dev='sdc' bus='ide'/> </disk> <disk type='block' device='cdrom'> <target dev='hdc' bus='ide'/> <readonly/> </disk> <interface type='network'> <source network='default'/> </interface> <serial type='pty'> <source path='/dev/pts/1'/> <target port='0'/> </serial> <console type='pty' tty='/dev/pts/1'> <source path='/dev/pts/1'/> <target port='0'/> </console> <input type='mouse' bus='ps2'/>

martes 17 de agosto de 2010

Page 16: Installation vm

• Define the VM, with the new name ( you should be change before)

• root@test02:/etc/libvirt/qemu# sudo virsh define jboss_ctrl02.xml

• Start the VM

• root@test02:/etc/libvirt/qemu# sudo virsh start jboss_ctrl02

• Get the IP address

• root@test02:~# sudo virsh console jboss_ctrl02

Connecting to uri: qemu:///system

Fedora release 12 (Constantine) Kernel 2.6.31.6-162.fc12.x86_64 on an x86_64 (/dev/ttyS0) jboss_ctrl login: Password: Last login: Thu Jun 17 13:38:23 on ttyS0

[test@jboss_ctrl ~]$ ifconfig

martes 17 de agosto de 2010

Page 17: Installation vm

• Creating the nodes

• Create new swap partition • test02@test02:/$ sudo lvcreate -L 1GM -n

jboss_swap1 test02  (where test02 is your volume group name)

• Create a snapshot of the jboss1's root partition • test02@test02:/$ sudo lvcreate -L592M -s -n

jboss_node11 /dev/test02/jboss_node1

• Use can use the current boot partition

• Copy the config file • root@test02:~# sudo cp /mnt/vm-share/

images/jboss/jboss_node1.xml /etc/libvirt/qemu/jboss_node2.xml

• Edit jboss_node1.xml and change it's name

<domain type='kvm'> <name>jboss_ctrl02</name> <uuid>8d695160-06e3-6af1-03b7-05d368c54aa8</uuid> <memory>10485764</memory> <currentMemory>1048576</currentMemory> <vcpu>2</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='disk'> <source file='/dev/test02/jboss_boot'/> <target dev='sda' bus='ide'/> </disk> <disk type='file' device='disk'> <source file='/dev/test02/jboss_ctrl'/> <target dev='sdb' bus='ide'/> </disk> <disk type='file' device='disk'> <source file='/dev/test02/jboss_ctrl_swap'/> <target dev='sdc' bus='ide'/> </disk> <disk type='block' device='cdrom'> <target dev='hdc' bus='ide'/> <readonly/> </disk> <interface type='network'> <mac address='52:54:00:83:04:87'/> <source network='default'/> </interface> <serial type='pty'> <source path='/dev/pts/1'/> <target port='0'/> </serial> <console type='pty' tty='/dev/pts/1'> <source path='/dev/pts/1'/> <target port='0'/> </console> <input type='mouse' bus='ps2'/>

<domain type='kvm'> <name>jboss_node1</name> <uuid></uuid> <memory>10485764</memory> <currentMemory>1048576</currentMemory> <vcpu>2</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> <boot dev='hd'/> </os> <features> <acpi/> <apic/> <pae/> </features> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <emulator>/usr/bin/kvm</emulator> <disk type='file' device='disk'> <source file='/dev/test02/jboss_boot'/> <target dev='sda' bus='ide'/> </disk> <disk type='file' device='disk'> <source file='/dev/test02/jboss_node11'/> <target dev='sdb' bus='ide'/> </disk> <disk type='file' device='disk'> <source file='/dev/test02/jboss_swap1'/> <target dev='sdc' bus='ide'/> </disk> <disk type='block' device='cdrom'> <target dev='hdc' bus='ide'/> <readonly/> </disk>

<interface type='network'> <mac address='52:54:00:83:04:87'/> <source network='default'/> </interface> <serial type='pty'> <source path='/dev/pts/1'/> <target port='0'/> </serial> <console type='pty' tty='/dev/pts/1'> <source path='/dev/pts/1'/> <target port='0'/> </console> <input type='mouse' bus='ps2'/>

martes 17 de agosto de 2010

Page 18: Installation vm

• Define the VM • root@test02:/etc/libvirt/qemu# sudo virsh define jboss_node1.xml

• Start the VM • root@test02:/etc/libvirt/qemu# virsh start jboss_node1

• TO go inside the node1 machine to install harmony• root@test02:~# sudo virsh console jboss_node1

• login with test/test

• Get the IP address • ifconfig and note the ip address

• Observations,• If you want copy in one of the nodes a image, you can use the same commands that we use for the load balancer, but

we need create the space for this image.

• For the nodes:

• sudo lvcreate -L 11GM -n jboss_node1 test02 • sudo dd if=/mnt/vm-share/images/jboss/jboss_node_rootv1.img of=/dev/test02/jboss_node1

martes 17 de agosto de 2010

Page 19: Installation vm

• http://en.wikipedia.org/wiki/JBoss_application_server

• http://www.jboss.org/

• Login as the node user

• Download harmony, in the directory /home/test/

• wget http://apache.mirrors.esat.net/harmony/milestones/5.0/M14/apache-harmony-5.0-jre- r946978-linux-x86_64-snapshot.tar.gz

• We can change the name of the file, is very large: mv apache................. harmony5

• Unzip

• tar -zxvf http://apache.mirrors.esat.net/harmony/milestones/5.0/M14/apache- harmony-5.0-jre-r946978-linux-x86_64-snapshot.tar.gz

• tar -zxvf harmony5

• Go to /home/test Jboss is listed here. Then edit the run.conf file in the bin and set JAVA_HOME =$ save and exit (make sure to remove # from JAVA)

• From the command line execute run.sh in the directory: jboss-4.2.3/bin

Run JBoss with Harmony

martes 17 de agosto de 2010

Page 20: Installation vm

• When we have Harmony and

JBoss running properly:

• Go to the directory /etc/httpd and edit workers.properties

[test@jboss_ctrl ~]$ cd /etc/httpd/ [test@jboss_ctrl httpd]$ ls conf conf.d logs modules run workers.properties [test@jboss_ctrl httpd]$ nano workers.properties

• Make the following changes in the file

# The load balancer is the main entry that goes into the child entries worker.list=loadbalancer # Node1 worker.jboss1.port=8009 worker.jboss1.host=192.168.122.184 worker.jboss1.type=ajp13 worker.jboss1.lbfactor=1 # Node2 worker.jboss2.port=8009 worker.jboss2.host=jboss2 worker.jboss2.type=ajp3 worker.jboss2.lbfactor=1 # Load balancing behaviour worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=jboss1

# set sticky to zero so that we are able to test alternation worker.loadbalancer.sticky_session=0

# The load balancer is the main entry that goes into the child entries worker.list=loadbalancer # Node1 worker.jboss1.port=8009 worker.jboss1.host=192.168.122.104 worker.jboss1.type=ajp13 worker.jboss1.lbfactor=1 # Node2 worker.jboss2.port=8009 worker.jboss2.host= 192.168.122.114 worker.jboss2.type=ajp13 worker.jboss2.lbfactor=1

# Node3 worker.jboss3.port=8009 worker.jboss3.host= 192.168.122.72 worker.jboss3.type=ajp13 worker.jboss3.lbfactor=1 # Load balancing behaviour worker.loadbalancer.type=lb worker.loadbalancer.balance_workers=jboss1 worker.loadbalancer.balance_workers=jboss2 worker.loadbalancer.balance_workers=jboss3 # set sticky to zero so that we are able to test alternation worker.loadbalancer.sticky_session=0

martes 17 de agosto de 2010

Page 21: Installation vm

• Now you need copy the file testservlet.war from the local machine to host machine

• [workstation09@workstation09 Desktop]$ scp testservlet.war [email protected]:

• The authenticity of host '10.2.0.62 (10.2.0.62)' can't be established. RSA key fingerprint is e9:d2:89:ae:7c:ab:cd:c6:d4:df:3b:ed:42:ab:21:1c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.2.0.62' (RSA) to the list of known hosts. [email protected]'s password: testservlet.war

• Then from the load balancing machine to each node. We should be change the ip for each node.

• [test@jboss_ctrl ~]$ scp testservlet.war [email protected]:jboss-4.2.3.GA/server/all/deploy

• To see if the file is inside, go to the console for the node and use to swich off the firewall, make in a off state permanently sudo /etc/init.d/iptables stop

• To check the configuration of the firewall: sudo /etc/init.d/iptables status

• Go to the hosts file sudo vim /etc/hosts

• Insert this line in the file 127.0.0.1 localhost.localdomain localhost test02 jboss_ctrl

• Restart the Apache service sudo /etc/init.d/httpd restart

• Running jboss in cluster mode on node ./run.sh -c all -b ip adress of node ./run.sh -c all -b 192.168.122.104

martes 17 de agosto de 2010