Tuesday, January 8, 2013

OpenNebula setup


This will be the first of many blog posts to come outlining the process of setting up OpenNebula on a CentOS box and managing a small cluster of VMs.

First, a simple and good definition for OpenNebula:
…the open-source industry standard for data center virtualization, offering the most feature-rich, flexible solution for the comprehensive management of virtualized data centers to enable on-premise IaaS clouds
This diagram clearly shows the role of OpenNebula as far a Cloud infrastructure goes:
Even though the OpenNebula website is very complete and provides lots of good documentation and reference guides, a lot of that information is still out of context for me.
I haven’t dealt with cloud infrastructure before, so it is hard to put all these features and solutions that OpenNebula provides in context.
I guess once we have a small cloud set up it will start becoming clear the problems OpenNebula was designed to solved.
With all that being said lets get started!
I’ll be following the official tutorial posted on opennebula.org:
There are a few ways to install OpenNebula, they have prebuilt packages for a few Linux Distros and also provide the source code for whoever wants to build from source.
Later I plan to build from source, for now I’ll be installing from one of their pre-built packages
I selected the option:
OpenNebula 3.8.1 Download Source, RHEL/CentOS, Debian, openSUSE and Ubuntu Binary Packages Now!
Which took me to the another download page where I selected the distro I was interested in, my case CentOS.
The downloaded tar file came with three packages and the src code:
opennebula-3.8.1-1.x86_64.rpm
opennebula-java-3.8.1-1.x86_64.rpm
opennebula-sunstone-3.8.1-1.x86_64.rpm
src/
At first I tried to install the rpm packages by typing:
01[diogogmt@localhost opennebula-3.8.1]$ sudo rpm -Uvh opennebula-3.8.1-1.x86_64.rpm
02error: Failed dependencies:
03    libxmlrpc++.so.4()(64bit) is needed by opennebula-3.8.1-1.x86_64
04    libxmlrpc_client++.so.4()(64bit) is needed by opennebula-3.8.1-1.x86_64
05    libxmlrpc_server++.so.4()(64bit) is needed by opennebula-3.8.1-1.x86_64
06    libxmlrpc_server_abyss++.so.4()(64bit) is needed by opennebula-3.8.1-1.x86_64
07    rubygem-json is needed by opennebula-3.8.1-1.x86_64
08    rubygem-nokogiri is needed by opennebula-3.8.1-1.x86_64
09    rubygem-rack is needed by opennebula-3.8.1-1.x86_64
10    rubygem-sequel is needed by opennebula-3.8.1-1.x86_64
11    rubygem-sinatra is needed by opennebula-3.8.1-1.x86_64
12    rubygem-sqlite3-ruby is needed by opennebula-3.8.1-1.x86_64
13    rubygem-thin is needed by opennebula-3.8.1-1.x86_64
14    rubygem-uuidtools is needed by opennebula-3.8.1-1.x86_64
15    rubygems is needed by opennebula-3.8.1-1.x86_64
However it gave me an error saying the package needed some dependencies.
Instead of installing each dependency by hand, yum has a nice feature that installs all the dependencies automatically:
1[diogogmt@localhost opennebula-3.8.1]$ sudo yum localinstall opennebula-3.8.1-1.x86_64.rpm
After installing all the three packages the next step was to install the required ruby gems.
1sudo /usr/share/one/install_gems
installs_gems is nothing more than a ruby script.
A snippet of the script:
01DISTRIBUTIONS={
02    :debian => {
03        :id => ['Ubuntu''Debian'],
04        :dependencies => {
05            SQLITE      => ['gcc''libsqlite3-dev'],
06            'mysql'     => ['gcc''libmysqlclient-dev'],
07            'curb'      => ['gcc''libcurl4-openssl-dev'],
08            'nokogiri'  => %w{gcc rake libxml2-dev libxslt1-dev},
09            'xmlparser' => ['gcc''libexpat1-dev'],
10            'thin'      => ['g++'],
11            'json'      => ['make''gcc']
12        },
13        :install_command => 'apt-get install',
14        :gem_env    => {
15            'rake'      => '/usr/bin/rake'
16        }
17    },
18    :redhat => {
19        :id => ['CentOS', /^RedHat/],
20        :dependencies => {
21            SQLITE      => ['gcc''sqlite-devel'],
22            'mysql'     => ['gcc''mysql-devel'],
23            'curb'      => ['gcc''curl-devel'],
24            'nokogiri'  => %w{gcc rubygem-rake libxml2-devel libxslt-devel},
25            'xmlparser' => ['gcc''expat-devel'],
26            'thin'      => ['gcc-c++'],
27            'json'      => ['make''gcc']
28        },
29        :install_command => 'yum install'
30    },
31    :suse => {
32        :id => [/^SUSE/],
33        :dependencies => {
34            SQLITE      => ['gcc''sqlite3-devel'],
35            'mysql'     => ['gcc''libmysqlclient-devel'],
36            'curb'      => ['gcc''libcurl-devel'],
37            'nokogiri'  => %w{rubygem-rake gcc rubygem-rake libxml2-devel libxslt-devel},
38            'xmlparser' => ['gcc''libexpat-devel'],
39            'thin'      => ['rubygem-rake''gcc-c++'],
40            'json'      => ['make''gcc']
41        },
42        :install_command => 'zypper install'
43    }
44}
It checks which distro you are running and then install the correct packages for it.
When I tried to run the script I bumped into two problems:
1[diogogmt@localhost opennebula-3.8.1]$ sudo /usr/share/one/install_gems
2mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
3ruby development package is needed to install gems
4 
5[diogogmt@localhost opennebula-3.8.1]$ sudo /usr/share/one/install_gems
6/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31: command not found: lsb_release -a
7lsb_release command not found. If you are using a RedHat based
8distribution install redhat-lsb
To fix those problems I installed the following packages:
  • ruby-devel
  • redhat-lsb
