[Tutorial] How to Get Apache Stratos 4.0.0 Running on a Single Machine

  • By Punnadi Gunarathna
  • 7 Apr, 2014

Prerequisites

The following softwares have to be installed in the target machine prior to installing Apache Stratos.

Oracle Java SE Development Kit (JDK) Version 1.6.24 or above/1.7
MySQL Server Version 5.5.0 or above
Git Version 1.9.0 or above
Apache Maven Version 3.0.3 or above

More details:https://cwiki.apache.org/confluence/display/STRATOS/4.0.0+Prerequisites

Introduction

As you probably know Apache Stratos is a polyglot PaaS framework, providing developers a cloud-based environment for developing, testing, and running scalable applications. It helps to run Tomcat, PHP and MySQL applications as a service on major cloud infrastructures such as EC2, vCloud, and OpenStack. Apache Stratos has the ability to take any server software and make it into a Stratos cartridge.

This tutorial will provide you step-by-step guide on how to setup Apache Stratos 4.0.0-Incubating on a single machine in collaboration with OpenStack as the IaaS provider. It will also guide you on how to define a Stratos LB cartridge, a PHP framework cartridge and how to subscribe to it.

Note: The reader would require sound knowledge on Linux environment, Puppet, and OpenStack as it is necessary to follow the steps given in this tutorial.

Environment

IaaS provider - OpenStack

Ubuntu 12.10, x86_64 machine (10.100.0.106) - Puppet Master, Stratos setup

Ubuntu 13.04, i686 - OpenStack image used to spawn instances On Demand

