If you want to execute some commands during boot up(launch), you can execute it easily by loading script in user data section during EC2 launch. Bootstrap scripts run only once - when the instance is instantiated for the 1st time.
Please follow the below steps to create an EC2 instance. We will be installing Java, Maven and Jenkins during boot up.
Please follow the below steps to create an EC2 instance. We will be installing Java, Maven and Jenkins during boot up.
How to create EC2 instance in AWS console?
What is EC2 instance?
It is virtual server provided by AWS. We will be using this EC2 to setup Jenkins. Please follow the below steps to create an EC2 instance.Pre-requisites:
Steps:
1: Login to AWS console by clicking this link --> https://aws.amazon.com/console/
1: Login to AWS console by clicking this link --> https://aws.amazon.com/console/
click on All services, Click on Compute --> Click on EC2
3. Enter Name as Jenkins-EC2 and enter 1 as number of instance
4. Select Ubuntu and choose Ubuntu server 18.0.4 as AMI
5. Enter t2.small as instance type
6. You can choose existing Key
7. Under Network settings, Click Edit
Add port range as 8080 and select AnyWhere as Source Type, that should enter 0.0.0.0/0 as Source
8. Enter 10 GB as storage
Steps to add bootstrap script during EC2 launch
go to User Data section and Copy the script from this link.
Click on View instances
once EC2 is provisioned, you can login and you will be able to see Java, Maven and Jenkins installed in EC2 instance after launch.
Check the Console Output Logs in EC2 instance
Login to EC2 instance, and type the below command:
tail -f /var/log/cloud-init-output.log
This will give the output of bootstrap execution
Verify if Java got installed.
java -version
mvn --version
mvn --version
Go to the browser and try to access Jenkins in the browser, Jenkins should be coming up.(make sure you open port 8080 in the firewall rules)
Execute below command to get Jenkins admin password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Enter the password and click on continue
Click on Suggested plug-ins and setup the admin user for Jenkins.
Nice
ReplyDelete