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.
2018.6.19 Added a little for Tomcat 9
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.
This procedure uses wget
to download remote files.
Install first if necessary.
yum -y install wget
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)
Install the JDK with the following command.
yum install java-1.8.0-openjdk-devel
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
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
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
Download the latest version of Apache Tomcat from the official website as well.
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
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
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
Create a user to run Apache Tomcat with the following command.
useradd -M -d /usr/tomcat9 tomcat
chown -R tomcat:tomcat /usr/tomcat9
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
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