[LINUX] The programmer tried hard to build a server to overcome it, saying that infrastructure seems to be difficult. WebAP server edition

Introduction

Servers, networks, and so on ... I'm thinking that I'll have to do it someday * n. During work, I often asked the person in charge of infrastructure, and I always avoided the opportunity to touch it.

** "But that's okay> <!" ** So, ~~ Black screen allergy ~~ This is a memorandum built by beginners while investigating. If you find any omissions or mistakes in the settings, please let us know ...

I tried to build a simple WebAP server without Apache cooperation.

Construction image

img.JPG

In this article, I will write down the construction of the WebAP server. img_web.jpg

environment

Built with EC2 on AWS. OS:Red Hat Enterprise Linux 7

This time, 8080 is set for the security zone. If necessary, make the appropriate settings.

What to prepare from now on ... ・ Tomcat ・ JDK -JDBC driver

** * The version is as of January 2019. Use the right one. ** **

Environment

before that

It is necessary to know the path when building the environment. I proceeded with the construction while searching for the installed path with the following command. (In the text, the detailed path is not described and unified with [Installed path].)

$ find / -name "File name you want to look up" -ls

The file name you want to look up is a wildcard (*) Can be used for fuzzy search.
Example) find/ -name "tomcat*" -ls

Also, some commands required root privileges, but I ran them with sudo. (The description is omitted this time.)

JDK

Installation

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

Verification

$ 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)
$ javac -version

javac 1.8.0_191

Tomcat -Find the URL for installation Tomcat official website

Installation


$ wget http://ftp.jaist.ac.jp/pub/apache/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
$ yum -y install wget

Deployment and placement of tar.gz

$ tar -xzvf installed path/apache-tomcat-8.5.37.tar.gz
$ mkdir /opt/apache-tomcat-8.5.37
$mv installed path/apache-tomcat-8.5.37 /opt/apache-tomcat-8.5.37

Create configuration file

Create a new tomcat.service and open it

$ vi /etc/systemd/system/tomcat.service

Describe the following

[Unit]
Description=Apache Tomcat 8
After=syslog.target network.target

[Service]
User=tomcat
Group=tomcat
Type=oneshot
PIDFile=/opt/tomcat/tomcat.pid
RemainAfterExit=yes

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
ExecReStart=/opt/tomcat/bin/shutdown.sh;/opt/tomcat/bin/startup.sh

[Install]
WantedBy=multi-user.target

Grant authority

$ chmod 755 /etc/systemd/system/tomcat.service

Start tomcat

$ systemctl start tomcat

Bonus: Auto start setting

$ systemctl enable tomcat

Bonus: Tomcat management screen

Modify tomcat-users.xml

$vi installed path/tomcat-users.xml

Add permissions when opening tomcat-users.xml

<role rolename="admin"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user name="xxxxxxxx" password="yyyyyyyy" roles="admin,manager,admin-gui,admin-script,manager-gui,manager-script,manager-jmx,manager-status" />

Modify context.xml

$vi installed path/manager/META-INF/context.xml

Comment out the following

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

↓

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

Restart tomcat

$ systemctl restart tomcat

Access and check

[http: // public IP: 8080 / manager / html](http: // public IP: 8080 / manager / html)

OK if the Tomcat cat screen is displayed

If you cannot access it, set the firewall

Firewall

Add port 8080

$ firewall-cmd --add-port=8080/tcp --zone=public --permanent
$ yum -y install firewalld

restart

$ systemctl restart firewalld

Auto start settings

$ systemctl enable firewalld

Confirm

$ firewall-cmd --list-all

ports: 8080/tcp ← OK if added

JDBC driver

This time, install the JDBC driver to connect to PostgreSQL in the DB server from the Java application.

Installation

$ yum install -y postgresql-jdbc

copy

Copy to the lib folder of installed Tomcat

$ cp /Installed path/postgresql-jdbc.jar /Installed path/apach-tomcat-8.5.37/lib

end

You have now built a simple WebAP server. Next, we will summarize the construction of the DB server.

Recommended Posts

The programmer tried hard to build a server to overcome it, saying that infrastructure seems to be difficult. WebAP server edition
I tried to build a SATA software RAID configuration that boots the OS on Ubuntu Server
I tried to make a site that makes it easy to see the update information of Azure
I tried to expand the database so that it can be used with PES analysis software
I tried to create a server environment that runs on Windows 10
How to build a NEM (current version) node (NIS1: NEM Infrastructure Server)
I tried to push the Sphinx document to BitBucket and it will be automatically reflected on the web server
[AWS] Flask application deployment preparation edition that tried to build a Python environment with eb [Elastic Beanstalk]