[JAVA] Build Apache / Tomcat development environment on Cent OS 7

Introduction

I would like to build a Web server environment that runs Apache Tomcat 9 on CentOS 7, which is a standard Linux server environment.

The following environment construction is introduced in this article.

Change log

2018.6.19 Added a little for Tomcat 9

Click here for articles up to the last time

The articles up to the last time have summarized the procedure for building a CentOS development server on GCP, so please read it as well.

Installation procedure

Work policy

  1. Use the package manager yum wherever possible.
  2. Install the official package to be as up-to-date as possible.
  3. Use Apache as the HTTP front server instead of Apache Tomcat alone.
  4. Use the JVM / JDK from Oracle.

Advance preparation

This procedure uses wget to download remote files. Install first if necessary.

yum -y install wget

Apache 2.4 installation

This item has the same procedure as last time, so please refer to the following. [Building Apache / PHP development environment on Cent OS 7](https://qiita.com/ariaki/items/2ec627a7567437f893ee#apache-24%E3%82%A4%E3%83%B3%E3%82% B9% E3% 83% 88% E3% 83% BC% E3% 83% AB)

JDK installation

When using OpenJDK

Install the JDK with the following command.

yum install java-1.8.0-openjdk-devel

When using Oracle JDK

download

First, download the latest version package for Linux x64 (jdk-8uxxx-linux-x64.tar.gz) locally from the URL below. http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Program placement

The following procedure is based on Java8u171, so please read the version number as appropriate.

mkdir /usr/java/
cd /usr/java/
tar zxf /path/to/jdk-8u171-linux-x64.tar.gz
ln -s jdk1.8.0_171 latest
echo -e "export JAVA_HOME=/usr/java/latest\nPATH=\$PATH:\$JAVA_HOME/bin" > /etc/profile.d/java.sh
source /etc/profile.d/java.sh

Execution path setting

Use the alternatives command to set which java command to launch by default.

alternatives --install /usr/bin/java java /usr/java/latest/bin/java 9999
alternatives --config java
alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 9999
alternatives --config javac

After completing the settings, use the following command to check if the version you just installed is executed.

java -version
javac -version

Apache tomcat 9 installation

Download the latest version of Apache Tomcat from the official website as well.

Download and unpack

The following example will download the current latest version of Apache Tomcat 8.5.23, so please read as appropriate. The installation destination this time is "/ usr / tomcat8".

cd /usr/local/src
wget http://ftp.jaist.ac.jp/pub/apache/tomcat/tomcat-9/v9.0.8/bin/apache-tomcat-9.0.8.tar.gz
tar zxf apache-tomcat-9.0.8.tar.gz
mv apache-tomcat-9.0.8 /usr/tomcat9

basic configuration

Let's set environment variables using the following command.

echo -e "export CATALINA_HOME=/usr/tomcat9\nexport CATALINA_BASE=/usr/tomcat9" > /etc/profile.d/tomcat.sh
source /etc/profile.d/tomcat.sh

Operation check

You can check the version information and the execution JVM environment with the following command.

/usr/tomcat9/bin/version.sh 

Let's confirm that the execution result is as follows.

Using CATALINA_BASE:   /usr/tomcat9
Using CATALINA_HOME:   /usr/tomcat9
Using CATALINA_TMPDIR: /usr/tomcat9/temp
Using JRE_HOME:        /
Using CLASSPATH:       /usr/tomcat9/bin/bootstrap.jar:/usr/tomcat9/bin/tomcat-juli.jar
Server version: Apache Tomcat/9.0.8
Server built:   Apr 27 2018 19:32:00 UTC
Server number:  9.0.8.0
OS Name:        Linux
OS Version:     3.10.0-862.3.2.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_171-b10
JVM Vendor:     Oracle Corporation

User created

Create a user to run Apache Tomcat with the following command.

useradd -M -d /usr/tomcat9 tomcat
chown -R tomcat:tomcat /usr/tomcat9

Auto start setting

Manually generate a systemctl startup script with the following command.

echo "[Unit]
Description=Apache Tomcat Servlet Container
After=syslog.target network.target

[Service]
Type=forking
User=tomcat
Group=tomcat
Environment=CATALINA_BASE=/usr/tomcat9
Environment=CATALINA_HOME=/usr/tomcat9
ExecStart=$CATALINA_HOME/bin/startup.sh
ExecStop=$CATALINA_HOME/bin/shutdown.sh
ExecReStart=$CATALINA_HOME/bin/shutdown.sh;$CATALINA_HOME/bin/startup.sh
KillMode=none

[Install]
WantedBy=multi-user.target
" > /usr/lib/systemd/system/tomcat9.service

Start / stop with the following command.

#Start-up
systemctl start tomcat9
#End
systemctl stop tomcat9
#Reboot
systemctl restart tomcat9

After completing the settings, use the following command to set automatic startup.

systemctl enable tomcat9

Apache → Tomcat linkage setting

To pass requests from Apache to Tomcat, you need to configure a ** reverse proxy **.

The following is a setting example to pass all requests under "/" to Tomcat.

echo "ProxyPass / ajp://localhost:8009/" > /etc/httpd/conf.d/proxy.conf

Once the above is done, let's restart Apache for the settings to take effect.

systemctl restart httpd

The above procedure completes the initial installation of Tomcat.

Recommended Posts

Build Apache / Tomcat development environment on Cent OS 7
Build Unity development environment on docker
Build a Java development environment on Mac
Build Java 8 development environment on AWS Cloud9
Build Apache + Tomcat + Pebble locally on Mac
Build an Ultra96v2 development environment on Docker 1
[Java] Build Java development environment on Ubuntu & check execution
Build Java development environment with VS Code on Mac
Build a Ruby on Rails development environment on AWS Cloud9
Build a Tomcat 8.5 environment with Pleiades 4.8
I installed TinyTinyRSS on Cent OS 8
Build Java development environment (for Mac)
Build a XAMPP environment on Ubuntu
Build jooby development environment with Eclipse
Install Java development environment on Mac
I tried to build an http2 development environment with Eclipse + Tomcat
Build a development environment where Ruby on Rails breakpoints work on Windows
Steps to build a Ruby on Rails development environment with Vagrant
Create Spring Boot development environment on Vagrant
Build a PureScript development environment with Docker
Java development environment construction memo on Mac
[Ruby] Building a Ruby development environment on Ubuntu
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Build a Wordpress development environment with Docker
Build Redmine code reading environment on Docker
Run jooby's Eclipse development environment on Gradle
Build a development environment on AWS EC2 with CentOS7 + Nginx + pm2 + Nuxt.js
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Build an environment with Docker on AWS
Build a JMeter environment on your Mac
Build a simple Docker + Django development environment
Build a Doker-based development environment on Windows 10 Home 2020 ver. Part 1 Until WSL2-based Docker build
Build Apache and Tomcat environment with Docker. By the way, Maven & Java cooperation
Build a development environment to create Ruby on Jets + React apps with Docker
Try to build Java8 environment on Amazon Linux2
Build and install Wireshark Development Release (3.3.1) on Ubuntu
Build openssl, apache2.4, php7.4 from source on Ubuntu-server20.04.
Build a WordPress development environment quickly with Docker
Development environment construction using IntelliJ IDEA + Maven + Tomcat 9
Build a simple Docker Compose + Django development environment
Build a Laravel environment on an AWS instance
[Win10] Build a JSF development environment with NetBeans
Install Java, Apache, Tomcat9 on EC2 (Amazon Linux2)
[Ruby on Rails] Let's build an environment on mac
Ruby on Rails development environment construction on M1 Mac
Build a development environment for Docker, java, vscode
Build a Java runtime environment on Sakura VPS
How to build a Pytorch environment on Ubuntu
[First team development ②] Build an environment with Docker
GitLab development environment setup (GDK) on macOS (September 2020)
Build a Java development environment with VS Code
JSP on tomcat
Java development environment
Apache and tomcat
[For beginners] Until building a Web application development environment using Java on Mac OS
Create a Java development environment using jenv on Mac
Memo to build a Servlet environment on AWS EC2
Build Ubuntu 20.04 LTS desktop environment on Raspberry Pi 4 (+ Japanese)
[Environment construction] Ruby on Rails 5.2 system development environment construction [within 1 hour]
Java development environment construction on Mac-JDK Install (2020 preservation version)
Docker the development environment of Ruby on Rails project