ubuntu cloud image _ more mind spew-age from harold spencer jr

Upload: sahad-sali

Post on 04-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Ubuntu Cloud Image _ More Mind Spew-Age From Harold Spencer Jr

    1/6

    11/1/13 ubuntu cloud image | More Mind Spew-age from Harold Spencer Jr.

    blogs.mindspew-age.com/tag/ubuntu-cloud-image/

    More Mind Spew-age from Harold Spencer Jr.

    Random Information sometimes techie, sometimes

    not..

    Tag Archives: ubuntu cloud image

    Another Great Example of AWS Fidelity Neo4j,

    Cloud-Init and Eucalyptus

    Posted by hspencer77 on December 4, 2012

    I recently ran across a blog entry entitled Neo4j 1.9.M01 Self-managed HA(http://http://blog.neo4j.org/2012/10/neo4j-19m01-self-managed-ha.html). I found the concept ofgraph databases storing data (http://www.neo4j.org/learn/graphdatabase) really interesting andreached out to the guys at Neo4j (http://www.neo4j.org/) to get some insight on how to deploy theirHA solution on Eucalyptus. Amongst the resources that they provided, they shared this little gem how to deploy Neo4j on EC2 (http://www.neo4j.org/develop/ec2). In order to run first, you need toknow how to walk so before going down the path of standing up HA Neo4j, I decided to beinfluenced by the DIY on EC2 article provided by Neo4j and deploy Neo4j on Eucalyptus - with a litthelpfrom Cloud-Init (https://help.ubuntu.com/community/CloudInit). The follow-up blog will show

    howto use the same setup, and deploy an HA Neo4j environment.

    The Setup

    Eucalyptus

    http://www.neo4j.org/learn/graphdatabasehttp://blogs.mindspew-age.com/2012/12/04/another-great-example-of-aws-fidelity-neo4j-cloud-init-and-eucalyptus/http://blogs.mindspew-age.com/http://blogs.mindspew-age.com/https://help.ubuntu.com/community/CloudInithttp://www.neo4j.org/develop/ec2http://www.neo4j.org/http://www.neo4j.org/learn/graphdatabasehttp://http//blog.neo4j.org/2012/10/neo4j-19m01-self-managed-ha.htmlhttp://blogs.mindspew-age.com/2012/12/04/another-great-example-of-aws-fidelity-neo4j-cloud-init-and-eucalyptus/http://blogs.mindspew-age.com/author/hspencer77/http://blogs.mindspew-age.com/2012/12/04/another-great-example-of-aws-fidelity-neo4j-cloud-init-and-eucalyptus/http://blogs.mindspew-age.com/
  • 8/14/2019 Ubuntu Cloud Image _ More Mind Spew-Age From Harold Spencer Jr

    2/6

    11/1/13 ubuntu cloud image | More Mind Spew-age from Harold Spencer Jr.

    blogs.mindspew-age.com/tag/ubuntu-cloud-image/

    The Eucalyptus cloud I used is configured using Eucalyptus High-Availability(http://www.eucalyptus.com/docs/3.1/ig/planning_ha.html#planning_ha). Its running on CentOS 6.3running KVM. Its also running in Managed networking mode(http://www.eucalyptus.com/docs/3.1/ig/nw_managed.html#nw_managed), so that we can takeadvantage of network isolation of the VMs, and the use of security groups - interacting very much in

    the same way as its done in the security groups provided in AWS EC2(http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-network-security.html).

    Ubuntu Cloud Image 12.04 LTS Precise Pangolin

    The image that we will use is the Ubuntu 12.04 LTS Cloud image (http://cloud-images.ubuntu.com/precise/current/). The reasons for using this image is as follows:

    Ubuntu cloud images (http://cloud-images.ubuntu.com/) come pre-packaged with cloud-init,which helps with bootstrapping the instance.I wanted to have the solution work on AWS EC2 and Eucalyptus; since Ubuntu cloud images woron both, its a great choice.

    Registering the Ubuntu Cloud Image with Eucalyptus

    In order for us to get started, we need to get the Ubuntu Cloud image into Eucalyptus so that we canuse it for our instance. To upload, bundle and register the Ubuntu Cloud image, ramdisk and kernel,do the following:

    1. Download current version of Ubuntu Precise Server AMD64 (http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64.tar.gz) from the Ubuntu ClouImage Precise (http://cloud-images.ubuntu.com/precise/current/) page, then unpack (ungzip,unarchive) the tar-gzipped file.

    $ tar -zxvf precise-server-cloudimg-amd64.tar.gzx precise-server-cloudimg-amd64.imgx precise-server-cloudimg-amd64-vmlinuz-virtualx precise-server-cloudimg-amd64-loaderx precise-server-cloudimg-amd64-floppyx README.files

    2. Make sure to download and source your Eucalyptus credentials(http://www.eucalyptus.com/docs/3.1/ug/get_creds.html#get_cred).

    http://www.eucalyptus.com/docs/3.1/ug/get_creds.html#get_credhttp://cloud-images.ubuntu.com/precise/current/http://cloud-images.ubuntu.com/precise/current/precise-server-cloudimg-amd64.tar.gzhttp://cloud-images.ubuntu.com/http://cloud-images.ubuntu.com/precise/current/http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-network-security.htmlhttp://www.eucalyptus.com/docs/3.1/ig/nw_managed.html#nw_managedhttp://www.eucalyptus.com/docs/3.1/ig/planning_ha.html#planning_ha
  • 8/14/2019 Ubuntu Cloud Image _ More Mind Spew-Age From Harold Spencer Jr

    3/6

    11/1/13 ubuntu cloud image | More Mind Spew-age from Harold Spencer Jr.

    blogs.mindspew-age.com/tag/ubuntu-cloud-image/

    3. We need to bundle, upload, and register precise-server-cloudimg-amd64-loader (ERI), precise-server-cloudimg-amd64-vmlinuz-virtual (EKI), and precise-server-cloudimg-amd64.img (EMI). Fomore information regarding this, please refer to the Image Overview(http://www.eucalyptus.com/docs/3.1/ug/understanding_images.html#understanding_images)section of the Eucalyptus 3.1 User Guide(http://www.eucalyptus.com/docs/3.1/ug/index.html#welcome).

    $ euca-bundle-image -i precise-server-cloudimg-amd64-loader --ramdisk t

    $ euca-upload-bundle -b latest-ubuntu-precise -m /tmp/precise-server-cl$ euca-register -a x86_64 latest-ubuntu-precise/precise-server-cloudimg$ euca-bundle-image -i precise-server-cloudimg-amd64-vmlinuz-virtual --$ euca-upload-bundle -b latest-ubuntu-precise -m /tmp/precise-server-cl$ euca-register -a x86_64 latest-ubuntu-precise/precise-server-cloudimg$ euca-bundle-image -i precise-server-cloudimg-amd64.img$ euca-upload-bundle -b latest-ubuntu-precise -m /tmp/precise-server-cl$ euca-register -a x86_64 latest-ubuntu-precise/precise-server-cloudimg

    After bundling, uploading and registering the ramdisk, kernel and image, the latest-ubuntu-precisebucket in Walrus should have the following images:

    $ euca-describe-images | grep latest-ubuntu-preciseIMAGE eki-0F3937E9 latest-ubuntu-precise/precise-server-cloudimg-amd64-vml

    IMAGE emi-C1613E67 latest-ubuntu-precise/precise-server-cloudimg-amd64.img

    IMAGE eri-0BE53BFD latest-ubuntu-precise/precise-server-cloudimg-amd64-loa

    Cloud-init Config File

    Now that we have the image ready to go, we need to create a cloud-init config file to pass in using the

    user-data-file option that is part of euca-run-instances. For more examples of different cloud-init files,please refer to the cloud-init-dev/cloud-init repository on bazaar.launchpad.net(http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/files/head:/doc/examples/). Below is thecloud-init.config file I created for bootstrapping the instance with an install of Neo4j, using ephemeraldisk for the application storage, and installing some other packages (i.e. latest euca2ools, mlocate, less,etc.). The script can be also accessed from github as well under the eucalptus/recipes repo(https://github.com/eucalyptus/recipes/blob/master/cloud-init/cloud-init-neo4j.config).

    https://github.com/eucalyptus/recipes/blob/master/cloud-init/cloud-init-neo4j.confighttp://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/files/head:/doc/examples/http://www.eucalyptus.com/docs/3.1/ug/index.html#welcomehttp://www.eucalyptus.com/docs/3.1/ug/understanding_images.html#understanding_images
  • 8/14/2019 Ubuntu Cloud Image _ More Mind Spew-Age From Harold Spencer Jr

    4/6

    11/1/13 ubuntu cloud image | More Mind Spew-age from Harold Spencer Jr.

    blogs.mindspew-age.com/tag/ubuntu-cloud-image/

    #cloud-configapt_update: trueapt_upgrade: truedisable_root: truepackage_reboot_if_required: truepackages:- less

    - bind9utils- dnsutils- mlocatecloud_config_modules:- ssh- [ apt-update-upgrade, always ]- updates-check- runcmdruncmd:

    - [ sh, -xc, "if [ -b /dev/sda2 ]; then tune2fs -L ephemeral0 /dev/sda2;e- [ sh, -xc, "mkdir -p /var/lib/neo4j" ]- [ sh, -xc, "mount LABEL=ephemeral0 /var/lib/neo4j" ]- [ sh, -xc, "if [ -z `ls /var/lib/neo4j/*` ]; then sed --in-place '$ iME- [ sh, -xc, "META_HOSTNAME=`curl -s http://169.254.169.254/latest/meta-d- [ sh, -xc, "META_HOSTNAME=`curl -s http://169.254.169.254/latest/meta-d- [ sh, -xc, "wget -O c1240596-eucalyptus-release-key.pub http://www.euca- [ apt-key, add, c1240596-eucalyptus-release-key.pub ]- [ sh, -xc, "echo 'deb http://downloads.eucalyptus.com/software/euca2ool- [ sh, -xc, "echo 'deb http://debian.neo4j.org/repo stable/' > /etc/apt/

    - [ apt-get, update ]- [ apt-get, install, -y, --force-yes, euca2ools ]- [ apt-get, install, -y, --force-yes, neo4j ]- [ sh, -xc, "sed --in-place 's/#org.neo4j.server.webserver.address=0.0.0- [ sh, -xc, "service neo4j-service restart" ]- [ sh, -xc, "export LANGUAGE=en_US.UTF-8" ]- [ sh, -xc, "export LANG=en_US.UTF-8" ]- [ sh, -xc, "export LC_ALL=en_US.UTF-8" ]- [ locale-gen, en_US.UTF-8 ]- [ dpkg-reconfigure, locales ]- [ updatedb ]mounts:- [ ephemeral0, /var/lib/neo4j, auto, "defaults,noexec" ]

    Now, we are ready to launch the instance.

  • 8/14/2019 Ubuntu Cloud Image _ More Mind Spew-Age From Harold Spencer Jr

    5/6

    11/1/13 ubuntu cloud image | More Mind Spew-age from Harold Spencer Jr.

    blogs.mindspew-age.com/tag/ubuntu-cloud-image/

    Putting It All Together

    Before launching the instance, we need to set up our keypair and security group that we will use with

    the instance.1. To create a keypair, run euca-create-keypair (http://www.eucalyptus.com/docs/3.1/cli/euca-create-

    keypair.html#euca-add-keypair). *NOTE*Make sure you change the permissions of the keypairto 0600 after its been created.

    euca-create-keypair neo4j-user > neo4j-user.priv; chmod 0600 neo4j-use

    2. Next, we need to create a security group for our instance. To create a security group, use euca-create-group (http://www.eucalyptus.com/docs/3.1/cli/euca-create-group.html#euca-add-group).To open any ports you need for the application, use euca-authorize(http://www.eucalyptus.com/docs/3.1/cli/euca-authorize.html#euca-authorize). The ports we willopen up for the Neo4j application are SSH (22), ICMP, HTTP( 7474), and HTTPS (7473).

    Create security group:

    # euca-create-group neo4j-test -d "Security for Neo4j Instances"

    Authorize SSH:

    # euca-authorize -P tcp -p 22 -s 0.0.0.0/0 neo4j-test

    Authorize HTTP:

    # euca-authorize -P tcp -p 7474 -s 0.0.0.0/0 neo4j-test

    Authorize HTTPS:

    # euca-authorize -P tcp -p 7473 -s 0.0.0.0/0 neo4j-test

    Authorize ICMP:

    # euca-authorize -P icmp -t -1:-1 -s 0.0.0.0/0 neo4j-test

    3. Finally, we use euca-run-instances (http://www.eucalyptus.com/docs/3.1/cli/euca-run-instances.html#euca-run-instances) to launch the Ubuntu Precise image, and use cloud-init to instaNeo4j:

    # euca-run-instances -k neo4j-user --user-data-file cloud-init-neo4j.co

    http://www.eucalyptus.com/docs/3.1/cli/euca-run-instances.html#euca-run-instanceshttp://www.eucalyptus.com/docs/3.1/cli/euca-authorize.html#euca-authorizehttp://www.eucalyptus.com/docs/3.1/cli/euca-create-group.html#euca-add-grouphttp://www.eucalyptus.com/docs/3.1/cli/euca-create-keypair.html#euca-add-keypair
  • 8/14/2019 Ubuntu Cloud Image _ More Mind Spew-Age From Harold Spencer Jr

    6/6

    11/1/13 ubuntu cloud image | More Mind Spew-age from Harold Spencer Jr.

    blogs.mindspew-age.com/tag/ubuntu-cloud-image/

    To check the status of the instance, use euca-describe-instances(http://www.eucalyptus.com/docs/3.1/cli/euca-describe-instances.html#euca-describe-instances).

    # euca-describe-instances i-A9EF448CRESERVATION r-ED8E4699 345590850920 neo4j-testINSTANCE i-A9EF448C emi-C1613E67 euca-192-168-55-104.wu-tang.euca-hasp.euceuca-10-106-69-154.wu-tang.internal running admin 0 m1.small 2012-12-04T03

    enter-the-wu eki-0F3937E9 eri-0BE53BFD monitoring-disableeuca-192-168-55-104.wu-tang.euca-hasp.eucalyptus-systems.com euca-10-106-6

    Because I added in the cloud-init config file to do an apt-get upgrade, it takes about 5 to 7 minutesuntil the instance is fully configured and Neo4j is running. Once you have it running, go to https://