How to install Java 8 and tomcat 8 on CentOS 6 as service
Install Java 8:
1 2 3 4 5 6 7 8 9 10 11 12 |
#Install Java 8 cd /opt wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.rpm" rpm -ivh jdk-8u45-linux-x64.rpm #Create a link to Java ln -s /usr/java/jdk1.8.0_45/ ~/java #Check if Java is installed java -version javac -version |
Install Tomcat 8
1 2 3 4 5 6 |
#Install tomcat 8 wget http://apache.cs.uu.nl/tomcat/tomcat-8/v8.0.23/bin/apache-tomcat-8.0.23.tar.gz tar xzf apache-tomcat-8.0.23.tar.gz #Create a link to Tomcat ln -s /opt/apache-tomcat-8.0.23 ~/tomcat |
Lets add Tomcat as a service
1 2 3 |
#Add tomcat to start up cd /etc/init.d vi tomcat |
Paste
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#!/bin/bash # description: Tomcat Start Stop Restart Status # processname: tomcat # chkconfig: 234 20 80 JAVA_HOME=~/java export JAVA_HOME PATH=$JAVA_HOME/bin:$PATH export PATH CATALINA_HOME=~/tomcat case $1 in start) sh $CATALINA_HOME/bin/startup.sh ;; stop) sh $CATALINA_HOME/bin/shutdown.sh ;; restart) sh $CATALINA_HOME/bin/shutdown.sh sh $CATALINA_HOME/bin/startup.sh ;; status) ps -ef | grep tomcat esac exit 0 |
Add tomcat to startup
1 2 3 4 5 |
#Add tomcat to start up chmod 755 tomcat chkconfig --add tomcat chkconfig --level 234 tomcat on chkconfig --list tomcat |
Lets enable tomcat user:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#Enable tomcat users cd \ vi tomcat/conf/tomcat-users.xml #paste this before </tomcat-users> #Make sure to change the username and password <role rolename="manager-gui"/> <role rolename="manager-script"/> <role rolename="manager-jmx"/> <role rolename="manager-status"/> <role rolename="admin-gui"/> <role rolename="admin-script"/> <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/> |
Start tomcat
1 2 |
#start tomcat service tomcat start |
Go to the browser:
http://serverip:8080/
If you want to run tomcat on port 80:
1 2 3 4 |
vi tomcat/conf/server.xml #replace 8080 with 80 service tomcat restart |
http://serverip/