How to configure and install Tomcat in Centos

Install Tomcat in Centos.

  1. How to start tomcat?
  2. How to install SSL for tomcat server?
  3. How to run tomcat on Domain name?
  4. How to run Tomcat without port?

Step – 1

Install JAVA

sudo yum install java-1.8.0-openjdk.x86_64

java -version

Step – 2

1. Download tomcat, Download the version you need from the below link.

http://tomcat.apache.org/

Step – 3

2. Check the download using md5 checksum

md5sum apache-tomcat*

Step – 4

3. Extract the tar file in the /usr/local/tomcat

tar -zxvf apache-tomcat*

mv apache-tomcat* /usr/local/tomcat

Step – 5

4. Now we need to set path for both java and tomcat

vim /etc/environment

export JAVA_HOME=/usr/lib/java
export CATALINA_HOME=/usr/local/tomcat

5. How to start tomcat ?



To Start Tomcat enter this command in the terminal

$CATALINA_HOME/bin/startup.sh

6. How to check Tomcat is running or not?

netstat -ntlp

ps -ef | grep java
ps -ef | grep tomcat

http://localhost:8080/
http://192.168.122.33:8080/

7. How to install SSL for Tomcat Server ?

keytool -genkey -alias chirag.local -keyalg RSA -keystore /etc/pki/keystore

Enter keystore password:
keytool error: java.lang.Exception: Key pair not generated, alias <chirag.local> already exists
[[email protected] conf]# keytool -genkey -alias chirag.testing -keyalg RSA -keystore /etc/pki/keystore
Enter keystore password:
What is your first and last name?
[Unknown]: techouse
What is the name of your organizational unit?
[Unknown]: techouse
What is the name of your organization?
[Unknown]: techouse
What is the name of your City or Locality?
[Unknown]: ghaziabad
What is the name of your State or Province?
[Unknown]: Delhi
What is the two-letter country code for this unit?
[Unknown]: IN
Is CN=techouse, OU=techouse, O=techouse, L=ghaziabad, ST=Delhi, C=IN correct?
[no]: yes

Enter key password for <chirag.testing>
(RETURN if same as keystore password):
Re-enter new password:

Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore /etc/pki/keystore -destkeystore /etc/pki/keystore -deststoretype pkcs12".

8. Now we need to edit server.xml to configure SSL

vim /usr/local/tomcat/conf/server.xml

#find Connector port using below command and edit port and enable the ssl
/Connector port

<Connector port="8443" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
SSLEnabled="true"
scheme="https"
secure="true"
sslProtocol="TLS"
keystoreFile="/etc/pki/keystore"
keystorePass="chirag" />

9. How to run tomcat on Domain name?

Edit server.xml

vim /usr/local/tomcat/conf/server.xml

<Host name="techouse.local" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Alias>www.techouse.local</Alias>

10. How to run Tomcat on 80,443,8443 Port?

Method 1



How to run Tomcat without using port 8443 or 8080.

Running Tomcat without mentioning the port in URL.

Example :- Suppose we are running tomcat on this domain – techouse.co.in:8443

-> And need to run it without using port ie. – techouse.co.in, then follow the below steps.

For HTTPS connection set Default port 443

vim /usr/local/tomcat/conf/server.xml

<Connector port="443" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
SSLEnabled="true"
scheme="https"
secure="true"
sslProtocol="TLS"
keystoreFile="/etc/pki/keystore"
keystorePass="chirag" />

For HTTP connection set Default port 80

vim /usr/local/tomcat/conf/server.xml

<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

Method 2

Add VirtualHost in apache

VirtualHost

cd /etc/httpd/conf.d

vim tomcat_setup.conf

<VirtualHost *:80>
ServerName www.techouse.co.in
ProxyRequests On
ProxyPass / http://localhost:8080/Application_name/
ProxyPassReverse / http://localhost:8080/Application_name/
</VirtualHost>

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.