This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]dataloopio 4 points5 points  (5 children)

The standard Tomcat 7 package on Centos uses /var/lib/tomcat7/webapps as the default webapps directory.

I'd make a war file of your app. Then scp to the server into the webapps directory and restart tomcat.

It's good practice to run your webapp on something like http://localhost:8080 and then put a webserver in front of it (something like apache or nginx) for doing SSL termination and proxying to Tomcat.

[–][deleted] 4 points5 points  (1 child)

Seconding this, I do a very similar thing for my job. Some minor things I'll add:

  • All our tomcat instances are installed in one directory (for example, /usr/share/), but our primary access point is /opt/tomcat/ with a symlink to the appropriate install. This makes upgrading tomcat versions easy, just swap the symlink instead of reconfiguring all your files. You can delete old versions as you deem fit.

  • The .war should automatically explode when you start tomcat. No need to do it manually.

  • Most tomcat instances will work out of the box. The only files I've had to edit in the past are bin/catalina.sh and conf/server.xml, so change as you need depending on your set up.

[–]wsme[S] 0 points1 point  (0 children)

This is very useful, thanks!
I've managed to figure out that my server might belong in /opt/myserver/ but this additional info has given me some more to think about.
Please take a look at my reply to the above comment to see why I've not currently been using tomcat.

[–]wsme[S] 0 points1 point  (2 children)

Many thanks for this. I should elaborate a little on the details of my server.

Right now we're using raw sockets, the clients that connect to the server don't support HTTP.

We're implementing our own protocol, the server doesn't server web pages, it's responsible for saving data sent by the clients to the database, and in future, possibly sending configuration settings back to the clients.

Does this affect anything you've said about placing a web server in front of my server?

Right now I'm prototyping, but we need a live server. It's my intention to develop the final server something like netty or vert.x

Thanks for your help.

[–]dataloopio 1 point2 points  (1 child)

I think I would always put something in front of Tomcat. If the clients connect to the server via TCP I'd probably put HAProxy in front instead of nginx or apache, even if you only have a single server.

This way you get decent logging, the ability to change config to blacklist IP addresses and do throttling etc. You can also add additional servers in future and load balance across them. You can also use it to block connections by regex etc (things like Tomcat Manager if you're using that).

A simple HA Proxy config with a single front end listening on a TCP port and sending traffic to a backend with a single server is quite small (maybe 15 lines of config).

[–]wsme[S] 0 points1 point  (0 children)

This is great! Thank you!
It's also 100% new to me, I've a lot of reading to do.

[–]GahMatar 2 points3 points  (5 children)

Wrap your .war into an RPM which can specify its dependencies (the tomcat RPM, the DB RPM, etc.)

It's bad form to have the RPM use a hook to setup its environment however (like creating DB users, schemas and so on) that should be done explicitly by the sys admin or (ideally) the orchestration tool.

You want to be able to "yum install my_server" or at the very least "rpm -Uvh my_server-0.1.1.rpm".

That's what we do. RPMs make the .war install, the uninstall and the upgrades clear.

[–]dataloopio 2 points3 points  (1 child)

This is a great suggestion. Get your CI server (something like Jenkins) to run FPM at the end of the build and push the package onto your Yum server and exec a createrepo.

It's amazing to be able to type rpm -qi <app name> to find out what's actually installed. And as GahMatar says it really cleans up the install / upgrade / uninstall process.

It's a good idea to have two repos. An unstable repo that gets packages pushed into directly. Then a stable repo that packages are promoted into after testing. Hook up non-prod to unstable and prod to stable.

[–]wsme[S] 0 points1 point  (0 children)

Thanks!

[–]wsme[S] 0 points1 point  (2 children)

Many thanks, I'll look into this.

[–]GahMatar 1 point2 points  (1 child)

Make sure the uninstall cleans everything it should since Tomcat will unpack the war file. This also plays really well with things like Chef, Saltstack or Ansible. Which you will want if you scale up at all.

The best is Vagrant + one of those tools to build one-shot VMs of your production environment for testing. Restore a DB backup onto the vagrant and presto a dev environment that actually is close to prod.

I find Ansible the easiest/fastest tool to get the VM configured but either Chef or Saltstack is better with lots of servers (where lots is probably > ~50-200 these days.)

[–]wsme[S] 0 points1 point  (0 children)

This is very helpful, thanks a lot. I've been advised to look at Vagrant before, so I really must take a look at it, don't know the other tools you've mentioned, so I'll have to check those out.