opennebula and amazon ec2 integration table of contents · • before installing opennebula,...

12
OpenNebula and Amazon EC2 integration Table of Contents Hardware/software requirements :...................................................................................................2 Setup OpenNebula Host................................................................................................................... 2 Configure the OpenNebula host:................................................................................................. 2 Install OpenNebula in Ubuntu server :........................................................................................ 4 Prepare Amazon EC2 :......................................................................................................................7 Install EC2 API Library and tools in OpenNebula and configure OpenNebula ........................ 7 Create EC2 Host and VM in OpenNebula ................................................................................. 9 Connecting to your new EC2 instance :..................................................................................... 11 Terminate an EC2 instance through OpenNebula..................................................................... 11 ANIL KUMAR A N Chennai [email protected] [email protected] p l a c e f o r p r a c ti c a l g u id e s o n c l o u d c o m p u t i n g p l a c e f o r p r a c ti c a l g u id e s o n c l o u d c o m p u t i n g

Upload: others

Post on 10-Jul-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

OpenNebula and Amazon EC2 integration

Table of ContentsHardware/software requirements :...................................................................................................2Setup OpenNebula Host...................................................................................................................2

Configure the OpenNebula host:.................................................................................................2Install OpenNebula in Ubuntu server :........................................................................................4

Prepare Amazon EC2 :......................................................................................................................7 Install EC2 API Library and tools in OpenNebula and configure OpenNebula ........................7 Create EC2 Host and VM in OpenNebula .................................................................................9Connecting to your new EC2 instance :.....................................................................................11Terminate an EC2 instance through OpenNebula.....................................................................11

ANIL KUMAR A NChennai

[email protected] [email protected]

plac

e for

practical guides on cloud computingpl

ace f

or practical guides on cloud computing

Page 2: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

OpenNebula and Amazon EC2 integration

Hardware/software requirements :

A VT enabled hardware with Ubuntu 11.04 or 11.10 server installedHostname : OneHost IP address : 192.168.1.104Gateway : 192.168.1.1username : localadmin

Setup OpenNebula Host• Before installation of OpenNebula in Ubuntu Server , just check the following to ensure

that you have a proper setup.

/etc/network/interfaces # The loopback network interfaceauto loiface lo inet loopback

# The primary network interfaceauto eth0iface eth0 inet static address 192.168.1.104 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 # dns-* options are implemented by the resolvconf package, if installed dns-nameservers 192.168.1.1 dns-search example.com

/etc/hosts 127.0.0.1 localhost192.168.1.104 OneHost.example.com OneHost

/etc/resolv.conf search example.comnameserver 192.168.1.1

Configure the OpenNebula host:

• Create a folder "cloud" and create a group named "cloud"sudo mkdir -p /srv/cloud/

sudo groupadd -g 10000 cloud

plac

e for

practical guides on cloud computing

Page 3: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

• Create a user "oneadmin" , add user to group "cloud" and have /srv/cloud/one as home folder.

sudo useradd -u 10000 -m oneadmin -d /srv/cloud/one -s /bin/bash -g cloud

• Setup password for "oneadmin" and make oneadmin owner of "/srv/cloud"sudo passwd oneadmin - I chose “redhat123” as the password

sudo chown -R oneadmin:cloud /srv/cloud/

• Test by logging as user "oneadmin" and exitsu -l oneadmin

exit

• Install Network file Server [NFS] – Not a must for EC2 integrationsudo apt-get install nfs-kernel-server

• edit /etc/exports and add the following line to make folder /srv/cloud/one/var shareable with ESXi server. We will configure ESXi server later.

/srv/cloud/one/var 192.168.1.0/24(rw,sync,no_subtree_check,all_squash,anonuid=10000,anongid=10000)

• Restart NFS serversudo /etc/init.d/nfs-kernel-server start

• create a SSH key for oneadmin and disable host key checking else make all hostkeys known on the OpenNebula node.

su -l oneadmin

ssh-keygen • {Note - all defaults, and no passphrase.}

cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys

nano ~/.ssh/config• [add below two lines to SSH config file]

Host *StrictHostKeyChecking no

• exit

plac

e for

practical guides on cloud computing

Page 4: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

Install OpenNebula in Ubuntu server :

• Login to 192.168.1.98[OneHost] and download OpenNebula Release 3.2.1su -l oneadminDownload stable opennebula release for ubuntu [opennebula-3.2.1.tar.gz] from http://downloads.opennebula.org/ and save it in /srv/cloud/one folder.Also add oneadmin to sudoers file with permissions same as root,

• Un-tar the build tar xzf opennebula-3.2.1.tar.gzcd opennebula-3.2.1//

