{"id":5083,"date":"2015-08-07T17:00:22","date_gmt":"2015-08-07T09:00:22","guid":{"rendered":"http:\/\/rmohan.com\/?p=5083"},"modified":"2015-08-07T17:02:17","modified_gmt":"2015-08-07T09:02:17","slug":"tomcat-8-on-centos-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5083","title":{"rendered":"Tomcat 8 on CentOS 7"},"content":{"rendered":"<div>The instructions below are assuming you&#8217;re logged in as root, if you are logged in as another user remember to prepend sudo to the commands shown below.<\/div>\n<div><\/div>\n<div>Install the necessary packages<br \/>\nFirst of all update your server and install the necessary packages using the following commands:<\/div>\n<div><\/div>\n<div>yum -y update<br \/>\nyum -y install curl libcap-devel<br \/>\nyum -y groupinstall &#8220;Development tools&#8221;<\/div>\n<div><\/div>\n<div>Download\/Install Java JDK 8<\/div>\n<div><\/div>\n<div>We&#8217;ll download and install the latest Java JDK 8, from the Oracle webite. Download the rpm package according to your architecture:<\/div>\n<div><\/div>\n<div>curl -LO &#8216;http:\/\/download.oracle.com\/otn-pub\/java\/jdk\/8u51-b16\/jdk-8u51-linux-x64.rpm&#8217; -H &#8216;Cookie: oraclelicense=accept-securebackup-cookie&#8217;<\/div>\n<div><\/div>\n<div>alternatives &#8211;install \/usr\/bin\/java java \/usr\/java\/jdk1.8.0_51\/jre\/bin\/java 1<br \/>\nalternatives &#8211;install \/usr\/bin\/jar jar \/usr\/java\/jdk1.8.0_51\/bin\/jar 1<br \/>\nalternatives &#8211;install \/usr\/bin\/javac javac \/usr\/java\/jdk1.8.0_51\/bin\/javac 1<br \/>\nalternatives &#8211;install \/usr\/bin\/javaws javaws \/usr\/java\/jdk1.8.0_51\/javaws 1<\/div>\n<div><\/div>\n<div>alternatives &#8211;set java\u00a0\u00a0\u00a0 \/usr\/java\/jdk1.8.0_51\/jre\/bin\/java<br \/>\nalternatives &#8211;set javaws \/usr\/java\/jdk1.8.0_51\/jre\/bin\/javaws<br \/>\nalternatives &#8211;set javac \/usr\/java\/jdk1.8.0_51\/bin\/javac<br \/>\nalternatives &#8211;set jar\u00a0 \/usr\/java\/jdk1.8.0_51\/bin\/jar<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div>http:\/\/mirror.nus.edu.sg\/apache\/tomcat\/tomcat-8\/v8.0.24\/bin\/apache-tomcat-8.0.24.tar.gz<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div>Build Jsvc<br \/>\nJsvc is a set of libraries and applications for making Java applications run on UNIX more easily and we&#8217;ll use it to start\/stop the Tomcat instance. The building process is pretty straightforward:<\/div>\n<div><\/div>\n<div>cd \/usr\/tomcat\/bin<br \/>\ntar xvfz commons-daemon-native.tar.gz<br \/>\ncd commons-daemon-*-native-src\/unix<br \/>\n.\/configure &#8211;with-java=\/usr\/java\/latest<br \/>\nmake<br \/>\ncp jsvc ..\/..<\/div>\n<div><\/div>\n<div><\/div>\n<div><\/div>\n<div>Create tomcat user<\/div>\n<div><\/div>\n<div>The following commands will create a dedicated user who will run the Tomcat instance and change the ownership of all files in the \/opt\/tomcat directory to the newly created tomcat user.<\/div>\n<div><\/div>\n<div>useradd -r -s \/sbin\/nologin tomcat<br \/>\nchown -R tomcat: \/usr\/tomcat<\/div>\n<div><\/div>\n<div>Create a systemd service<br \/>\nCreate a new file named tomcat.service:<\/div>\n<div><\/div>\n<div>vi \/usr\/lib\/systemd\/system\/tomcat.service<\/div>\n<div><\/div>\n<div>[Unit]<br \/>\nDescription=Apache Tomcat Web Application Container<br \/>\nAfter=network.target<\/div>\n<div><\/div>\n<div>[Service]<br \/>\nType=forking<br \/>\nPIDFile=\/var\/run\/tomcat.pid<br \/>\nEnvironment=CATALINA_PID=\/var\/run\/tomcat.pid<br \/>\nEnvironment=JAVA_HOME=\/usr\/java\/default<br \/>\nEnvironment=CATALINA_HOME=\/usr\/tomcat<br \/>\nEnvironment=CATALINA_BASE=\/usr\/tomcat<br \/>\nEnvironment=CATALINA_OPTS=<\/div>\n<div><\/div>\n<div>ExecStart=\/usr\/tomcat\/bin\/jsvc \\<br \/>\n-Dcatalina.home=${CATALINA_HOME} \\<br \/>\n-Dcatalina.base=${CATALINA_BASE} \\<br \/>\n-cp ${CATALINA_HOME}\/bin\/commons-daemon.jar:${CATALINA_HOME}\/bin\/bootstrap.jar:${CATALINA_HOME}\/bin\/tomcat-juli.jar \\<br \/>\n-user tomcat \\<br \/>\n-java-home ${JAVA_HOME} \\<br \/>\n-pidfile \/var\/run\/tomcat.pid \\<br \/>\n-errfile SYSLOG \\<br \/>\n-outfile SYSLOG \\<br \/>\n$CATALINA_OPTS \\<br \/>\norg.apache.catalina.startup.Bootstrap<\/div>\n<div><\/div>\n<div>ExecStop=\/usr\/tomcat\/bin\/jsvc \\<br \/>\n-pidfile \/var\/run\/tomcat.pid \\<br \/>\n-stop \\<br \/>\norg.apache.catalina.startup.Bootstrap<\/div>\n<div><\/div>\n<div>[Install]<br \/>\nWantedBy=multi-user.target<\/div>\n<div><\/div>\n<div>You can change the line with CATALINA_OPTS to suit your needs.<br \/>\nTo enable the Tomcat service to start on boot run:<\/div>\n<div><\/div>\n<div>systemctl enable tomcat.service<\/div>\n<div><\/div>\n<div>Now, you can use the following commands to start, stop, restart and check the status the Tomcat service:<\/div>\n<div><\/div>\n<div>systemctl start tomcat<br \/>\nsystemctl stop tomcat<br \/>\nsystemctl restart tomcat<br \/>\nsystemctl status tomcat<\/div>\n<div><\/div>\n<div>Final steps<br \/>\nIf you need to open port 8080 in the firewall, run:<\/div>\n<div><\/div>\n<div>firewall-cmd &#8211;zone=public &#8211;add-port=8080\/tcp &#8211;permanent<br \/>\nfirewall-cmd &#8211;reload<\/div>\n<div><\/div>\n<div>That&#8217;s it, Tomcat installation is complete. To open Tomcat, point your browser at:<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The instructions below are assuming you&#8217;re logged in as root, if you are logged in as another user remember to prepend sudo to the commands shown below. Install the necessary packages First of all update your server and install the necessary packages using the following commands: yum -y update yum -y install curl libcap-devel yum [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5083"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5083"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5083\/revisions"}],"predecessor-version":[{"id":5085,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5083\/revisions\/5085"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}