Tag: tomcat

  • Install Tomcat on CentOS 7

    Install Tomcat on CentOS 7

    Apache Tomcat is an open source implementation of the Java Servlet and Java Server Pages. To install Apache Tomcat on CentOS 7, run

    yum install tomcat
    

    To enable tomcat start on boot

    systemctl enable tomcat
    

    You can manage tomcat with

    systemctl stop tomcat
    systemctl start tomcat
    systemctl status tomcat
    systemctl restart tomcat
    

    To see the ports used by tomcat

    [root@tomcat ~]# netstat -lntp| grep java
    tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      31423/java          
    tcp6       0      0 :::8009                 :::*                    LISTEN      31423/java          
    tcp6       0      0 :::8080                 :::*                    LISTEN      31423/java          
    [root@tomcat ~]# 
    

    webapps are stored in the directory

    /var/lib/tomcat/webapps
    

    Create the default page with

    mkdir /var/lib/tomcat/webapps/ROOT
    echo "Hello Cat" > /var/lib/tomcat/webapps/ROOT/index.html
    

    Tomcat web server can be accessed using

    http://your-server-ip:8080
    

    To open 8080 port on the firewall, use commands

    firewall-cmd --permanent --zone=public --add-port=8080/tcp
    firewall-cmd --reload
    

    Tomcat configurations are available in the directory.

    /etc/tomcat/
    

    Install tomcat Manager

    To install the Tomcat manager GUI application, run

    yum install tomcat-admin-webapps.noarch -y
    

    To create user, edit file

    vi /etc/tomcat/tomcat-users.xml
    

    Inside ““, add

    
    
    

    USER_NAME_HERE and PW_HERE – replace with the username and password you need.

    Restart tomcat to activate Tomcat Manager GUI.

    systemctl restart tomcat
    

    To access GUI, go to

    http://your-server-ip-here:8080/manager/
    
  • List contents of jks keystore file

    List contents of jks keystore file

    To list the content of jks keystore file used by tomcat web server, run command

    keytool -list -keystore FILE.jks 
    

    It will ask Keystore password. Once you enter the password, it will list the contents of the file.

    keytool list certificates

    In the above keystore, there are 5 certificates with names inter, root1, root2, ssl_tomcat2, and tomcat.

    To get detailed information on the certificates, use the command

    keytool -list -v -keystore FILE.jks 
    

    See keytool

  • Installing tomcat on Ubuntu

    How to find java version
    Install Tomcat on CentOS 7

    To install tomcat on Ubuntu 18.04, run

    apt install tomcat9
    

    Start tomcat with

    systemctl start tomcat9
    

    Once tomcat started, you will be able to see it at

    http://your-ip-addr:8080/

    You can verify tomcat running with netstat

    root@magmito-server:~# netstat -lntp | grep java
    tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      2921/java           
    tcp6       0      0 :::8080                 :::*                    LISTEN      2921/java           
    root@magmito-server:~# 
    

    Tomcat default home page is

    /var/lib/tomcat9/webapps/ROOT/index.html
    

    Some other folders

    CATALINA_HOME=/usr/share/tomcat9
    CATALINA_BASE=/var/lib/tomcat9
    

    Deploying Application

    You can upload war file to /var/lib/tomcat9/webapps folder. When you upload war file, it get auto extracted to the folder.

    To deplay sample application, do following

    cd /var/lib/tomcat9/webapps/
    wget https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war
    

    Now you will see “sample” folder (/var/lib/tomcat9/webapps/sample). You can access the application with url

    http://your-ip-addr:8080/sample/