Before starting aiCache must be running and at least one Origin server on your web application. How-to run aiCache server on EC2 is described in this article.
Origin server will be used as a Scalr instance snapshot source and can be terminated at the conclusion of this tutorial. Note
It is strongly recommended to terminate your Origin server after it is imported to Scalr.
Scalr will take care of running it after successful configuration.
Scalr
installation
You have 3 ways of having Scalr server. The procedure of getting Scalr up and running is out of scopes of this document but these links are great place to starting
You must configure the appropriate environment in order to use Scalr with Amazon EC2. If you are not using Scalr hosting you have to create a new user and work with a regular non Administrator user. Here are steps for creating regular Scalr user
Login with Administrator account. The default username and password are admin:admin (Change it) Click on Clients → Add new After you have created new user you must configure environment in order to start using EC2. Here is a good How-To for that So lets assume that you have up and running Scalr, and now you need to use it for auto-scaling your origin servers and updating aiCache to use them. Integrating Startup and Shutdown scripts for updating aiCache configuration Click on Scripts → Add new At next screen You must add Scripts Name, Description ans Script.
Lets give names “Origin Startup” & “Origin Shutdown” to start and shutdown scripts accordingly. Copy and paste texts below and make change in give order. Startup Script (Copy & Paste Block-quoted text only). Change YOUR_SERVER to IP of your aiCache instance. #!/bin/bash # Extra options to ssh client OPTIONS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" # Change tou your aiCache server AICACHE=YOUR_SERVER # Do not touch script below untill you are sure what to do ssh $OPTIONS $AICACHE "echo origin %internal_ip% 80 >> /usr/local/aicache/aicache.cfg" && pkill aicacheDo the same again for creating Shut Down script
Shutdown Script (Copy & Paste Block-quoted text only). Change YOUR_SERVER to IP of your aiCache instance.
#!/bin/bash # Extra options to ssh client OPTIONS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" # Change tou your aiCache server AICACHE=YOUR_SERVER # Do not touch script below untill you are sure what to do ssh $OPTIONS $AICACHE "sed -i /%internal_ip%/d /usr/local/aicache/aicache.cfg" && pkill aicache Correct Shutdown script must look like this.
Setup password less ssh access from origins to aiCache server First of all we need to be sure that origin servers can access aiCache instance via ssh and without password. First of configure EC2 Security groups for that. The minimal Security group for aiCache server shall look like this Origin servers will be in separate security group created by Scalr.
Now as EC2 security groups are configured you have to setup password less ssh access. This can be done by running following commands on first origin server.
cd /root/.ssh ssh-keygen -t rsa -b 2048 scp /root/.ssh/id_rsa.pub aiCache-server:/root/.ssh/authorized_keys2Hit Enter when ssh-keygen program prompts for key location & Leave password empty when ssh-keygen ask for passphrase.
Now you shall be able to access aiCache server from origin server by ssh without password. Integrate your origin servers to Scalr
Before starting integration we must install Scalr client on Origin servers. This is quiet easy task is you are using Debian or Red-Hat family Linux distributions. For RHEL/CentOS/Fedora: Add the EPEL repository, install Python 2.6 rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm yum install python26rpm -Uvh http://rpm.scalr.net/rpm/scalr-release-2-1.noarch.rpm yum install scalarizrFor
Debian/Ubuntu
Add the Scalr repository && install scalarizr
wget http://apt.scalr.net/scalr-repository_0.2_all.deb dpkg -i scalr-repository_0.2_all.deb apt-get update apt-get -y install scalarizrOK now as scalarizr is installed we can go forward with creating image for Scalr.
Login to Scalr with your user and password & start Importing your origin server. Click on Servers → import non-scalr server Note In order to run scalarizr you need to open TCP 8013 port on EC2 Firewall. So minimal Security groups policy for server that must be imported shall look like this
Choose platform “Amazon EC2” and correct Behavior. We assume that you are using web-server like Apache or Nginx so Behavior must be chosen correctly. Be sure to write you public IP address in field Servers IP Address (Note EC2 internal address like 10.x.x.x) Note Do not use spaces when describing Role Name. Apache Role will cause error during image creation Apache_Role or ApacheRole is OK. This problem is not documented and may not exist on some installations but I got it and and it is much easier not to use Spaces and not get scalarizr errors rather than debugging what was wrong. So screenshot below shows how this can be done correctly.
Hit Next for next screen.
At next screen you will see short how-to for installing scalarizr and the line that you must select Copy and paster it to your servers terminal. After you will copy and paste this text to your server you will wait some time until Scalr will create the server image. I f you get errors remove and reinstall scalarizr. The process of creating image may take up to 40 minutes depends on disk size and use of the server.
If everything goes well you will something like this in terminal of server.scalarizr --import -y -o server-id=2224dedf-06b9-42ea-a5c5-76b24e005ae9 -o role-name=MyApacheRole -o crypto-key=VnpsOVqkVxkuvSEt28a7alKxS+5vc9ZayCqmmeGx5x8qAEQZq/Bf8Q== -o platform=ec2 -o behaviour=app -o queryenv-url=http://scalr.netangels.net/query-env -o messaging-p2p.producer-url=http://scalr.netangels.net/messagingStarting import process... Don't terminate Scalarizr until Scalr will create the new role 2011-01-31 07:42:22,429 - INFO - scalarizr - [pid: 2205] Starting scalarizr 2011-01-31 07:42:22,431 - INFO - scalarizr.handlers.lifecycle - Server will be imported into Scalr 2011-01-31 07:42:22,438 - INFO - scalarizr.messaging.p2p.consumer - Build message consumer server on 0.0.0.0:8013 2011-01-31 07:42:23,070 - INFO - scalarizr.messaging.p2p.producer - Message 'Hello' delivered (message_id: c10ac914-cb20-4c91-bed1-49bb3c2e7084) 2011-01-31 07:42:23,318 - INFO - scalarizr.snmp.agent - [pid: 2257] Starting SNMP server on 0.0.0.0:8014 …... …... …... …... 2011-01-31 07:48:10,881 - INFO - scalarizr.platform.ec2.s3tool - Upload complete! 2011-01-31 07:48:10,882 - INFO - scalarizr.handlers.ec2.rebundle - Registering image 'scalr2-images-us-east-1-575682692618/MyApacheRole-20110131074305.manifest.xml' 2011-01-31 07:48:11,594 - INFO - scalarizr.handlers.ec2.rebundle - Registration complete! 2011-01-31 07:48:12,463 - INFO - scalarizr.messaging.p2p.producer - Message 'RebundleResult' delivered (message_id: 7c4bdd1c-d3a5-4435-bd78-7a5411ff6b66) 2011-01-31 07:48:12,480 - INFO - scalarizr.handlers.ec2.rebundle - Rebundle complete! If you imported this server to Scalr, you can terminate Scalarizr now. Now it is safe to terminate your instance and start building your Scalr farm. Click on Server Farms → Build new At next field write name for your new farm and click on Roles Click on + button to add Roles & expand Application Servers And navigate to MyApacheRole as you have cerated it before
initial parameters for Farm.
Do following
Minimum instances at least 1 Maximum instances (choose your preferred amount ) optimal is 5 or more Select “Keep oldest instance running after scale down” Select Delays. Default 10 minutes is OK but you free to select your preference. Choose Enable scaling based on “LoadAverages” and click + button After adding this metrics choose Use 5 minutes load average for scaling At the bottom you will see Scale in and Scale out parameters. The easiest way to calculate Load Averages is set maximum allowed to amount of cores of processor. For example if you have m1.small instance maximum allowed Load Average must be 1 as this instance has only one virtual core. For M1.Large instance Load Average must be 2 as it has double virtual core etc... For making correct scaling we can 1 point for scale out . For example in case or m1.small instance Scale out will start when Load Average goes over 2 points and for m1.large over 3 points accordingly . So lets select values. I use m1.small instance for testing so I will scale out (Add more instances ) when Load goes over 2 and points and Scale in (Release instances) when Load Average will be normal 1 . Screen-shot below demonstrates it Not we need to add our startup and shutdown scripts.
Click on Scripting at the side. Select Origin Startup & Hostinit & click on + button to add start origin script. Note “Choose Hostiniti and not HostUP”
After clicking on + button accept default values
Now we need to do the same with shutdown script. Figure below shows how. Now you need to choose Origin Shutdown and BeforeHostTerminate accordingly |
















