Latest

Tuesday, 5 March 2019

How to Install Apache TomEE 8 on CentOS 7

Install Apache TomEE 8 on CentOS 7

Apache TomEE (pronounced “Tommy”) is the Java Enterprise Edition of Apache Tomcat. Apache TomEE combines several Java enterprise projects including Apache OpenEJB, Apache OpenWebBeans, Apache OpenJPA, Apache MyFaces, etc. In comparison with Apache Tomcat, Apache TomEE is loaded with more technology support. According to Wikipedia, TomEE = Tomcat + JavaEE.

In this article, we will install Apache TomEE 8 on CentOS 7 server and configure Application Manager.

 

Table of Contents:

Install Apache TomEE 8 on CentOS 7

System Specification:

We have provision a CentOS 7 virtual machine with following specifications.

  • Hostname - tomee-01.example.com
  • IP Address - 192.168.116.145/24
  • Operating System - CentOS 7.6
  • Apache TomEE - 8

 

Installing OpenJDK 8 on CentOS 7:

Apache TomEE requires Java 8 (or above) runtime environment. Therefore, we are installing OpenJDK 8 on our CentOS 7 server.

# yum install -y java-1.8.0-openjdk-devel

Java executables have been automatically added to PATH environment variable. Therefore, we are only required to set the JAVA_HOME environment variable.

# echo "export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64" >> /etc/profile
# . /etc/profile
# env | grep JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64

Verify Java version.

# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

OpenJDK 8 has been installed on our CentOS 7 server.

 

Installing Apache TomEE 8 on CentOS 7:

Create a user to own Apache TomEE software.

# useradd -s /sbin/nologin tomcat

Go to Apache TomEE website to download it.

There are many distributions of Apache TomEE are available. Download your required Apache TomEE distribution from this page.

We are downloading Apache TomEE webprofile. But the installation steps are exactly same for other distributions like Apache TomEE plus, Apache TomEE plume, etc.

Note: There is a good comparison of Apache TomEE distributions is available on their website, that will help you selection of your required Apache TomEE distribution.

# wget https://www-eu.apache.org/dist/tomee/tomee-8.0.0-M2/apache-tomee-8.0.0-M2-webprofile.tar.gz
--2019-03-04 23:00:23--  https://www-eu.apache.org/dist/tomee/tomee-8.0.0-M2/apache-tomee-8.0.0-M2-webprofile.tar.gz
Resolving www-eu.apache.org (www-eu.apache.org)... 95.216.24.32, 2a01:4f9:2a:185f::2
Connecting to www-eu.apache.org (www-eu.apache.org)|95.216.24.32|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 41727556 (40M) [application/x-gzip]
Saving to: âapache-tomee-8.0.0-M2-webprofile.tar.gzâ

100%[======================================>] 41,727,556   234KB/s   in 3m 0s

2019-03-04 23:03:23 (226 KB/s) - âapache-tomee-8.0.0-M2-webprofile.tar.gzâ saved [41727556/41727556]

Extract downloaded file.

# tar xf apache-tomee-8.0.0-M2-webprofile.tar.gz

Move extracted directory to /opt/tomee/.

# mkdir /opt/tomee
# mv apache-tomee-webprofile-8.0.0-M2/ /opt/tomee/

Change ownership of /opt/tomee directory.

# chown -R tomcat:tomcat /opt/tomee/

We will create a soft link latest for /opt/tomee/apache-tomee-webprofile-8.0.0-M2 directory. So, we can upgrade/downgrade Apache TomEE conveniently.

# ln -s /opt/tomee/apache-tomee-webprofile-8.0.0-M2 /opt/tomee/latest

Create a systemd unit file to define a service for Apache TomEE 8 server.

# vi /usr/lib/systemd/system/tomee.service

and add following lines therein.

[Unit]
Description=TomEE 8 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/jre"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomee/latest"
Environment="CATALINA_HOME=/opt/tomee/latest"
Environment="CATALINA_PID=/opt/tomee/latest/temp/tomee.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomee/latest/bin/startup.sh
ExecStop=/opt/tomee/latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Execute following command to notify systemd that we have created a new unit file.

# systemctl daemon-reload

Start and enable Apache TomEE service.

# systemctl enable tomee.service
Created symlink from /etc/systemd/system/multi-user.target.wants/tomee.service to /usr/lib/systemd/system/tomee.service.
# systemctl start tomee.service

Allow Apache TomEE service port in Linux firewall.

# firewall-cmd --permanent --add-port=8080/tcp
success
# firewall-cmd --reload
success

Browse URL http://tomee-01.example.com:8080/ in a client's browser.

Apache TomEE Homepage

Apache TomEE 8 has been installed on CentOS 7.

 

Configure Apache TomEE Application Manager on CentOS 7:

Application Manager provides Web UI to easily manage, deploy, start and stop Java applications running on Apache TomEE 8 server. It is installed with Apache TomEE but requires some necessary settings prior to use.

Define users and roles to access Apache TomEE 8 Manager Web UI.

# vi /opt/tomee/latest/conf/tomcat-users.xml

Add following lines just before </tomcat-usersgt; tag.

   <role rolename="admin-gui"/>
   <role rolename="manager-gui"/>
   <user username="admin" password="admin" roles="admin-gui,manager-gui"/>
   <user username="ahmer" password="123" roles="admin-gui,manager-gui"/>

By default Application Manager is allowed to be accessed from localhost only.

We must edit the following files to let us access it from other machines.

# vi /opt/tomee/latest/webapps/manager/META-INF/context.xml

Find following lines of code and add the IP address of the client system, that you are using for Apache TomEE administration.

<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />

Our client's IP address is 192.168.116.1/24. Therefore, after adding it in the above file, the final code is looks like following.

<Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|192.168.116.1" />

Similarly, repeat the above step for following file.

# vi /opt/tomee/latest/webapps/host-manager/META-INF/context.xml

Restart Apache TomEE 8 service to apply changes.

# systemctl restart tomee.service

Browse URL http://tomee-01.example.com:8080 using a client's browser.

Apache TomEE Homepage

Click on Server Status.

Apache TomEE Server Status

Go back and click on Manager App.

Apache TomEE Application Manager

Go back and click on Host Manager.

Apache TomEE Virtual Host Manager

Application Manager has been configured on Apache TomEE 8 running on CentOS 7 server.

If you find this article useful? Consider supporting us by Buy Me A Coffee


4 comments:

  1. this message was given when i tried to start the service.
    Job for tomee.service failed because the control process exited with error code.
    See "systemctl status tomee.service" and "journalctl -xe" for details.

    ReplyDelete
    Replies
    1. Hi, this is a generic error. You have to look into error logs (as advised in the error message) to find the cause of this error.

      Delete
  2. tomee.service: Failed to execute command: Permission denied

    ReplyDelete
    Replies
    1. It is a generic error. You may find the actual cause of the problem in system/service logs.

      Delete

© 2022 CentLinux. All Rights Reserved.