• Before installing OpenNebula, install all pre-requisite packagessudo apt-get install libsqlite3-dev libxmlrpc-c3-dev g++ ruby libopenssl-ruby libssl-dev ruby-devsudo apt-get install libxml2-dev libmysqlclient-dev libmysql++-dev libsqlite3-ruby libexpat1-devsudo apt-get install libc6 libgcc1 libmysqlclient16 libpassword-ruby libsequel-ruby libsqlite3-0 libssl0.9.8 libstdc++6 libxml2 libxmlrpc-c3-0 libxmlrpc-core-c3-0sudo apt-get install ruby rubygems libmysql-ruby libsqlite3-ruby libamazonec2-ruby sudo apt-get install rake rubygems libxml-parser-ruby1.8 libxslt1-dev genisoimage sconssudo gem install nokogiri rake xmlparsersudo apt-get install opennebula-common [optional]sudo apt-get install mysql-server [ set the password when asked. I normally give “mygreatsecret” as the pwd]

• configure MYSql: <refer below screen shot in case of any doubt)mysql -uroot -pmygreatsecretCREATE USER 'oneadmin'@'localhost' IDENTIFIED BY 'oneadmin';CREATE DATABASE opennebula;GRANT ALL PRIVILEGES ON opennebula.* TO 'oneadmin' IDENTIFIED BY 'oneadmin';quit;

• <Screen shot as shown below>

plac

e for

practical guides on cloud computing

Page 5: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

• Before installing OpenNebula, configure mysql support as oneadmin usercd ~/opennebula-3.2.1 [change your folder to opennebula source]scons sqlite=no mysql=yes

• Install openebula in /srv/cloud/one accessible by group cloud and as user "oneadmin"

./install.sh -u oneadmin -g cloud -d /srv/cloud/one

• Create a profile file[~/.bash_profile] to set ENVIRONMENT VARIABLES required to start and use services rendered by "one"

nano ~/.bash_profileexport ONE_LOCATION=/srv/cloud/oneexport ONE_AUTH=$ONE_LOCATION/.one/one_authexport ONE_XMLRPC=http://localhost:2633/RPC2export PATH=$ONE_LOCATION/bin:/usr/local/bin:/var/lib/gems/1.8/bin/:/var/lib/gems/1.8/:$PATH

• execute the profile file and set the environment variables source ~/.bash_profile

•• [Note: Anytime you open a new SSH window for OneHost, change user to “oneadmin” and

source ~/.bash_profile before issuing any “one” command]•

• Create and store OpenNebula user and password in a file. Substitute <THE_PASSWORD> with value

mkdir ~/.oneecho "oneadmin:<THE_PASSWORD>" > ~/.one/one_auth

• Make required changes in OpenNebula configuration file ~/etc/oned.confnano ~/etc/oned.conf

a. comment following line # Line 58 or near by [c hange if your password for oneadmin is some different]#DB = [ backend = "sqlite" ] b. Set SQL as MYSQL-uncomment #lines 61 through 66 or near by DB = [ backend = "mysql", server = "localhost", port = 0, user = "oneadmin", passwd = "oneadmin", db_name = "opennebula" ]

plac

e for

practical guides on cloud computing

Page 6: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

• Start OpenNebulaone start { Note: it should start with no error messages}

• Now You can test OpenNebula services by typing “onevm list” on the $ prompt. The command should execute with no error.The list will be empty for now.

plac

e for

practical guides on cloud computing

Page 7: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

Prepare Amazon EC2 :

• Create an Amazon accountGo to http://aws.amazon.com, and click Create an AWS Account.

Follow the on-screen instructions.

Part of the sign-up procedure involves receiving a phone call and entering a PIN using the phone keypad.

Refer: http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/SignUp.html

• Create credentials

• make a folder “ec2” with in /srv/cloud/one/ After signing up, you should end up at the EC2 console

• Create a key pair and download the private key ◦ Click Key Pairs under Networking and Security in the Navigation pane and then click the Create Key

Pair button ◦ (save it in e.g. ~/.ec2/ec2.pem). This private key is for making SSH connections to newly created

instances. • You will also need to set up your Amazon API credentials.

◦ Go to Account->Security Credentials ◦ click X.509 Certificates tab ◦ Create a new Certificate ◦ Download the private key and the certificate (save them in e.g. ~/.ec2/cert-

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem and ~/.ec2/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem).

