Oracle XE on Ubuntu using Vagrant and Puppet

Using this excellent Oracle Xe on Ubuntu Howto post on the OTN discussion forum i’ve created some configuration files to install Oracle XE on a clean ubuntu 11.10 box using Vagrant and Puppet. On my laptop this creates a new Ubuntu virtual machine running an Oracle XE database in 7 minutes.

I’ve created the following vagrant folder structure:

Vagrant oracle-xe folder structure

The rpm for Oracle XE can be manually downloaded from OTN: Oracle Database Express Edition 11g Release 2

The vagrant configuration file, Vagrantfile, looks like this:

Vagrant::Config.run do |config|

  config.vm.define :oraxe do | db1_config|
    db1_config.vm.box = "vagrant-oneiric-v3"
    db1_config.vm.host_name = "oraxe"
    db1_config.vm.forward_port 22, 41022, :adapter => 1
    db1_config.vm.network :hostonly, "33.33.33.10", :adapter => 2
    db1_config.vm.provision :puppet, :module_path => "modules", :options => "--verbose"  do |puppet|
      puppet.manifests_path = "manifests"
      puppet.manifest_file  = "site.pp"
    end
    db1_config.vm.customize [ "modifyvm", :id, "--name", "dev_env_oraxe" ,"--memory", "2048"]
    db1_config.vm.boot_mode = :gui
  end

end

The vagrant box that is used is a clean ubuntu 11.10 64bit server box.

The puppet site.pp configuration file:

node oraxe {
    include oracle::server
    include oracle::xe
}

The puppet module oracle has the following init.pp file:

class oracle::server {
  exec {  "/usr/bin/apt-get -y update":
    alias => "aptUpdate",
    timeout => 3600
  }
  package { 
    "ntp":
        ensure => installed;
    "htop":
        ensure => installed;
    "unzip":
        ensure => installed;
    "monit":
        ensure => installed;
    "rsyslog":
        ensure => installed;
    "curl":
        ensure => installed;
    "alien":
        ensure => installed;  
    "libaio1":
        ensure => installed;  
    "unixodbc":
        ensure => installed;  
  }
  service {
    "ntp":
        ensure => stopped;
    "monit":
        ensure => running;
/*      subscribe => File["/etc/monit/conf.d/monitrc"];*/
    "rsyslog":
        ensure => running;
    "procps":
        ensure => running;
  }
  exec { 
        "/usr/sbin/ntpdate ntp.ubuntu.com":
            alias => "ntpdate",
            require => Service["ntp"];
  }
    file { 
        "/etc/sysctl.d/60-oracle.conf" :
            source => "puppet:///modules/oracle/xe-sysctl.conf";
    }
    user { "syslog":
        ensure => present,
        groups => ["syslog","adm"];
    }
}

class oracle::xe{
    file {
        "/tmp/oracle-xe-11.2.0-1.0.x86_64.rpm.zip":,
            source => "puppet:///modules/oracle/oracle-xe-11.2.0-1.0.x86_64.rpm.zip";
        "/tmp/xe.rsp":
            source => "puppet:///modules/oracle/xe.rsp";
        "/etc/init.d/oracle-shm":
            mode => 0755,
            source => "puppet:///modules/oracle/oracle-shm";
    }
    exec { 
        "unzip xe":
            alias => "unzip xe",
            command => "/usr/bin/unzip -o /tmp/oracle-xe-11.2.0-1.0.x86_64.rpm.zip",
            require => File["/tmp/oracle-xe-11.2.0-1.0.x86_64.rpm.zip"],
            cwd => "/tmp",
            user => root,
            creates => "/tmp/oracle-xe-11.2.0-1.0.x86_64.rpm";
        "alien xe":
            command => "/usr/bin/alien --to-deb --scripts /tmp/Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm",
            cwd => "/tmp/Disk1",
            require => Exec["unzip xe"],
            creates => "/tmp/Disk1/oracle-xe_11.2.0-2_amd64.deb",
            user => root;
        "configure xe":
            command => "/etc/init.d/oracle-xe configure responseFile=/tmp/xe.rsp >> /tmp/xe-install.log",
            require => [Package["oracle-xe"],Exec["update-rc oracle-shm"]],
            user => root;
        "update-rc oracle-shm":
            command => "/usr/sbin/update-rc.d oracle-shm defaults 01 99",
            cwd => "/etc/init.d",
            require => File["/etc/init.d/oracle-shm"],
            user => root;
        "oracle-shm":
            command => "/etc/init.d/oracle-shm start",
            user => root,
            require => File["/etc/init.d/oracle-shm"];
    }
    package {
        "oracle-xe":
            provider => "dpkg",
            ensure => latest,
            require => Exec["alien xe"],
            source => "/tmp/Disk1/oracle-xe_11.2.0-2_amd64.deb";
    }
}

The Oracle-shm file is copied from the OTN message:

#! /bin/sh
# /etc/init.d/oracle-shm
#
#
case "$1" in
  start)
    echo "Starting script /etc/init.d/oracle-shm"
    # Run only once at system startup
    if [ -e /dev/shm/.oracle-shm ]; then
      echo "/dev/shm is already mounted, nothing to do"
    else
      rm -f /dev/shm
      mkdir /dev/shm
      mount -B /run/shm /dev/shm
      touch /dev/shm/.oracle-shm
    fi
    ;;
  stop)
    echo "Stopping script /etc/init.d/oracle-shm"
    echo "Nothing to do"
    ;;
  *)
    echo "Usage: /etc/init.d/oracle-shm {start|stop}"
    exit 1
    ;;
esac
#
### BEGIN INIT INFO
# Provides:          oracle-shm
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6 
# Short-Description: Bind /run/shm to /dev/shm at system startup.
# Description:       Fix to allow Oracle 11g use AMM.
### END INIT INFO

Kernel setting need to be set using a xe-sysctl.config file:

# Oracle 11g XE kernel parameters
fs.file-max=6815744
net.ipv4.ip_local_port_range=9000 65500
kernel.sem=250 32000 100 128
# kernel.shmmax=429496729
kernel.shmmax=107374183

And finally the configuration parameters for creating a new database xe.rsp:

ORACLE_LISTENER_PORT=1521
ORACLE_HTTP_PORT=8080
ORACLE_PASSWORD=manager
ORACLE_CONFIRM_PASSWORD=manager
ORACLE_DBENABLE=y

To create a clean ubuntu virtual machine with a new oracle xe installation all you need to do is:

vagrant up

Ready for use:

$ sqlplus system/manager@//33.33.33.10:1521/xe
SQL*Plus: Release 11.2.0.3.0 Production on Tue Feb 28 12:06:32 2012
Copyright (c) 1982, 2011, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
SQL> 
blog comments powered by Disqus