Autoscaling,This is a component 1 of the Autoscaling for LAMP in AWS series. The step-via-step manual might stroll you via
1: Creating a LAMP Stack AMI
2: Setting up Autoscaling Groups.
3: Load Test the environment
4: Choose instance type
First, permit’s discuss the way to put together the AMI, create an ELB and RDS, verify the utility and terminate the instance.
Autoscaling,Prepare AMI
Autoscaling, create an AMI with all required applications set up. This AMI can be used as a template to release instances in autoscaling. For LAMP Stack, you must installation and first-class track the brand new variations of Apache and PHP.
- Log in to AWS console.
- Navigate to EC2 services. Make certain to interchange to the preferred place before launching instances
- Click on “Launch instance”.
4. Select your favorite Linux AMI in Classic Wizard.
5. Launch a micro example from the selected AMI with the favored Security institution and Key pair.
6. Now log in to the example and perform the PHP and Apache set up steps. For this text, we used Cygwin to connect the Linux servers. Make sure you open port 22 to allow SSH get entry to the usage of safety businesses.
We changed the “default” security group to open the SSH port. We advocate that you no longer completely open port 22 for SSH, however as a substitute allow incoming requests to SSH from your specific IP deal with. In our case the IP cope with changed into forty nine.206.166.12.
$ ssh –I LAMP_AMI.pem [email protected]:[email protected]
mailto:[email protected]
$ yum install httpd.x86_64 httpd-devel.x86_64 mod_ssl.x86_64 php.x86_64 php-common.x86_64 php-devel.x86_64 php-gd.x86_64 php-mbstring.x86_64 php-mysql.x86_64 php-pdo.x86_64 php-soap.x86_64 php-xml.x86_64 php-xmlrpc.x86_64 php-pecl-apc-devel.x86_64 php-pecl-memcache.x86_64 -y
Once you’ve correctly completed these instructions, Apache and PHP will install. Note that the instructions we’ve used are unique to CentOS 6.Three. Choosing a exceptional OS or a specific CentOS can also motive these instructions to fail to execute. The Hypertext Preprocessor modules indexed above are required for WordPress setup and they may range relying upon your requirements.
Now replace the PHP and Apache configurations for your Instance kinds and for the predicted load on utility. We used t1.Micro for this newsletter. Keep in mind that a manufacturing machine’s example kinds want to be chosen very carefully, and that the software must be tuned to those unique types.
Read extra on choosing instance types in Part 4 of this collection.
Install Postfix to ship e mail notification for the script used inside the next step.
$ yum install postfix
$ chkconfig –level 2345 postfix on
$ chkconfig –level 2345 httpd off
7. Now all the required programs are mounted and exceptional-tuned.
7. Now all the required programs are mounted and exceptional-tuned.
Autoscaling,AMI
Autoscaling,So, how does one deploy the code into AMI?
The technique described here automates the deployment. One cron activity could be protected in AMI, and it will down load and deploy the modern to be had S3 code. That manner that code updates will set up to S3 on every occasion, however not to times. Every time a brand new instance is up, the example will routinely down load updates from the S3 bucket and installation them.
What follows is a script scheduled for device boot-up. It calls for updating primarily based on specific user configurations and file paths.
#!/bin/bash
S3_URL= “http://s3-ap-southeast-1.amazonaws.com/lamp-deploy/wordpress.zip” #Change the following paths as per your requirement.
DOCUMENT_ROOT=</var/www/html>
TEMP_LOC=</tmp>
APACHE_RESTART=`/etc/init.d/httpd restart`
#Get the instance ID from AWS metadata.
INSTANCE_ID=` curl http://169.254.169.254/latest/meta-data/instance-id`
###download the latest code from s3 and deploy###
cd /tmp
wget $S3_URL
if [ $? –ne 0 ]
then
pkill -9 httpd
mail –s “Code Download Failed from S3##$INSTANCE_ID” [email protected] #Provide valid email ID here”
exit 1
fi
unzip wordpress.zip
rm –rf </var/www/html/*>
cp –r wordpress/* $DOCUMENT_ROOT
chmod 775 –R $DOCUMENT_ROOT
chown –R apache.root $DOCUMENT_ROOT
$APACHE_RESTART
if [ $? –ne 0 ]
then
pkill -9 httpd
mail –s “Apache startup Failed- $INSTANCE_ID” [email protected] #Provide valid email ID here”
exit 1
fi
##script ends here####
Put this bash script into a file in /opt/ directory:
$vim /opt/auto-deploy.sh
$chmod +x /opt/auto-deploy.sh
Open the Crontab and add this script to start at machine boot up:
$ crontab –e
Add the following script:
Save your changes and deploy the code through going for walks the script to test whether or not or now not the software is running as expected. This step is mandatory before creating an AMI. If you find any issues with the code or PHP/Apache settings, be sure to fix them earlier than creating an AMI.
Bundle and Upload the Code to S3
- Update the code with RDS DB configuration parameters.
- Now zip the running copy of the code and add it to the S3 vicinity. The S3 region must suit the location inside the script, and additionally match the zip document name.
- Upload the zip document to the S3 bucket that matches the script. You can add the zip document via the use of the console or any 1/3 birthday party tool like Cloudberry.
- Grant read permissions to down load the code from S3 to app servers.
Autoscaling,Create the ELB
Go to Services-> EC2 -> Load Balancers and select “Create Load Balancer”.
Keep Healthy/Unhealthy threshold limits to four because that’s demonstrated to be a perfect cost. Also ensure index.Html is to be had in the Document root. ELB looks for the index.Html as a health take a look at and removes the example from the burden balancer if it doesn’t get the 2 hundred reaction. Create the desired protection groups and key pair for the autoscaling times.
Autoscaling LAMP,Create RDS
- Go to Services -> RDS and select the MySQL engine.
2. Select instance types, offer the information for all required fields and release the instance. The RDS configuration details selected for this article may be seen below.
How need to you select the DB instance type? There are many monitoring tools available for tracking MySQL overall performance. If AWS RDS is used for MySQL, then it’s essential to bear in mind CloudWatch metrics. Since it’s no longer feasible to put in dealers in RDS, you can rely upon CloudWatch metrics.
By default, CloudWatch contains all required RDS monitoring metrics. Be positive to monitor the reminiscence, CPU, DB connections and community I/O before you scale up the server.
Ideally, m1.Small RDS can take care of as much as 75 concurrent connections effortlessly. But that relies upon upon the DB queries and the code.
3. After launching RDS, open the 3306 port to the app servers institution.
4. Import the DB and attempt connecting to the application. Then use preferred MySQL instructions to import the dump.
Example: mysql –h rds-endpoint –u user –ppasswwd databasename < unload.Sq.
Verify the Application
At this factor, it’s mandatory which you thoroughly confirm the application. Make positive to test Login/logout, add/download and any other applicable verifications. Create an AMI simplest after ensuring that the software is operating as expected. Fix any troubles before proceeding to the subsequent step.
Autoscaling LAMP Create an AMI
1. Delete the command history:
$ history -c
Delete the deployed code and logs files and make things as smooth as feasible.
2. Create an AMI the use of the micro example that you’ve configured.
Go to AWS Console->Services->EC2, right click on on the example, and pick out “Create Image” (EBS AMI).
Name the AMI the usage of a date because the naming conference. Do no longer select “No reboot”. Instead, allow it to reboot even as growing the AMI. The reboot will come up with a regular photo of EBS.
In a few minutes an AMI will be created and made to be had.
Keep the root partition as minimal as possible because that allows to save you insects. You don’t want huge space for root partition in autoscale because these times maintain rotating.
Terminate the Instance
Finally, terminate the instance by using proper clicking on the instance and deciding on “Terminate”. Keep the ELB and RDS walking.