Installation steps

  1. Checkout Stratos codebase
  • Check out source code from the incubator-stratos.git repository
  • Build the source using the following Maven command in a clean repository:
  • mvn clean install

  • The products needed by Apache Stratos can be found in the /products/
    /modules/distribution/target/ directory
  • Configure Puppet Master
    • Follow the below Stratos wiki page to do the necessary configuration
    • https://cwiki.apache.org/confluence/display/STRATOS/4.0.0+Configuring+Puppet+Master

    • The modified /etc/puppet/manifests/nodes.pp configuration is as follows (note that I have put the machine IP as mb_ip and cep_ip):
    • Once you copy the cartridge agent, load balancer and the jdk (make sure to check the snapshot/image Operating System bit version in IaaS provide and copy the appropriate jdk to the given path) the corresponding agent, lb and java folder structure is as follows:
  • Configure cartridge image
    • Follow the below Stratos wiki page to do the necessary configurations to the OpenStack image
    • Make sure you input the same hostname given as Puppet master in Step 2 for the query you get (puppet master hostname) when you ran the config.sh
    • https://cwiki.apache.org/confluence/display/STRATOS/4.0.0+Creating+a+Cartridge

    • If you come across any errors in red font while puppet init, make the necessary changes and rerun “puppet agent -vt” command until you get successful installation
    • Once you configure the instance, convert it to a snapshot. I have created a snapshot called “Tutorial”. If the snapshot is created successfully, you will notice the status is “active” as depicted below
  • Stratos configuration
    • Stratos setup can be done in two ways; either a manual configuration or through automated scripts. In this tutorial, I have used automated scripts. You can follow the below Stratos wiki page and do the necessary configurations (Follow up to Step 8)
    • https://cwiki.apache.org/confluence/display/STRATOS/4.0.0+Automated+Product+Configuration

    • My setup.conf is as follows:
      • Set the username of the account that you have used to login to the target machine as host_user
      • By default EC2 is enabled as IaaS provider. Make sure you disable EC2 and enable OpenStack specifying your OpenStack URL, user credentials, project name, key pair name, and security group correctly
      
    export setup_path="/home/stratos_setup/stratos-installer"
    export stratos_pack_path="/home/stratos_setup/stratos-packs"
    export stratos_path="/home/stratos_setup/stratos"
    
    export JAVA_HOME="/usr/lib/jvm/java-6-oracle" #Java home path
    
    export log_path="${stratos_path}"
    
    export host_user="punnadi" #A host user account for the machine which run Stratos component(s)
    
    export stratos_domain="stratos.apache.org"
    
    export mb_ip="10.100.0.106"    # Machine ip on which mb run
    export cep_ip="10.100.0.106"    # Machine ip on which cep run
    export cc_ip="10.100.0.106"     # Machine ip on which cc run
    export as_ip="10.100.0.106"    # Machine ip on which auto scalar run
    export sm_ip="10.100.0.106"    # Machine ip on which sc run
    export puppet_ip="10.100.0.106"     # Machine ip on which puppet master run
    export puppet_hostname="puppet.stratos.com" # Host name given to identify the puppet master
    export puppet_environment="ignore" # Name of puppet environment
    
    export cc_port_offset=1
    export sm_port_offset=2
    export as_port_offset=3
    export cep_port_offset=4
    export mb_port_offset=5
    
    export mb_hostname="mb.$stratos_domain"
    export cep_hostname="cep.$stratos_domain"
    export sm_hostname="$stratos_domain"
    export cc_hostname="cc.$stratos_domain"
    export as_hostname="as.$stratos_domain"
    
    export resource_path=$setup_path/resources
    
    
    # ----------------------------------------------------------------------------
    # MB configuration
    # ----------------------------------------------------------------------------
    export mb_path=$stratos_path/"wso2mb-2.1.0"
    export mb_pack_path=$stratos_pack_path/"wso2mb-2.1.0.zip"
    
    
    # ----------------------------------------------------------------------------
    # CEP configuration
    # ----------------------------------------------------------------------------
    export cep_artifacts_path="${stratos_pack_path}"
    export cep_extension_jar=$stratos_pack_path/"org.apache.stratos.cep.extension-1.0.0-SNAPSHOT.jar" # cep extensions jar file name
    export andes_client_jar=$stratos_pack_path/"andes-client-0.13.wso2v8.jar" # andes client jar file name
    
    export cep_path=$stratos_path/"wso2cep-3.0.0"
    export cep_pack_path=$stratos_pack_path/"wso2cep-3.0.0.zip"
    
    export cep_mb_ip=$mb_ip
    export cep_mb_listen_port=$((5672 + $mb_port_offset))
    
    # ----------------------------------------------------------------------------
    # CC configuration
    # ----------------------------------------------------------------------------
    export cc_path=$stratos_path/"apache-stratos-cc-4.0.0-SNAPSHOT"
    export cc_pack_path=$stratos_pack_path/"apache-stratos-cc-4.0.0-SNAPSHOT.zip"
    
    export cc_mb_listen_port=$((5672 + $mb_port_offset))
    export cc_https_port=$((9443 + $cc_port_offset))
    
    # IaaS Providers
    # ----------------------------------------------------------------------------
    # Set _provider_enabled parameter to true to enable desired IaaS. A hybrid cloud could be
    # created using multiple IaaSs.
    
    # EC2
    export ec2_provider_enabled=false
    export ec2_identity=""
    export ec2_credential=""
    export ec2_keypair_name=""
    export ec2_owner_id=""
    export ec2_availability_zone=""
    export ec2_security_groups=""
    
    # Openstack
    export openstack_provider_enabled=true
    export openstack_identity="openstackDemo:admin" # Openstack project name:Openstack login user
    export openstack_credential="password" # Openstack login password
    export openstack_jclouds_endpoint="https://appfactorycloud.private.wso2.com:5000/v2.0"
    export openstack_keypair_name="appfackey"
    export openstack_security_groups="default"
    
    
    # ----------------------------------------------------------------------------
    # Auto Scalar configuration
    # ----------------------------------------------------------------------------
    export as_path=$stratos_path/"apache-stratos-autoscaler-4.0.0-SNAPSHOT"
    export as_pack_path=$stratos_pack_path/"apache-stratos-autoscaler-4.0.0-SNAPSHOT.zip"
    
    export as_mb_listen_port=$((5672 + $mb_port_offset))
    export as_cc_https_port=$((9443 + $cc_port_offset))
    export as_sm_https_port=$((9443 + $sm_port_offset))
    
    
    # ----------------------------------------------------------------------------
    # SM configuration
    # ----------------------------------------------------------------------------
    export sm_path=$stratos_path/"apache-stratos-manager-4.0.0-SNAPSHOT"
    export sm_pack_path=$stratos_pack_path/"apache-stratos-manager-4.0.0-SNAPSHOT.zip"
    export mysql_connector_jar=$stratos_pack_path/"mysql-connector-java-5.1.27-bin.jar" #mysql connector jar file name
    
    export userstore_db_hostname="localhost"
    export userstore_db_schema="userstore"
    export userstore_db_port="3306"
    export userstore_db_user="root"
    export userstore_db_pass="root"
    
    export sm_puppet_ip=$puppet_ip
    export sm_puppet_hostname=$puppet_hostname
    export sm_puppet_environment=$puppet_environment
    export sm_mb_listen_port=$((5672 + $mb_port_offset))
    export sm_cc_https_port=$((9443 + $cc_port_offset))
    export sm_as_https_port=$((9443 + $as_port_offset))
    export sm_https_port=$((9443 + $sm_port_offset))
    export sm_http_port=$((9763 + $sm_port_offset))
    
  • Once you copy the packs and other required configurations to “stratos-packs” directory, the directory tree is similar to what has been shown in the following diagram
  • Once everything is ready, either of the following commands can be used to startup all Stratos servers. Do not close the terminal until all the servers are up and running. Tail the stratos.log as per the instructions given in the console
    • sudo ./setup.sh -p "all"
    • sudo ./setup.sh -p “mb cep cc as sm”
  • Tail the wso2carbon.log files found in
    /repository/log/ directory in each product. You are expected to see error-free logs
  • Setup cartridges
  •   
    
    {
    	"id": "P1",
    	"provider": "openstack",
    	"property": [
        	{
        	"name": "region",
        	"value": "RegionOne"
        	}
    	]
    }
    
  • deploy-autoscaling-policy -p /stratos_setup/autoscale-policy.json
  •   
    
    {
    	"id": "economyPolicy",
    	"loadThresholds": {
      	"requestsInFlight": {
        	"average": "300",
        	"gradient": "0",
        	"secondDerivative": "0",
        	"scaleDownMarginOfGradient": "1.0",
        	"scaleDownMarginOfSecondDerivative": "0.2"
      	},
      	"memoryConsumption": {
        	"average": "6000",
        	"gradient": "0",
        	"secondDerivative": "0",
        	"scaleDownMarginOfGradient": "1.0",
        	"scaleDownMarginOfSecondDerivative": "0.2"
      	},
      	"loadAverage": {
        	"average": "6000",
        	"gradient": "0",
        	"secondDerivative": "0",
        	"scaleDownMarginOfGradient": "1.0",
        	"scaleDownMarginOfSecondDerivative": "0.2"
      	}
    	}
    }
    
  • deploy-deployment-policy -p /deployment-policy.json
  •   
    
    {
    	"id": "af-deployment",
    	"partitionGroup": {
      	"id": "N1",
      	"partitionAlgo": "one-after-another",
      	"partition": [
        	{
          	"id": "P1",
          	"partitionMax": "5",
          	"partitionMin": "1"
        	}
      	]
    	}
      }
    
  • deploy-cartridge -p /lb-cartridge.json (You need to copy the image id from openstack image and set it in json file, Moreover set the keypair name)
  •   
    {
    	"type":"lb",
    	"provider":"lb",
    	"host":"stratos.com",
    	"displayName":"load balancer",
    	"description":"LB Cartridge",
    	"version":"4",
    	"defaultAutoscalingPolicy":"economyPolicy",
    	"multiTenant":"false",
    	"portMapping":[
         	{
            	"protocol":"http",
            	"port":"8280",
            	"proxyPort":"8280"
         	},
         	{
            	"protocol":"https",
            	"port":"8243",
            	"proxyPort":"8243"
         	}
    	],
    	"iaasProvider":[
         	{
            	"type":"openstack",
            	"imageId":"RegionOne/",
            	"maxInstanceLimit":"5",
            	"property":[
               	{
                  	"name":"instanceType",
                  	"value":"RegionOne/2"
               	},
               	{
                  	"name":"keyPair",
                  	"value":""
               	}
            	]
         	}
    	],
    	 
    	"property":[
         	{
            	"name":"load.balancer",
            	"value":"true"
         	}
    	]
    }
    
  • deploy-cartridge -p /php-cartridge.json(You need to copy the image id from openstack image and set it in json file, moreover, set the keypair name)
  •   
    
    {
    	"type":"php",
    	"provider":"apache",
    	"host":"stratos.com",
    	"displayName":"PHP",
    
    	"description":"PHP Cartridge",
    	"version":"7",
    	"defaultAutoscalingPolicy":"economyPolicy",
    	"multiTenant":"false",
    	"portMapping":[
         	{
            	"protocol":"http",
            	"port":"80",
            	"proxyPort":"8280"
         	},
         	{
            	"protocol":"https",
            	"port":"443",
            	"proxyPort":"8243"
         	}
    	],
    	"iaasProvider":[
         	{
            	"type":"openstack",
            	"imageId":"RegionOne/",
            	"maxInstanceLimit":"4",
            	"property":[
               	{
                  	"name":"instanceType",
                  	"value":"RegionOne/2"
               	},
               	{
                  	"name":"keyPair",
                  	"value":""
               	}
            	]
         	}
    	],
    	"loadBalancer":{
         	"type":"lb",
         	"property":{
            	"name":"default.load.balancer",
            	"value":"true"
         	}
    	},
    }
    
  • Subscribe to PHP cartridge
    • The final setup is to subscribe to the PHP cartridge created in Step 5. Using the CLI tool, it can be done with the following command. In order to use this command, you need to have a PHP application in GitHub and the corresponding git URL has to be provided as the command argument as follows:
    • subscribe-cartridge php php1 -r -dp af-deployment -ap economyPolicy

    • You should check the logs frequently to check for any errors
    • Once the subscription is successful, you will notice that the LB and PHP instances are spawning in OpenStack Console. If the puppet agent ran successfully in spawned instances you will notice that the “Member Created” and “Member Activated” logs in Stratos Manager
    • In addition, the host entry to your local machine /etc/hosts file will be as follows. You can get LB IP from instance information found under OpenStack instances tab
    • php1.stratos.com

    • For more information refer to the below wiki URL
    • https://cwiki.apache.org/confluence/display/STRATOS/4.0.0+subscribe-cartridge

  • Access PHP application via LB
    • By default, LB http and https ports are configured to 8280 and 8243. Therefore, you need to access the PHP application with the below URL:
    • https://php1.stratos.com:8280/

    • Make sure you have enabled these ports (8280/8243) in the OpenStack instance security group