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.
In this article, I will write down the construction of the WebAP server.
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. ** **
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
$ yum -y install java-1.8.0-openjdk-devel
$ 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
$ 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
$ 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 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
$ chmod 755 /etc/systemd/system/tomcat.service
$ systemctl start tomcat
$ systemctl enable tomcat
$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" />
$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" />
-->
$ systemctl restart tomcat
[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-cmd --add-port=8080/tcp --zone=public --permanent
$ yum -y install firewalld
$ systemctl restart firewalld
$ systemctl enable firewalld
$ firewall-cmd --list-all
ports: 8080/tcp ← OK if added
This time, install the JDBC driver to connect to PostgreSQL in the DB server from the Java application.
$ yum install -y postgresql-jdbc
Copy to the lib folder of installed Tomcat
$ cp /Installed path/postgresql-jdbc.jar /Installed path/apach-tomcat-8.5.37/lib
You have now built a simple WebAP server. Next, we will summarize the construction of the DB server.
Recommended Posts