{"id":410,"date":"2015-11-17T09:14:42","date_gmt":"2015-11-17T09:14:42","guid":{"rendered":"http:\/\/onlinelab.info\/?p=410"},"modified":"2015-11-17T09:14:42","modified_gmt":"2015-11-17T09:14:42","slug":"install-tomcat-8-on-centos-rhel-or-fedora","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2015\/11\/17\/install-tomcat-8-on-centos-rhel-or-fedora\/","title":{"rendered":"Install Tomcat 8 on CentOS, RHEL, or Fedora"},"content":{"rendered":"<div><b>Step 1: Install JDK 1.7<\/b><\/div>\n<div><\/div>\n<p>You can download the latest JDK here: <a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html<\/a><\/p>\n<p>We&#8217;ll install JDK 7, Update 60 (7u60). The JDK is specific to 32 and 64 bit versions.<\/p>\n<p>My CentOS box is 64 bit, so I&#8217;ll need: jdk-7u60-linux-x64.tar.gz.<\/p>\n<p>If you are on 32 bit, you&#8217;ll need: jdk-7u60-linux-i586.tar.gz<\/p>\n<p>Start by creating a new directory \/usr\/java:<\/p>\n<blockquote><p>[root@srv6\u00a0~]#\u00a0mkdir\u00a0\/usr\/java<\/p><\/blockquote>\n<p>Change to the \/usr\/java directory we created<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0~]#\u00a0cd\u00a0\/usr\/java<\/p>\n<p>[root@srv6\u00a0java\u00a0]#<\/p><\/blockquote>\n<\/div>\n<p><a href=\"http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html\" target=\"_blank\" rel=\"noopener\">Download<\/a> the appropriate JDK and save it to \/usr\/java directory we created above.<\/p>\n<p>Unpack jdk-7u60-linux-x64.tar.gz in the \/usr\/java directory using tar -xzf:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0java]#\u00a0tar\u00a0-xzf\u00a0jdk-7u60-linux-x64.tar.gz<\/p><\/blockquote>\n<\/div>\n<p>This will create the directory \/usr\/java\/jdk1.7.0_60. This will be our JAVA_HOME.<\/p>\n<p>We can now set JAVA_HOME and put Java into the path of our users.<\/p>\n<p>To set it for your current session, you can issue the following from the CLI:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0java]#\u00a0JAVA_HOME=\/usr\/java\/jdk1.7.0_60<\/p>\n<p>[root@srv6\u00a0java]#\u00a0<span class=\"keyword\">export<\/span>\u00a0JAVA_HOME<\/p>\n<p>[root@srv6\u00a0java]#\u00a0PATH=$JAVA_HOME\/bin:$PATH<\/p>\n<p>[root@srv6\u00a0java]#\u00a0<span class=\"keyword\">export<\/span>\u00a0PATH<\/p><\/blockquote>\n<\/div>\n<p>To set the JAVA_HOME permanently, however, we need to add below to the ~\/.bash_profile of the user (in this case, root).<br \/>\nWe can also add it \/etc\/profile and then source it to give to all users.<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>JAVA_HOME=\/usr\/java\/jdk1.7.0_60<\/p>\n<p><span class=\"keyword\">export<\/span>\u00a0JAVA_HOME<\/p>\n<p>PATH=$JAVA_HOME\/bin:$PATH<\/p>\n<p><span class=\"keyword\">export<\/span>\u00a0PATH<\/p><\/blockquote>\n<\/div>\n<p>Once you have added the above to ~\/.bash_profile, you should log out, then log back in and check that the JAVA_HOME is set correctly.<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0~]#\u00a0\u00a0echo\u00a0$JAVA_HOME<\/p>\n<p>\/usr\/java\/jdk1.7.0_60<\/p><\/blockquote>\n<\/div>\n<p><i>Note: If you decided to use JDK 6 rather than 7 as we did above, simply save the JDK 6 bin file to \/opt (or another location), then navigate to \/usr\/java and issue:<\/i> &#8216;sh \/opt\/jdk-6u33-linux-x64.bin&#8217;. <i>This will create a JAVA Home of \/usr\/java\/jdk1.6.0.33 <\/i><\/p>\n<div><b>Step 2: Download and Unpack Tomcat 8.0.8 (or latest)<\/b><\/div>\n<p>We will install Tomcat 8 under \/usr\/share.<\/p>\n<p>Switch to the \/usr\/share directory:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0~]#\u00a0cd\u00a0\/usr\/share<\/p>\n<p>[root@srv6\u00a0share\u00a0]#<\/p><\/blockquote>\n<\/div>\n<p>Download apache-tomcat-8.0.8.tar.gz (or the latest version) <a href=\"http:\/\/tomcat.apache.org\/download-80.cgi\" target=\"_blank\" rel=\"noopener\">here<\/a><\/p>\n<p>and save it to \/usr\/share<\/p>\n<p>Once downloaded, you should verify the MD5 Checksum for your Tomcat download using the md5sum command.<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0share\u00a0]#\u00a0md5sum\u00a0apache-tomcat-8.0.8.tar.gz<\/p>\n<p>c377b34fc4d228a63f7f1a51efbec333\u00a0*apache-tomcat-8.0.8.tar.gz<\/p><\/blockquote>\n<\/div>\n<p>Compare the output above to the MD5 Checksum provided next to <a href=\"http:\/\/tomcat.apache.org\/download-70.cgi\" target=\"_blank\" rel=\"noopener\">the download link<\/a> and you used above and check that it matches.<\/p>\n<p>unpack the file using tar -xzf:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0share\u00a0]#\u00a0tar\u00a0-xzf\u00a0apache-tomcat-8.0.8.tar.gz<\/p><\/blockquote>\n<\/div>\n<p>This will create the directory \/usr\/share\/apache-tomcat-8.0.8<\/p>\n<div><b>Step 3: Configure Tomcat to Run as a Service.<\/b><\/div>\n<p>We will now see how to run Tomcat as a service and create a simple Start\/Stop\/Restart script, as well as to start Tomcat at boot.<\/p>\n<p>Change to the \/etc\/init.d directory and create a script called &#8216;tomcat&#8217; as shown below.<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0share]#\u00a0cd\u00a0\/etc\/init.d<\/p>\n<p>[root@srv6\u00a0init.d]#\u00a0vi\u00a0tomcat<\/p><\/blockquote>\n<\/div>\n<p>And here is the script we will use.<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p><span class=\"preprocessor\">#!\/bin\/bash<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0description:\u00a0Tomcat\u00a0Start\u00a0Stop\u00a0Restart<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0processname:\u00a0tomcat<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0chkconfig:\u00a0234\u00a020\u00a080<\/span><\/p>\n<p>JAVA_HOME=\/usr\/java\/jdk1.7.0_60<\/p>\n<p><span class=\"keyword\">export<\/span>\u00a0JAVA_HOME<\/p>\n<p>PATH=$JAVA_HOME\/bin:$PATH<\/p>\n<p><span class=\"keyword\">export<\/span>\u00a0PATH<\/p>\n<p>CATALINA_HOME=\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p><span class=\"keyword\">case<\/span>\u00a0$1\u00a0<span class=\"keyword\">in<\/span><\/p>\n<p>start)<\/p>\n<p>sh\u00a0$CATALINA_HOME\/bin\/startup.sh<\/p>\n<p>;;<\/p>\n<p>stop)<\/p>\n<p>sh\u00a0$CATALINA_HOME\/bin\/shutdown.sh<\/p>\n<p>;;<\/p>\n<p>restart)<\/p>\n<p>sh\u00a0$CATALINA_HOME\/bin\/shutdown.sh<\/p>\n<p>sh\u00a0$CATALINA_HOME\/bin\/startup.sh<\/p>\n<p>;;<\/p>\n<p>esac<\/p>\n<p>exit\u00a00<\/p><\/blockquote>\n<\/div>\n<p>The above script is simple and contains all of the basic elements you will need to get going.<\/p>\n<p>As you can see, we are simply calling the startup.sh and shutdown.sh scripts located in the Tomcat bin directory (\/usr\/share\/apache-tomcat-8.0.8\/bin).<\/p>\n<p>You can adjust your script according to your needs and, in subsequent posts, we&#8217;ll look at additional examples.<\/p>\n<p>CATALINA_HOME is the Tomcat home directory (\/usr\/share\/apache-tomcat-8.0.8)<\/p>\n<p>Now, set the permissions for your script to make it executable:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0init.d]#\u00a0chmod\u00a0755\u00a0tomcat<\/p><\/blockquote>\n<\/div>\n<p>We now use the chkconfig utility to have Tomcat start at boot time. In my script above, I am using chkconfig: 234 20 80. 2345 are the run levels and 20 and 80 are the stop and start priorities respectively. You can adjust as needed.<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0init.d]#\u00a0chkconfig\u00a0&#8211;add\u00a0tomcat<\/p>\n<p>[root@srv6\u00a0init.d]#\u00a0chkconfig\u00a0&#8211;level\u00a0234\u00a0tomcat\u00a0on<\/p><\/blockquote>\n<\/div>\n<p>Verify it:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0init.d]#\u00a0chkconfig\u00a0&#8211;list\u00a0tomcat<\/p>\n<p>tomcat\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a00:off\u00a0\u00a0\u00a01:off\u00a0\u00a0\u00a02:on\u00a0\u00a0\u00a0\u00a03:on\u00a0\u00a0\u00a0\u00a04:on\u00a0\u00a0\u00a0\u00a05:off\u00a0\u00a0\u00a06:off<\/p><\/blockquote>\n<\/div>\n<p>Now, let&#8217;s test our script.<\/p>\n<p>Start Tomcat:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0~]#\u00a0service\u00a0tomcat\u00a0start<\/p>\n<p>Using\u00a0CATALINA_BASE:\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p>Using\u00a0CATALINA_HOME:\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p>Using\u00a0CATALINA_TMPDIR:\u00a0\/usr\/share\/apache-tomcat-8.0.8\/temp<\/p>\n<p>Using\u00a0JRE_HOME:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/usr\/java\/jdk1.7.0_60<\/p>\n<p>Using\u00a0CLASSPATH:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8\/bin\/bootstrap.jar:\/usr\/share\/apache-tomcat-8.0.8\/bin\/tomcat-juli.jar<\/p><\/blockquote>\n<\/div>\n<p>Stop Tomcat:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0~]#\u00a0service\u00a0tomcat\u00a0stop<\/p>\n<p>Using\u00a0CATALINA_BASE:\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p>Using\u00a0CATALINA_HOME:\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p>Using\u00a0CATALINA_TMPDIR:\u00a0\/usr\/share\/apache-tomcat-8.0.8\/temp<\/p>\n<p>Using\u00a0JRE_HOME:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/usr\/java\/jdk1.7.0_60<\/p>\n<p>Using\u00a0CLASSPATH:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8\/bin\/bootstrap.jar:\/usr\/share\/apache-tomcat-8.0.8\/bin\/tomcat-juli.jar<\/p><\/blockquote>\n<\/div>\n<p>Restarting Tomcat (Must be started first):<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0~]#\u00a0service\u00a0tomcat\u00a0restart<\/p>\n<p>Using\u00a0CATALINA_BASE:\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p>Using\u00a0CATALINA_HOME:\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p>Using\u00a0CATALINA_TMPDIR:\u00a0\/usr\/share\/apache-tomcat-8.0.8\/temp<\/p>\n<p>Using\u00a0JRE_HOME:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/usr\/java\/jdk1.7.0_60<\/p>\n<p>Using\u00a0CLASSPATH:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8\/bin\/bootstrap.jar:\/usr\/share\/apache-tomcat-8.0.8\/bin\/tomcat-juli.jar<\/p>\n<p>Using\u00a0CATALINA_BASE:\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p>Using\u00a0CATALINA_HOME:\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8<\/p>\n<p>Using\u00a0CATALINA_TMPDIR:\u00a0\/usr\/share\/apache-tomcat-8.0.8\/temp<\/p>\n<p>Using\u00a0JRE_HOME:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/usr\/java\/jdk1.7.0_60<\/p>\n<p>Using\u00a0CLASSPATH:\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/usr\/share\/apache-tomcat-8.0.8\/bin\/bootstrap.jar:\/usr\/share\/apache-tomcat-8.0.8\/bin\/tomcat-juli.jar<\/p><\/blockquote>\n<\/div>\n<p>We should review the Catalina.out log located at \/usr\/share\/apache-tomcat-8.0.8\/logs\/catalina.out and check for any errors.<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0init.d]#\u00a0more\u00a0\/usr\/share\/apache-tomcat-8.0.8\/logs\/catalina.out<\/p><\/blockquote>\n<\/div>\n<p>We can now access the Tomcat Manager page at:<\/p>\n<blockquote><p>http:\/\/yourdomain.com:8080 or http:\/\/yourIPaddress:8080<\/p><\/blockquote>\n<p>and we should see the Tomcat home page.<\/p>\n<div><b>Step 4: Configuring Tomcat Manager Access.<\/b><\/div>\n<p>Tomcat 8 contains a number of changes that offer finer-grain roles.<\/p>\n<p>For security reasons, no users or passwords are created for the Tomcat manager roles by default. In a production deployment, it is always best to remove the Manager application.<\/p>\n<p>To set roles, user name(s) and password(s), we need to configure the tomcat-users.xml file located at $CATALINA_HOME\/conf\/tomcat-users.xml.<\/p>\n<p>In the case of our installation, $CATALINA_HOME is located at \/usr\/share\/apache-tomcat-8.0.8.<\/p>\n<p>By default the Tomcat 8 tomcat-users.xml file will have the elements between the and tags commented-out. .<\/p>\n<p>New roles for Tomcat 8 offer finer-grained access and The following roles are now available:<\/p>\n<blockquote><p>manager-gui<br \/>\nmanager-status<br \/>\nmanager-jmx<br \/>\nmanager-script<br \/>\nadmin-gu<br \/>\nadmin-script.<\/p><\/blockquote>\n<p>We can set the manager-gui role, for example as below<\/p>\n<p>&nbsp;<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>&lt;role rolename=&#8221;manager-script&#8221;\/&gt;<br \/>\n&lt;role rolename=&#8221;manager-gui&#8221;\/&gt;<br \/>\n&lt;role rolename=&#8221;admin-gui&#8221;\/&gt;<br \/>\n&lt;role rolename=&#8221;manager-status&#8221;\/&gt;<br \/>\n&lt;user username=&#8221;admin&#8221; password=&#8221;admin&#8221; roles=&#8221;manager-gui,manager-script,admin-gui,manager-status&#8221;\/&gt;<\/p><\/blockquote>\n<\/div>\n<p>Caution should be exercised in granting multiple roles so as not to under-mind security.<\/p>\n<div><b>Step 5 (Oprtional): Manage Memory Usage Using JAVA_OPTS.<\/b><\/div>\n<p>Getting the right heap memory settings for your installation will depend on a number of factors.<\/p>\n<p>For simplicity, we will set our inital heap size, Xms, and our maximum heap size, Xmx, to the same value of 128 Mb<\/p>\n<p>Simliarly, there are several approaches you can take as to where and how you set your JAVA_OPTS<\/p>\n<p>Again, for simplicity, we will add our JAVA_OPTS memory parameters in our Catalina.sh file.<\/p>\n<p>So, open the Catalina.sh file located under \/usr\/share\/apache-tomcat-8.0.8\/bin with a text editor or vi.<\/p>\n<p>Since we are using 128 Mb for both initial and maximum heap size, add the following line to Catalina.sh<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>JAVA_OPTS=<span class=\"string\">&#8220;-Xms128m\u00a0-Xmx128m&#8221;<\/span><\/p><\/blockquote>\n<\/div>\n<p>I usually just add this in the second line of the file so it looks as so:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p><span class=\"preprocessor\">#!\/bin\/sh<\/span><\/p>\n<p>JAVA_OPTS=<span class=\"string\">&#8220;-Xms128m\u00a0-Xmx128m&#8221;<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0Licensed\u00a0to\u00a0the\u00a0Apache\u00a0Software\u00a0Foundation\u00a0(ASF)\u00a0under\u00a0one\u00a0or\u00a0more<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0contributor\u00a0license\u00a0agreements.\u00a0\u00a0See\u00a0the\u00a0NOTICE\u00a0file\u00a0distributed\u00a0with<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0this\u00a0work\u00a0for\u00a0additional\u00a0information\u00a0regarding\u00a0copyright\u00a0ownership.<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0The\u00a0ASF\u00a0licenses\u00a0this\u00a0file\u00a0to\u00a0You\u00a0under\u00a0the\u00a0Apache\u00a0License,\u00a0Version\u00a02.0<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0(the\u00a0&#8220;License&#8221;);\u00a0you\u00a0may\u00a0not\u00a0use\u00a0this\u00a0file\u00a0except\u00a0in\u00a0compliance\u00a0with<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0the\u00a0License.\u00a0\u00a0You\u00a0may\u00a0obtain\u00a0a\u00a0copy\u00a0of\u00a0the\u00a0License\u00a0at<\/span><\/p><\/blockquote>\n<\/div>\n<p>&nbsp;<\/p>\n<div><\/div>\n<div><b>Step 6 (Optional): How to Run Tomcat using Minimally Privileged (non-root) User.<\/b><\/div>\n<p>In our Tomcat configuration above, we are running Tomcat as Root.<\/p>\n<p>For security reasons, it is always best to run services with the only those privileges that are necessary.<\/p>\n<p>There are some who make a strong case that this is not required, but it&#8217;s always best to err on the side of caution.<\/p>\n<p>To run Tomcat as non-root user, we need to do the following:<\/p>\n<p>1. Create the group &#8216;tomcat&#8217;:<\/p>\n<div class=\"dp-highlighter\">\n<ol class=\"dp-c\" start=\"1\">\n<li class=\"alt\">[root@srv6\u00a0~]#\u00a0groupadd\u00a0tomcat<\/li>\n<\/ol>\n<\/div>\n<p>2. Create the user &#8216;tomcat&#8217; and add this user to the tomcat group we created above.<\/p>\n<div class=\"dp-highlighter\">\n<ol class=\"dp-c\" start=\"1\">\n<li class=\"alt\">[root@srv6\u00a0~]#\u00a0useradd\u00a0-s\u00a0\/bin\/bash\u00a0-g\u00a0tomcat\u00a0tomcat<\/li>\n<\/ol>\n<\/div>\n<p>The above will create a home directory for the user tomcat in the default user home as \/home\/tomcat<\/p>\n<p>If we want the home directory to be elsewhere, we simply specify so using the -d switch.<\/p>\n<div class=\"dp-highlighter\">\n<ol class=\"dp-c\" start=\"1\">\n<li class=\"alt\">[root@srv6\u00a0~]#\u00a0useradd\u00a0-g\u00a0tomcat\u00a0-d\u00a0\/usr\/share\/apache-tomcat-8.0.8\/tomcat\u00a0tomcat<\/li>\n<\/ol>\n<\/div>\n<p>The above will create the user tomcat&#8217;s home directory as \/usr\/share\/apache-tomcat-8.0.8\/tomcat<\/p>\n<p>3. Change ownership of the tomcat files to the user tomcat we created above:<\/p>\n<div class=\"dp-highlighter\">\n<ol class=\"dp-c\" start=\"1\">\n<li class=\"alt\">[root@srv6\u00a0~]#\u00a0chown\u00a0-Rf\u00a0tomcat.tomcat\u00a0\/usr\/share\/apache-tomcat-8.0.8\/<\/li>\n<\/ol>\n<\/div>\n<p>Note: it is possible to enhance our security still further by making certain files and directories read-only. This will not be covered in this post and care should be used when setting such permissions.<\/p>\n<p>4. Adjust the start\/stop service script we created above. In our new script, we need to su to the user tomcat:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p><span class=\"preprocessor\">#!\/bin\/bash<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0description:\u00a0Tomcat\u00a0Start\u00a0Stop\u00a0Restart<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0processname:\u00a0tomcat<\/span><\/p>\n<p><span class=\"preprocessor\">#\u00a0chkconfig:\u00a0234\u00a020\u00a080<\/span><\/p>\n<p>JAVA_HOME=\/usr\/java\/jdk1.7.0_60<\/p>\n<p><span class=\"keyword\">export<\/span>\u00a0JAVA_HOME<\/p>\n<p>PATH=$JAVA_HOME\/bin:$PATH<\/p>\n<p><span class=\"keyword\">export<\/span>\u00a0PATH<\/p>\n<p>CATALINA_HOME=\/usr\/share\/apache-tomcat-8.0.8\/bin<\/p>\n<p><span class=\"keyword\">case<\/span>\u00a0$1\u00a0<span class=\"keyword\">in<\/span><\/p>\n<p>start)<\/p>\n<p>\/bin\/su\u00a0tomcat\u00a0$CATALINA_HOME\/startup.sh<\/p>\n<p>;;<\/p>\n<p>stop)<\/p>\n<p>\/bin\/su\u00a0tomcat\u00a0$CATALINA_HOME\/shutdown.sh<\/p>\n<p>;;<\/p>\n<p>restart)<\/p>\n<p>\/bin\/su\u00a0tomcat\u00a0$CATALINA_HOME\/shutdown.sh<\/p>\n<p>\/bin\/su\u00a0tomcat\u00a0$CATALINA_HOME\/startup.sh<\/p>\n<p>;;<\/p>\n<p>esac<\/p>\n<p>exit\u00a00<\/p><\/blockquote>\n<\/div>\n<p>&nbsp;<\/p>\n<div><b>Step 7 (Optional): How to Run Tomcat on Port 80 as Non-Root User.<\/b><\/div>\n<p>Note: the following applies when you are running Tomcat in &#8220;stand alone&#8221; mode with Tomcat running under the minimally privileged user Tomcat we created in the previous step.<\/p>\n<p>To run services below port 1024 as a user other than root, you can add the following to your IP tables:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>[root@srv6\u00a0~]#\u00a0iptables\u00a0-t\u00a0nat\u00a0-A\u00a0PREROUTING\u00a0-p\u00a0tcp\u00a0-m\u00a0tcp\u00a0&#8211;dport\u00a080\u00a0-j\u00a0REDIRECT\u00a0&#8211;to-ports\u00a08080<\/p>\n<p>[root@srv6\u00a0~]#\u00a0iptables\u00a0-t\u00a0nat\u00a0-A\u00a0PREROUTING\u00a0-p\u00a0udp\u00a0-m\u00a0udp\u00a0&#8211;dport\u00a080\u00a0-j\u00a0REDIRECT\u00a0&#8211;to-ports\u00a08080<\/p><\/blockquote>\n<\/div>\n<p>Be sure to save and restart your IP Tables.<\/p>\n<div><b>Step 8 (Optional): Running Tomcat behind Apache<\/b><\/div>\n<p>As an alternative to running Tomcat on port 80, if you have Apache in front of Tomcat, you can use mod_proxy as well as ajp connector to map your domain to your Tomcat application(s) using an Apache vhost as shown below.<\/p>\n<p>While Tomcat has improved it&#8217;s &#8216;standalone performance&#8217;, I still prefer to have Apace in front of it for a number of reasons.<\/p>\n<p>In your Apache config, be sure to set KeepAlive to &#8216;on&#8217;. Apache tuning, of course, is a whole subject in itself&#8230;<\/p>\n<p><b>Example 1: VHOST with mod_proxy:<\/b><\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>&lt;VirtualHost\u00a0*:80&gt;<\/p>\n<p>ServerAdmin\u00a0admin@yourdomain.com<\/p>\n<p>ServerName\u00a0yourdomain.com<\/p>\n<p>ServerAlias\u00a0www.yourdomain.com<\/p>\n<p>ProxyRequests\u00a0Off<\/p>\n<p>ProxyPreserveHost\u00a0On<\/p>\n<p>&lt;Proxy\u00a0*&gt;<\/p>\n<p>Order\u00a0allow,deny<\/p>\n<p>Allow\u00a0from\u00a0all<\/p>\n<p>&lt;\/Proxy&gt;<\/p>\n<p>ProxyPass\u00a0\/\u00a0http:<span class=\"comment\">\/\/localhost:8080\/<\/span><\/p>\n<p>ProxyPassReverse\u00a0\/\u00a0http:<span class=\"comment\">\/\/localhost:8080\/<\/span><\/p>\n<p>ErrorLog\u00a0logs\/yourdomain.com-error_log<\/p>\n<p>CustomLog\u00a0logs\/yourdomain.com-access_log\u00a0common<\/p>\n<p>\/VirtualHost&gt;<\/p><\/blockquote>\n<\/div>\n<p><b>Example 2: VHOST with ajp connector and mod_proxy:<\/b><\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>&lt;VirtualHost\u00a0*:80&gt;<\/p>\n<p>ServerAdmin\u00a0admin@yourdomain.com<\/p>\n<p>ServerName\u00a0yourdomain.com<\/p>\n<p>ServerAlias\u00a0www.yourdomain.com<\/p>\n<p>ProxyRequests\u00a0Off<\/p>\n<p>ProxyPreserveHost\u00a0On<\/p>\n<p>&lt;Proxy\u00a0*&gt;<\/p>\n<p>Order\u00a0allow,deny<\/p>\n<p>Allow\u00a0from\u00a0all<\/p>\n<p>&lt;\/Proxy&gt;<\/p>\n<p>ProxyPass\u00a0\/\u00a0ajp:<span class=\"comment\">\/\/localhost:8009\/<\/span><\/p>\n<p>ProxyPassReverse\u00a0\/\u00a0ajp:<span class=\"comment\">\/\/localhost:8009\/<\/span><\/p>\n<p>ErrorLog\u00a0logs\/yourdomain.com-error_log<\/p>\n<p>CustomLog\u00a0logs\/yourdomain.com-access_log\u00a0common<\/p>\n<p>&lt;\/VirtualHost&gt;<\/p><\/blockquote>\n<\/div>\n<p>In both vhost examples above, we are &#8220;mapping&#8221; the domain to Tomcat&#8217;s ROOT directory.<\/p>\n<p>If we wish to map to an application such as yourdomain.com\/myapp, we can add some rewrite as shown below.<\/p>\n<p>This will rewrite all requests for yourdomain.com to yourdomain.com\/myapp.<\/p>\n<p><b>Example 3: VHOST with rewrite<\/b>:<\/p>\n<div class=\"dp-highlighter\">\n<blockquote><p>&lt;VirtualHost\u00a0*:80&gt;<\/p>\n<p>ServerAdmin\u00a0admin@yourdomain.com<\/p>\n<p>ServerName\u00a0yourdomain.com<\/p>\n<p>ServerAlias\u00a0www.yourdomain.com<\/p>\n<p>RewriteEngine\u00a0On<\/p>\n<p>RewriteRule\u00a0^\/$\u00a0myapp\/\u00a0[R=301]<\/p>\n<p>ProxyRequests\u00a0Off<\/p>\n<p>ProxyPreserveHost\u00a0On<\/p>\n<p>&lt;Proxy\u00a0*&gt;<\/p>\n<p>Order\u00a0allow,deny<\/p>\n<p>Allow\u00a0from\u00a0all<\/p>\n<p>&lt;\/Proxy&gt;<\/p>\n<p>ProxyPass\u00a0\/\u00a0ajp:<span class=\"comment\">\/\/localhost:8009\/<\/span><\/p>\n<p>ProxyPassReverse\u00a0\/\u00a0ajp:<span class=\"comment\">\/\/localhost:8009\/<\/span><\/p>\n<p>ErrorLog\u00a0logs\/yourdomain.com-error_log<\/p>\n<p>CustomLog\u00a0logs\/yourdomain.com-access_log\u00a0common<\/p><\/blockquote>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Step 1: Install JDK 1.7 You can download the latest JDK here: http:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html We&#8217;ll install JDK 7, Update 60 (7u60). The JDK is specific to 32 and 64 bit versions. My CentOS box is 64&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,3],"tags":[],"class_list":["post-410","post","type-post","status-publish","format-standard","hentry","category-he-thong","category-linux"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/comments?post=410"}],"version-history":[{"count":0,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/410\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}