forked from Sonal0409/DevOps_ClassNotes
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkins_Tomcat
More file actions
245 lines (123 loc) · 4.45 KB
/
Copy pathJenkins_Tomcat
File metadata and controls
245 lines (123 loc) · 4.45 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
Using jenkins we have to Deploy a war file on tomcat server
Jenkins --> compile --> unit testing ---> Package(.war file)
Using jenkins we have to take this .war file and deplpy it on a webserver
Webserver : tomcat
Step 1: Create server on which we have to install tomcat 8
Step 2: Create another server on which jenkins is installed
Step 3: We will create a free style job to deploy the package on a tomcat server
plugin : deploy on container
Step 4: we will create a pipeline job, in which we will write code to deploy on tomcats erver
plugin : ssh agent
Steps for deployment on a webserver:
> on a server you are goign to install webserver
> Start the tomcat service or start the webserver
> Copy .war file (package) into the webapps directory of tomcat
> restart tomcat -> so that application is deployed successfully
Access the web application
publicip:8080/packagename
https://github.com/Sonal0409/DevOpsClassCodes
Step 1: Create server on which we have to install tomcat 8
Pre-req: Install java8 on the server
Install tomcat
$ cd /opt
$ wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.78/bin/apache-tomcat-8.5.78.tar.gz
$ tar -xvzf apache-tomcat-8.5.78.tar.gz
$ mv apache-tomcat-8.5.78.tar.gz tomcat
$ cd tomcat
$ cd bin
$ ./startup.sh ==> tomcat will be up and running
go to browser
public ip:8080 ==> you will see tomcat
Do the desired config changes in context.xml file for access manager APP
Apply the changes in these 2 context.xml file of tomcat
vim /opt/tomcat/webapps/host-manager/META-INF/context.xml
vim /opt/tomcat/webapps/manager/META-INF/context.xml
comment this line in the contxt.xml
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
commented in both the files
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
Create roles & credentials
****
$ cd conf
$ vim tomcat-users.xml
at the end before </tomcat-users> add these roles
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
Save the file
$ cd bin
$ ./shutdown.sh
$ ./startup.sh
publicip:8080
click on managerapp
username: tomcat
password:s3cret
you can now see the manager app
Step 2: Create another server on which jenkins is installed - complete
Start jenkins
publicip:8080
Install a plugin : Deploy to container Plugin
Create a free style job
give the repo name
give the trigger
build step --> invoike top level maven target
goal as : clean install package
Post build actions
select deploy war/ear on container
WAR/EAR files : **/*.war
Containers:
click on add container--> select tomcat 8
Select credentials
and give tomcat URL
Build the job
Deployment complete
****************************************
Pipeline as code:
Give permissions to ec2-user to make chnages to webapps directory
chown -R ec2-user:ec2-user /opt
Download a plugin that will connect to tomcat server form jenkins
plugin: ssh agent
Using ssh copy the war file in the tomcat webapps directory
sh 'scp /var/lib/jenkins/workspace/TomcatDeploypipeline/target/addressbook.war ec2-user@3.129.17.201:/opt/tomcat/webapps'
command: scp filenamelocation username@publicip:Destinationpath
to do this step
we need a plugin
ssh agent
it connects to you tomcat server through jenkins using ssh
username : ec2-user
pem file
copy the war file in the tomcat webapps directory
Pipeline Code:
pipeline{
agent any
tools{
jdk 'myJAVA'
maven 'mymvn'
}
stages{
stage('cloneRepo'){
steps{
git 'https://github.com/Sonal0409/DevOpsClassCodes.git'
}
}
stage('package')
{
steps{
sh 'mvn clean install package'
}
}
stage('Deploy on tomcat'){
steps{
sshagent(['idnew']) {
sh 'scp -o StrictHostKeyChecking=no /var/lib/jenkins/workspace/TomcatDeploypipeline/target/addressbook.war ec2-user@3.129.17.201:/opt/tomcat/webapps'
}
}
}
}
}