Build a Java runtime environment on Sakura VPS

First VPS and first Java environment construction. Install Tomcat to make Java 8 executable.

Environment so far

--Sakura VPS

While reading "Understanding even with cats! Sakura's VPS course", we will use the environment that was built in a traceable manner. https://knowledge.sakura.ad.jp/8218/

Installation of Java Runtime Environment (JRE)

Use 8 of OpenJDK (Open Java Development Kit). It is named java-1.8.0-openjdk in the standard CentOS yum repository.

# yum install java-1.8.0-openjdk

Execute the following command and switch to 8 if there are multiple versions.

# alternatives --config java 

Install tomcat

Download the tar.gz format file [apache-tomcat-8.5.34.tar.gz] from the distribution page of Tomcat.

Transfer the downloaded file by FTP (appropriately / var / www / html / test or the directory where FTP access was set when building the Web server), and expand it on CentOS with the following command.

# tar xvfz apache-tomcat-8.5.34.tar.gz 

Move the extracted folder to the / usr / local directory

# mv apache-tomcat-8.5.34 /usr/local 

Set a symbolic link so that you can access it with the name [tomcat]

# cd /usr/local 
# ln -s apache-tomcat-8.5.34 tomcat

Deploy MySQL Connector / J

It absorbs the differences between databases. Move the mysql-connector-java-x.x.x-bin.jar included in the download to / usr / local / tomcat / lib https://dev.mysql.com/downloads/connector/j/5.1.html

# mv mysql-connector-java-x.x.x-bin.jar /usr/local/tomcat/lib 

Tomcat web application manager settings

The following are the settings required if you want to use the Tomcat GUI. You can place it by moving the war file to / usr / local / tomcat / webapps without GUI.

– Add the following settings to /usr/local/tomcat/conf/tomcat-users.xml

tomcat-users.xml


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

Allow access to the Tomcat management screen from the host machine side Add the following settings to the following 2 files

- /usr/local/tomcat/webapps/manager/METAINF/context.xml - /usr/local/tomcat/webapps/host-manager/METAINF/context.xml

By default, the GUI is restricted so that it can only be accessed locally, so if you want to access it from the outside, do the following or comment it out. * Security precautions

context.xml


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

Opening 8080 port for tomcat

Immediate reflection
# firewall-cmd --zone=public --add-port=8080/tcp
Reflection of permanent settings
# firewall-cmd --zone=public --add-port=8080/tcp --permanent
Reload
# firewall-cmd --reload
Check settings
# firewall-cmd --list-all

Quit and start tomcat

If you change something, it will not be reflected unless you restart

# /usr/local/tomcat/bin/startup.sh 
# /usr/local/tomcat/bin/shutdown.sh 

Success if you can access the GUI with the URL below.

http://[IP address of VPS]:8080/

Register tomcat as a service

Set Tomcat to start when the server starts. Create a user

# useradd -s /sbin/nologin tomcat

Change the owner of the tomcat directory to tomcat

# chown -R tomcat /usr/local/apache-tomcat-8.x.x 

Creating a startup script file

# vi /etc/init.d/tomcat

/etc/init.d/tomcat


#!/bin/bash
#
# Startup script for the Tomcat Servlet Container
#
# chkconfig: 2345 80 10
# description: Tomcat is the servlet container that is used in the official \
#              Reference Implementation for the Java Servlet and JavaServer \
#              Pages technologies

TOMCAT_USER=tomcat
CATALINA_HOME=/usr/local/tomcat

. /etc/rc.d/init.d/functions
prog=tomcat

start() {
    echo -n $"Starting $prog: "
    daemon --user $TOMCAT_USER $CATALINA_HOME/bin/startup.sh > /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo_success
    else
        echo_failure
    fi
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    daemon --user $TOMCAT_USER $CATALINA_HOME/bin/shutdown.sh > /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        echo_success
    else
        echo_failure
    fi
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
    return $RETVAL
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  status)
    INSTANCES=`ps --columns 512 -aef|grep java|grep tomcat|grep org.apache.catalina.startup.Bootstrap|wc -l`
    if [ $INSTANCES -eq 0 ]; then
        echo $prog is stopped
        RETVAL=3
    else
        if [ $INSTANCES -eq 1 ]; then
            echo $prog is running 1 instance...
        else
            echo $prog is running $INSTANCES instances...
        fi
        RETVAL=0
    fi
    ;;
  *)
    echo $"Usage: $prog {start|stop|restart|status|help}"
    exit 1
esac

exit $RETVAL

Grant execute permission to the startup script file

# chmod a+x /etc/init.d/tomcat 

Enable automatic service start with the chkconfig command

# chkconfig tomcat on 

Recommended Posts

Build a Java runtime environment on Sakura VPS
Build a Java development environment on Mac
Build a XAMPP environment on Ubuntu
Build Java 8 development environment on AWS Cloud9
Build a JMeter environment on your Mac
Build Web Application Server (Java) on VPS
Try to build Java8 environment on Amazon Linux2
[Java] Build Java development environment on Ubuntu & check execution
java build a triangle
Build a Laravel environment on an AWS instance
Build a development environment for Docker, java, vscode
How to build a Pytorch environment on Ubuntu
Build a Java development environment with VS Code
Create a Java development environment using jenv on Mac
Memo to build a Servlet environment on AWS EC2
Build Java development environment with VS Code on Mac
Build a Ruby on Rails development environment on AWS Cloud9
[Environment construction] Build a Java development environment with VS Code!
Try to build a Java development environment using Docker
Creating a lightweight Java environment that runs on Docker
Ruby ① Build a Windows environment
Build a CentOS 8 virtual environment on your Mac with VirtualBox
Build a Java project with Gradle
Build a Node.js environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Build a Minecraft server on AWS
Build Unity development environment on docker
Install Java development environment on Mac
Build a development environment where Ruby on Rails breakpoints work on Windows
[Introduction] Build a virtual environment of Vagrant + VirtualBox on Window10 [Environment construction]
Steps to build a Ruby on Rails development environment with Vagrant
Java runtime environment construction method (Tomcat @ Linux)
How to build a Ruby on Rails environment using Docker (for Docker beginners)
Build a PureScript development environment with Docker
Java development environment construction memo on Mac
Let's create a Java development environment (updating)
Build a Maven repository on AWS S3
[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
Deploy a Java web app on Heroku
Build Redmine code reading environment on Docker
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 an Ultra96v2 development environment on Docker 1
I had a hard time installing MariaDB 10.5.5 on CentOS 8 of Sakura VPS
Install Docker and create Java runtime environment
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
I built a Java EE environment on AWS and tried running a web application
Build a development environment to create Ruby on Jets + React apps with Docker
Build a development environment for Docker + Rails6 + Postgresql
Build a test flow on CircleCI using Jib
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Create a Lambda Container Image based on Java 15
Build a Laravel / Docker environment with VSCode devcontainer
Building a Ruby environment for classes on Mac
Build a WordPress development environment quickly with Docker
Try Azure Service Fabric (Java) on Mac-Local Environment
Build Java environment and output hello world [Beginner]