Thursday 27 December 2012

Amazon EC2 Basics (Part 1.2)


To install a regular Apache version of Tomcat 7 (c.f., the version found in the Amazon repository described in Part 1):
  • If you installed Tomcat by following Part 1, stop the currently running Tomcat service:
    • sudo service tomcat7 stop
    • sudo chkconfig tomcat7 off
    • chkconfig --list (check that everything is off)
  • Get the Apache Tomcat repo and untar it into the /opt directory in your filesystem:
    • cd /opt
    • sudo wget -c http://apache.mirror.iweb.ca/tomcat/tomcat-7/v7.0.34/bin/apache-tomcat-7.0.34.tar.gz (Go to the official Apache Tomcat website and get the URL of the binary version you want to work with. I have chosen apache-tomcat-7.0.34 here.)
    • sudo tar xvfz apache-tomcat-7.0.34.tar.gz
    • sudo ln -s /opt/apache-tomcat-version /opt/tomcat (This is optional. It creates a symbolic link to the directory.)
  • Create a user account to run Tomcat. If you installed Tomcat by following Part 1, then skip this step. Otherwise, run the following commands: 
    • sudo /usr/sbin/groupadd -g 91 -r tomcat
    • sudo /usr/sbin/useradd -c "Apache Tomcat" -u 91 -g tomcat -s /sbin/nologin -r -d /opt/apache-tomcat-7.0.34 tomcat
  • Change file permissions:
    • cd /opt/apache-tomcat-7.0.34
    • sudo chown -R root:apache-tomcat-7.0.34 *
    • sudo chmod -R go-w bin lib
    • sudo chmod -R g+rw conf logs temp webapps work
  • Create a start/stop script (preferably):
    • sudo vim /etc/init.d/tomcat
    • Type in:
    • #!/bin/sh
      # Baseline Apache Tomcat start/stop script
      #
      # chkconfig: 345 80 20
      # description: Apache Tomcat
      
      case $1 in
      start)
              /bin/su -s /bin/sh -l tomcat -c /opt/apache-tomcat-7.0.34/bin/startup.sh
              ;;
      stop)
              /bin/su -s /bin/sh -l tomcat -c /opt/apache-tomcat-7.0.34/bin/shutdown.sh
              ;;
      restart)
              /bin/su -s /bin/sh -l tomcat -c /opt/apache-tomcat-7.0.34/bin/shutdown.sh
              /bin/su -s /bin/sh -l tomcat -c /opt/apache-tomcat-7.0.34/bin/startup.sh
              ;;
      esac
      exit 0
    • sudo chmod go-w /etc/init.d/tomcat (Change permission of script file.)
  • Start Tomcat using the script:
    • sudo service tomcat start
  • You should be able to see the Tomcat manager on port 8080 of your instance! If you don't see it, make sure you change your Amazon security group permissions to allow access to port 8080. 
  • If you want to start Tomcat automatically on instance boot, type:
    • sudo /sbin/chkconfig --add tomcat
I personally chose to install the Apache version and not the Amazon version, because:
  • The Amazon version is a customised and only certain builds are available. 
  • The Amazon packages get upgraded when you update the system. This might break things.
  • Most of the help resources you find online refer to the Apache version.
(This post is based on this article.)

No comments:

Post a Comment