First VPS and first Java environment construction. Install Tomcat to make Java 8 executable.
--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/
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
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
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
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+"/>
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
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/
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
# 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