forked from maulik2311/Linux-by-Kastro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 29- AWS Training - B9_CIVIL Edu.txt
167 lines (96 loc) · 7.53 KB
/
Day 29- AWS Training - B9_CIVIL Edu.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
########################################################################################
DevOps - Day 21
########################################################################################
===============
JENKINS
===============
Project 2: JENKINS + GITHUB + MAVEN + TOMCAT - Integration
------------------------------------------------------------------------------------------
~ Code is usually available in GITHUB Repo. We have to create a Jenkins job that job should take code from GITHUB repo. It should compile and package that code using Maven, and then the war gets generated. This war file should be deployed into the Tomcat Webserver. So, here we are going to do Build & Deployment Process.
~ By default the Tomcat will run on Port No. 8080
~ By default the Jenkins will run on Port No. 8080
Tasks:
---------------
========
Part 1
========
1. Create an EC2 Instance - Connect to the instance using MobaXTerm Tool.
========
Part 2
========
JENKINS INSTALLATION ON LINUX EC2 INSTANCE
~ Add Jenkins repo. to our YUM repo:
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
~ Import a key-file from Jenkins-CI to enable the installation from package:
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade
~ Installing Java
sudo amazon-linux-extras install java-openjdk11 -y
java -version
~ Install Jenkins:
sudo yum install jenkins -y
~ Lets start, enable, and check the status of Jenkins
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
You should see Active & Running in Green Colour, which means the Jenkins Tool is successfully installed
~ Check the jenkins accessibility. By default the Jenkins will run on Port No. 8080.
So, open Port No. 8080 for EC2 instance to access Jenkins
"Check" the instance ----> Security ----> Click on the link under SGs ----> Add Rules ----> Custom TCP, 8080, Anwhere ----> Save Rules.
Open new tab: <Paste the Public IP of Instance>:8080 ----> You will see the Jenkins Home Page ----> Now we have to Unlock the Jenkins ----> You will see a code in the red colour ----> Copy the code in red colour ----> Go to MobaXTerm ----> sudo cat <paste the red color code> ----> You will see a password. Copy that password and paste in jenkins home page ----> Click on suggested plugins ----> You will see "Create First Admin User" ----> Enter Username, Password, Name, Email Id ----> Save and Continue ----> Jenkins URL:http://52.14.0.208:8080/ ----> Save and Finish ----> You will see "Jenkins is ready!" ----> Click on "Start using jenkins" ----> Now you can see the jenkins home page and here you can create Jenkins Jobs.
========
Part 3
========
TOMCAT WEBSERVER INSTALLATION ON LINUX EC2 INSTANCE
https://tomcat.apache.org/download-90.cgi ----> Downloads ----> Tomcat 9 ----> Copy the link of tar.gz file ----> https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.73/bin/apache-tomcat-9.0.73.tar.gz ----> sudo wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.73/bin/apache-tomcat-9.0.73.tar.gz ----> ls -l ----> You will the tomcat file in red colour. This is a tar.gz file and we have to extract the tar.gz file ----> tar -xvf <enter the name of tomcat file in red colour> ----> All the files will get extracted ----> ls -l ----> You will see the list of extracted files
Lets start the tomcat server:
Inorder to start the tomcat server, we need a file called "starup.sh"
This "startup.sh" file will be there in "bin" folder ----> cd bin ----> ls -l ----> you will see startup.sh file ----> ./startup.sh ----> You will see "Tomcat Started"
Lets access the tomcat server:
Since, the tomcat also runs on Port No. 8080, we cannot access tomcat as on the same port no. jenkins is also running.
Now, we have to change the Port No. of Tomcat. (Tomcat Port No. 9090)
How to change the port no. of Tomcat?
------------------------------------------------------
In order to change the port no. of Tomcat, we will configure a file known as "server.xml" This server.xml file will be available in "conf" folder.
cd .. ----> pwd ----> /home/ec2-user/apache-tomcat-9.0.73 ----> ls -l ----> cd conf ----> ls -l ----> you will see server.xml file ----> vi server.xml ----> scroll down till you see "connector port=8080" ----> press "i" ----> Change the port no to 9090 instead of 8080 ----> escape ----> :wq
Check the Tomcat accessibility. By default the Tomcat will also run on Port No. 8080. But on the same port no. jenkins is also running.
So we have to add the port no. to 9090 in ec2 instance to access Tomcat:
"Check" the instance ----> Security ----> Click on the link under SGs ----> Add Rules ----> Custom TCP, 9090, Anwhere ----> Save Rules.
Shutdown the tomcat server ----> cd bin ----> ./shutdown.sh ----> ./startup.sh
Open new tab: <Paste the Public IP of Instance>:9090 ----> You will see the Tomcat Home Page
Go to browser and check for tomcat accessibility. You are now able to access Tomcat and Jenkins in the same instance.
Here we can access only the Home page of Tomcat.
Inorder to access complete tomcat server, we need to do the configuration in "context.xml" file.
apache-tomcat-9.0.73/webapps/manager/META-INF/context.xml
cd apache-tomcat-9.0.73/webapps/manager/META-INF/context.xml ----> vi context.xml ----> You will see a valve tag. You have to edit "Allow" tag ----> ".*" />
Configuring the Users in Tomcat
---------------------------------------------
we need to edit the tomcat-users.xml to configure the users.
The "tomcat-users.xml" file is available in "conf" folder
<role rolename="manager-gui" />
<user username="tomcat" password="tomcat" roles="manager-gui" />
<role rolename="admin-gui" />
<user username="admin" password="admin" roles="manager-gui,admin-gui"/>
cd bin
./shutdown.sh
./startup.sh
Access Tomcat on Browser ----> Click on Server Status ----> Enter the username (admin) and password (admin)
Jenkins Port No.: 8080
Tomcat Port No.: 9090
Steps to create the jenkins job with GITHUB Repo. + Maven + Tomcat Server:
-----------------------------------------------------------------------------------------------------------
Connect to the Tomcat Server
Connect to the Jenkins Software
Inorder to do the automation, Jenkins is going to execute some script to deploy the war file into the Tomcat Webserver.
Step 1: Adding the manager-script role in tomcat-users.xml file
In order to do the automation, Tomcat user should have a "manager-script" permission. There should be one user in the Tomcat with the "manager-script" permission. Then with that user credentials we can automate the deployment process.
Goto MobaXTerm and Connect to the Instance ----> ls -l ----> cd apache-tomcat-9.0.73 ----> ls -l ----> cd conf ----> ls -l ----> You can see tomcat-users.xml ----> vi tomcat-users.xml
Step 2: Installing deploy-container plugin in Jenkins software
Jenkins Dashboard ----> Manage Jenkins ----> Mange Plugins ----> Available Plugins ----> In the search bar, type deploy to container and check the same ----> Install without restart ----> Click on "Go back to the top page.
Step 3: Creating a Jenkins job and for that Jenkins job we will give permission to deploy
Add JDK, GIT, MAVEN in Jenkins Browser Page by goinginto Global Tools Configuration
Install GIT in EC2 Instance where Jenkins is running
________________________________________________________________________________________
By
Kastro Kiran V