This time running the install_gems script installed all the dependencies, without errors.
The next sections from the official OpenNebula tutorial explained how to configure the user oneadmin in the FronteEnd and Hosts.
They refer to FrontEnd when talking about the machine that has OpenNebula installed and Hosts for the machines belonging to the cloud setup.
An important point to mention is that OpenNebula only needs to be installed on the FronteEnd, all the hosts only need to a ssh server, hypervisors and ruby installed.
For the oneadmin user configuration I followed the steps listed on the tutorial but I didn’t have a chance to look deeper on what is actually happening.
I’ll go over that configuration steps again once I configure a host computer.
Since right now there are no other computers with hypervisors installed in the network it is hard to test if the oneamdin is properly configured.
The last part of the tutorial was to actually start OpenNebula and test if everything was installed:
*All the interaction of OpenNebula needs to be done via the oneadmin user
So before running the commands below I needed to switch the terminal session to the oneadmin user:
1su oneadmin
First set the credentials for oneadmin user
1mkdir ~/.one
2echo "oneadmin:password" > ~/.one/one_auth
3chmod 600 ~/.one/one_auth
To start opennebula:
1one start
However OpenNebula didn’t start, I got an error instead
1[oneadmin@localhost ~]$ one start
2Could not open database.
3oned failed to start
Well, it turns out that I couldn’t even start mysql, no wonder why OpenNebula wasn’t able to open the database
1[diogogmt@localhost opennebula-3.8.1]$ mysql
2ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Searching about the error above, I actually found out mysql wasn’t fully installed on my machine. I wasn’t able to start mysql as a service.
I thought that OpenNebula had installed mysql before, but I guess it didn’t, either way I just installed the mysql pakcages again:
1yum install mysql-server mysql mysql-client
Then configured mysql to start on boot
1chkconfig --levels 235 mysqld on

1service mysqld start
After running those commands I was able to start mysql.
I then tried one more time to start OpenNebula
1[oneadmin@localhost ~]$ one start
2Could not open database.
3oned failed to start
But again I got the same error.
I started looking online for possible solutions for the error I was getting but didn’t have any luck.
I remembered reading at beginning of the tutorial that all the logs for OpenNebula are saved.
They have a very good diagram explaining all the directories used by OpenNebula:
I took a look on the /var/log/one/one.d file
That provided some very good information:
1----------------------------------------
2     OpenNebula Configuration File
3----------------------------------------
4AUTH_MAD=AUTHN=ssh,x509,ldap,server_cipher,server_x509,EXECUTABLE=one_auth_mad
5DATASTORE_LOCATION=/var/lib/one//datastores
6DATASTORE_MAD=ARGUMENTS=-t 15 -d fs,vmware,vmfs,iscsi,lvm,EXECUTABLE=one_datastore
7DB=BACKEND=sqlite
The DB was set to sqlite.
I didn’t have sqlite installed, no wonder why the OpenNebula wasn’t being able to Open the DB
I went to the configuration file where all the settings for OpenNebula are defined:
1/etc/one/oned.conf
Indeed the DB was set to sqlite:
1DB = [ backend = "sqlite" ]
2# Sample configuration for MySQL
3# DB = [ backend = "mysql",
4#        server  = "localhost",
5#        port    = 0,
6#        user    = "oneadmin",
7#        passwd  = "oneadmin",
8#        db_name = "opennebula" ]
I uncommented the configuration for mysql and commented out the one for sqlite
The last thing left to do was to create the database and user for mysql:
mysql> CREATE DATABASE opennebula; mysql> GRANT ALL ON opennebula.* TO oneadmin@localhost IDENTIFIED BY 'oneadmin';
This time when I tried to run OpenNebula everything worked as expected!
1[oneadmin@localhost diogogmt]$ one start
2[oneadmin@localhost diogogmt]$ onevm list
3    ID USER     GROUP    NAME            STAT UCPU    UMEM HOST             TIME
Next step is to understand how the ssh configuration works for the Front-End and Hosts and try to set up a small cluster of Hypervisors and use OpenNebula to manage them.

No comments:

Post a Comment