◦ Never share these files .◦ Make your credential files private: chmod go-rwx ~/.ec2/*.pem 5.◦ Scroll to the bottom of the page and note your account ID (a number of the form XXXX-XXXX-

XXXX). ◦ Create a Ubuntu instance in EC2

[http://docs.amazonwebservices.com/AWSEC2/latest/GettingStartedGuide/LaunchInstance.html]◦ Note the AMI- ID ,as we need to specify it in onevm template later◦ Create an Elastic IP using NETWORK and SECURITY section and note the IP.

Install EC2 API Library and tools in OpenNebula and configure OpenNebula

• Install EC2 API tools in Openenbula frontend machine• Login to openNebula Front-end machine [onehost] as root user and perform the following steps

apt-get update• Install the Amazon EC2 Query API library:

gem install amazon-ec2• Install the Sinatra web framework and the thin web server:

[if you get Invalid gemspec in [/var/lib/gems/1.8/specifications/tilt-1.3.3.gemspec]: invalid date format in specification: "2011-08-25 00:00:00.000000000Z"

plac

e for

practical guides on cloud computing

Page 8: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

Type below on the command prompt as root user:sudo sed -i 's/ 00:00:00.000000000Z//' /var/lib/gems/1.8/specifications/*

]gem install sinatragem install thingem install uuidgem install curbapt-get install libsqlite3-ruby apt-get install libcurl4-gnutls-dev apt-get install openssl libruby1.8gem install sqlite3-rubyapt-get install openjdk-6-jdk

• The service is configured through the $ONE_LOCATION/etc/econe.conf file• Edit $ONE_LOCATION/etc/econe.conf and update the following

:SERVER=<IP of onehost/OpenNebula frontend>:PORT=4567

• Check if multiverse is enabled in Ubuntu 11:10 serversudo nano /etc/apt/sources.list

• if commented , uncomment the followingdeb http://in.archive.ubuntu.com/ubuntu/ oneiric multiversedeb-src http://in.archive.ubuntu.com/ubuntu/ oneiric multiversedeb http://in.archive.ubuntu.com/ubuntu/ oneiric-updates multiversedeb-src http://in.archive.ubuntu.com/ubuntu/ oneiric-updates multiverse

• Login as oneadmin user

• Make sure you have the following environment variables set up in your shell profile. This is accomplished by adding the following lines to your ~/.bash_profile :

sudo nano ~/.bash_profileexport EC2_KEYPAIR=<your keypair name> # name only, not the file nameexport EC2_URL=https://ec2.<your region>.amazonaws.com # example: ec2.us-east-1.amazonaws.comexport EC2_PRIVATE_KEY=<PATH>/<where your private key is>/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem # The value of the EC2_PRIVATE_KEY environment variableexport EC2_CERT=<PATH>/<where your certificate is>/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem # The X.509 certificate to use when constructing requests to Amazon EC2export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/

• Load the changes into the current shell environment: source ~/.bash_profile

• Check to see if it's working by running the following command:ec2-describe-images -o self -o amazon

• If above step fails due to "Client.AuthFailure" then ensure you have signed up for both AWS and ec2 with amazon.com, and have provided valid payment details.

• Also double check that the EC2_PRIVATE_KEY and EC2_CERT point to the correct

plac

e for

practical guides on cloud computing

Page 9: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

locations

• Create a AMI using a running/stopped EC2 instanceec2-create-image <instance id> --name <name for new instance> -K <EC2_PRIVATE_KEY> -C <EC2_CERT> -v -U <EC2_URL>example: I am using the already sourced environment values:ec2-create-image i-5ccd593b --name ubuntu1110x64 -K $EC2_PRIVATE_KEY -C $EC2_CERT -v -U $EC2_URL

• Edit File: /srv/cloud/one/etc/vmm_ec2/vmm_ec2rc and add below lines

nano /srv/cloud/one/etc/vmm_ec2/vmm_ec2rcEC2_HOME=/usr # find the installed location of ec2-api-tools and provide the path here. For me it is /usr {/bin will appended by the program itself }EC2_URL=https://ec2.us-east-1.amazonaws.comEC2_PRIVATE_KEY=<PATH>/<where your private key is>/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXX.pemEC2_CERT=<PATH>/<where your certificate is>/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pemJAVA_HOME=/usr/lib/jvm/java-6-openjdk/

• Edit File: /srv/cloud/one/etc/oned.conf and make the follwing changes# EC2 Information Driver Manager Configuration#-------------------------------------------------------------------------------IM_MAD = [ name = "im_ec2", executable = "one_im_ec2", arguments = "im_ec2/im_ec2.conf" ]#-------------------------------------------------------------------------------

VM_MAD = [name = "vmm_ec2",executable = "one_vmm_ec2",arguments = "-u https://ec2.us-east-1.amazonaws.com -k <PATH>/<where your private key is>/pk-XXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem -c <PATH>/<where your certificate is>/cert-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pem -h <path where ec2-api tools are installed> vmm_ec2/vmm_ec2.conf", type = "xml" ]

#-------------------------------------------------------------------------------# Dummy Transfer Manager Driver Configuration#-------------------------------------------------------------------------------

TM_MAD = [ name = "tm_dummy", executable = "one_tm", arguments = "tm_dummy/tm_dummy.conf" ]

#-------------------------------------------------------------------------------

Create EC2 Host and VM in OpenNebula

• Start one server as oneadmin user source ~/.bash_profileone start

• Add EC2 host to OpenNebula

plac

e for

practical guides on cloud computing

Page 10: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

onehost create ec2 im_ec2 vmm_ec2 tm_dummy dummy

• You will get an output likeID NAME RVM TCPU FCPU ACPU TMEM FMEM AMEM STAT 0 ec2 0 500 500 500 8.5G 8.5G 8.5G on

• Create a OpenNebula template file to launch an Instance in Amazon EC2nano ~/ec2.one

• Add the following content to ec2.one , save and exit#EC2 template to submit a VM to EC2

CPU = 0.5MEMORY = 128

EC2 = [ AMI="<ami id of ubuntu instance>", KEYPAIR="<Name of keypair>", ELASTICIP="<Generated Elastic IP>", AUTHORIZED_PORTS="22", INSTANCETYPE=m1.small]

#Add this if you want to use only EC2 cloud#REQUIREMENTS = 'NAME = "ec2"'

• Launch the Instance in Amazon EC2onevm create ec2.one

• Monitor the log files in ~/var/oned.log and ~/var/<vmid>/vm.logoned.log:Mon Apr 16 01:03:51 2012 [DiM][I]: New VM state is ACTIVE.Mon Apr 16 01:03:51 2012 [LCM][I]: New VM state is PROLOG.Mon Apr 16 01:03:51 2012 [VM][I]: Virtual Machine has no contextMon Apr 16 01:03:51 2012 [DiM][D]: Deploying VM 1Mon Apr 16 01:03:51 2012 [LCM][I]: New VM state is BOOTMon Apr 16 01:14:16 2012 [VMM][D]: Message received: LOG I 1 ExitCode: 0Mon Apr 16 01:14:10 2012 [VMM][I]: Monitoring VM 1.Mon Apr 16 01:14:16 2012 [VMM][D]: Message received: POLL SUCCESS 1 USEDMEMORY=0 USEDCPU=0 NETTX=0 NETRX=0 STATE=a IP=ec2-23-23-200-8.compute-1.amazonaws.com

vm.log:

Mon Apr 16 01:03:51 2012 [TM][D]: Message received: TRANSFER SUCCESS 1 -Mon Apr 16 01:04:04 2012 [VMM][D]: Message received: LOG I 1 ExitCode: 0Mon Apr 16 01:03:51 2012 [VMM][I]: Generating deployment file: /srv/cloud/one/var/1/deployment.0Mon Apr 16 01:04:04 2012 [VMM][D]: Message received: DEPLOY SUCCESS 1 i-5ab7263dMon Apr 16 01:03:58 2012 [VMM][I]: ExitCode: 0Mon Apr 16 01:04:04 2012 [VMM][I]: ExitCode: 0Mon Apr 16 01:04:04 2012 [LCM][I]: New VM state is RUNNINGMon Apr 16 01:14:16 2012 [VMM][W]: Adding custom monitoring attribute: IP ec2-23-23-200-8.compute-1.amazonaws.comMon Apr 16 01:14:16 2012 [VMM][D]: Monitor Information:

• Just note the monitoring attribute: IP {ec2-23-23-200-8.compute-1.amazonaws.com }from the log, [You can get it from EC2 console also]. We need it to SSH to the instance

plac

e for

practical guides on cloud computing

Page 11: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

• On successful creation you will get following output

onevm list

ID USER GROUP NAME STAT CPU MEM HOSTNAME TIME1 oneadmin oneadmin one-1 runn 0 0K ec2 00 00:02:21

• Login in AMAZON EC2 management console and check the status of the instance. It should be running in awhile

Connecting to your new EC2 instance :

• In order to log in to your instance, you will need to authorize network access to the ssh port for the default security group: {if you have created a different security group and already added SSH to it, just skip below step}

• ec2-authorize default -p 22

• You may then log in to the instance using ssh:

• ssh -i <private SSH key file> ubuntu@<external-host-name>

• example : ssh -i ~/.ec2/ec2.pem [email protected]

• The <private SSH key file> is the filename of the private SSH key that corresponds to the Amazon Key Pair that you specified in the ec2-run-instances command. The <external-host-name> can be found using the ec2-describe-instances command. An example SSH command:

• Once you have logged in, you may begin to set up and use the instance just like any other Ubuntu machine.

Terminate an EC2 instance through OpenNebula

onevm shutdown <vmid>

plac

e for

practical guides on cloud computing

Page 12: OpenNebula and Amazon EC2 integration Table of Contents · • Before installing OpenNebula, configure mysql support as oneadmin user cd ~/opennebula-3.2.1 [change your folder to

That's it. You have successfully launched an Amazon EC2 instance using OpenNebula

If you liked this tutorial , just post your comments to ANIL KUMAR A N

[email protected] [email protected]

plac

e for

practical guides on cloud computing