Install Tomcat 8 on Ubuntu 14.04 (3 of 3)

I’m Patrick Bailey with whiteboard coder calm today is August 14 2015 and in this video i’ll be going over how to install and setup Tomcat 8 on a bun to 1404 this video went a lot longer than I thought it would as a result I did split it up into three videos this is the third part of the video if you want to go to the first part the second part click on the links to those videos now can now need to fix something if I do a cat on my logs I grab for the capr there’s a PR there we go when I was looking through my logs before when I was writing up this tutorial i noticed this a PR event kept coming up and really you can read up on this but there’s an APR tool that does some native things help speed things up so you might as well I want to include this the process to clean up tom cat just to kind of get it done completely to fix the APR it’s not really an air it’s more but warning what you do go to my home directory and i’ll do a make this wider ok let’s do a double you get on this big long monster but i’ll put this in the show notes so you can always look up on tomcat apache and they’ll talk about this APR tool but this is the native linux tool so you can grab it ontar it see into the directory how to do see DJ and I native there we go so get into the native directory and then you have to do some fun stuff because there’s some issues with the where it’s expecting things to be especially with the Oracle Java I guess so you want to do you set up some symlinks you know i’m gonna copy and paste this because it’s nothing right if I don’t I’m gonna miss type something they’re just missing some folders in the wrong place so you just have to run a few commands to make some symlinks to make this tool happy okay so that’s done so now here is the fun part you have to configure it so doc configure with Java home equals user JVM java java 7 Oracle with ap R equals user in apr1 config with OS type equals clewd licks hope I did something wrong with primers and correct you know that’s right I just forgot to actually bother to install the tools so sudo apt-get install lib apr1 and live a PR util 15 APR one dash dev and live slf dev and make so install those guys oh live a PR and the Ergo spell it the right way there we go ok let all those guys install okay now those are installed I should build 20 I mean copy and paste that so you can read that again you should be able to run this configure because now the files are actually there see if she works ah now it’s happier okay good so now we run make and so I’ll make install okay and then finally going to make a symlink let’s

see it’s a user local APR lib that guy to user lib lib TC native and copy this down on I’m going to miss type something okay there we go now we should be good so now let me go sudo service tomcat stop oh I’m kidding no speaking up let me go while I was trying to fix that thing I added some stuff okay pseudo so choose our dash Tom dash command added some stuff to the catalina out in case I might have thi might have cut that other video but let me go fix those real quick Kelly not SH I mean up we’re not trying to debug this I added all these guys remove those real quick so they’re not and i think i added something yep testing edit those guys too if you don’t have those you want me to remove my just added those when I was trying to debug it ok so now it should be should be running a smile running perfect I need to remove the log file remove the log file because now i want to see if the APR issue comes back so we start it and if it’s already started so we can like that okay no air so we fixed it alright so that’s how you get that a PR guy fixed okay next thing tomcat users okay again as the tomcat user you want to edit those documents edit the you want to edit the tomcat dash users at xml file which is an app’s Tomcat 8 com and now lower you can’t see it because i’m at the tomcat user but there is a file called tomcat users dot XML and so open it to edit it and I’m just going to kind of wipe it out and paste in my own now you can read up on a lot on how to set this up it’s just very bare-bones basic so most of these users and there’s a manager gooey and an admin gooey and the admin for this purpose he’s gonna have the password my password you know please don’t use that for your life system very bad because someone can login with admin and my password but just for testing purposes there we go so this admin is going to there’s his name his admin his passwords my password his role Gilliam manager gooey which should give him access to the GUI so I killed up and i’ll restart it I don’t know a thing with services it will tab complete who on that ok so we started and let me go I’ll put up my web browser again and so now able to go into server status I can login as admin in my password jump save your password and there we go so we can see some of our settings that took place there’s a heap memory is our

maximum oh that’s our old generation yeah that makes sense 5 12 right there right yeah from gen 2 episode 2 26 where’s my mac i’m here help there we go physical memory yeah it looks right ok and go back here and go into manager apps and there’s my current running apps now the default tom cat has examples and we don’t want to get rid of that and documents we don’t care about those but that gets you access to all this stuff ok next I need to edit is the server.xml file and again as the tomcat user apps tomcat and again you can’t see it so i just got to tighten that last bit ok not gay i’m just going to delete this because i have my own which is pretty close to what the actual one is and I’ll kind of go through what I did a little bit okay let’s see what I did different here most this is the same pretty much the same same pretty much the same here still listen port 8080 and 8443 still 809 here’s what I changed now this is interesting here because you can auto deploy war files so what this is set up to right now our base web app rat bases web apps the folder web apps and I said unpack any war files to true and auto deploy to true what this will do is if you put a wharf I on the web apps folder it will unpack automatically and it will auto deploy it so i’ll save that now we want to deploy something and I’ve since I’m working with Jenkins right now and figuring out how to do some deploys i’m going to deploy a Jenkins war file first let’s go to one hour tomcat web apps folder and if i look in here real quick we’ll see there’s the docs and examples and we really don’t need those so i’m just going to remove them no reason to keep them around okay now there’s a couple ways we can do this on installation but i did set our server up so that we can install merely by dropping a war file in there it’ll unpack it deployed on its own now i did some tests and you can just drop a war file in there while we’ve started running live and it will deploy it but it’s probably not the good best idea because as it downloads it tries to deploy it a couple of times and if you’re trying to redeploy something that’s already there it works but probably not the cleanest way to do it well it may be fine but in general i’m just going to terminate and this is not the only way to deploy war file is just the way i’m using right now and so we’ll stop Tomcat say go over here to the jenkins website click on long-term support release and then right click on the older but stable here war file and copy link address and then what you did what you do to do a pseudo switch user switch the tomcat and for the command duo w get there we go we do this week actually read it try it again just a tomcat run the command WK and we’ll get the latest jenkins war file and then you can place it with HP where you want to go and so we want to drop it in the web apps directory and that should do that ok so that grabs the file and downloads now we should have it let me look here real quick so there’s the chain contort file Tomcat hounds it so now what I’m going to do I’m going to shrink this down a bit and I’m going to tail the

Tomcat file to show us to show it being deployed okay then I’m come over here and on the same server makes a little bigger hard to see and start snap should start up and at some point it should grab up started grabbing it is deploying the war file right there there goes look it’s doing some drinking stuff now now if I look real quick there’s my drinking folder and if I go pull up my web my tomcat here I can go to Jenkins and let’s see if it deployed it and there you go drinkies is deployed simple as that okay two last things before i end this i thought i was kind of done but there’s just two more important things i want to go over real quick one is visual vm so what you can do is you can go to visual vm and you click on downloads go over here and you can see here’s the visual vm zip file and just click on that and download it ok so i go here and click it show in folder real quick i got a bunch of junk you’re done I so extract all here click extract okay there we go so now going here and click on let’s see then visualvm it okay so double click on this guy click on run alright start up another screen okay there we go so what we want to do looks like it remembered so i’ll delete what you want to do is you go pair file and go ad jmx connection and you enter in the location in my case it’s 19 5 192 that’s mine doesn’t I need to read it to you you do your own okay and put in the port you put in for for your jmx i put in ninety 90 online click OK and then it should find it right there double click on that and now you can go monitor your jvm i’m not going to go into any detail on how to use this or what you can do but it’s a just want to show you it’s a useful tool and how to use it and to make sure that the tomcat that it can actually talk to the tomcat and actually really see what’s going on right now so there’s my JVM there’s my CP usage there’s my memory heap sizes all that good stuff okay close out of that other thing i wanted to go over real briefly as logrotate i’m not going to go into super detail just kind of kind of throw it out there what we can have it becomes a real pain if you don’t pay attention so here i have i have my catalina out right and that’s going to keep this is if i don’t do anything different to keep growing and growing and growing and growing so what I want to do is hit up a log rotate to low rotate that file daily even if I have enough room to maintain that file and just let it grow indefinitely it can be hard to search through or harder to know what’s going on and order have daily dated files so I just if I had a problem yesterday I can go look at yesterday’s file and grep through it and maybe find a problem find out what happened but anyway so i will create a rotate file so go i’ll go buy etc logrotate d tomcat this will be our tomcat log rotate i touch my make it tom kenny and then i’ll just cut and paste here and go over what’s important ok what we’ve done here and i’ve messed this up in the past before what this will do is this will do your date format on the file on the file as you rotate out and here’s the extension output dot it’ll add dot out to the end well it says what the actual extent it out I wanted to rotate daily if it’s missing its ok and i want to wrote to keep 30 days worth and here’s what the permissions i want on the newly

created file now the important thing here is this copy truncate and what that does basically says zero out the current file you know create a copy back up the daily then zero out the current file in place and so the tomcat does not have to relinquish control of that log files as if it just keeps logging to it it’s not aware that’s been zeroed out now this is done for several reasons but i recall at one point I had some man if it wasn’t a patchy or in Gen X I had some kind of web server log and so what I did I didn’t realize you could do that and so you can actually do some commands in here so actually I I might be recalling correctly but if I recall right I had some commands and here’s actually temporarily shut down shut down in Gen X so that you could rotate the log file which is kind of dumb this prevents you from doing that if you don’t do this tomcat still has hold of that dot out file the log file and it won’t let you rotate it and this won’t work so anyway you do that and that’s all you need to do because it’ll be picked up the next time cron job goes through chrono check every minute or so and well it’ll run the next time it’s supposed to run now you can do some checks you can do a pseudo logrotate HD log rotate conf and that will test it I’ll see what should run and I go up here and there it is and when you run that what it’ll see if the log needs to be rotated right now it’s also a nice task it says yeah there’s a Catalina doubt it doesn’t need to be run yet because the current file is not old enough because we just started it today another thing you can do you can see what logrotate what logs have recently been rotating by going keting VAR lib log rotate status and since I haven’t logged anything I haven’t rotated anything is really nothing there right now anyway I just wanted to cover those last two bits because um rotating your files or it’s really important not only for debugging but also you could keep running too many far too much data to your hard drive and we’ve all been there where we just fill up our data are we ignore it we set up our system life is great but then our hard drive gets full and we crash everything also it’s nice to have the visual vm in place and not to working in case you to debug stuff ok well that’s that’s it for this big long video tutorial on how to install and setup Tomcat 8 thanks for watching I hope this video was useful to you if it was please give it a like to subscribe just click the subscribe button also you can follow me on twitter under the handle at whiteboard coder view any code i may have put up as a gist on github under the username pat man denver or check out my blog at whiteboard coder calm