실습) 10.10.3.80/tomcat/dbtest.jsp를 쳤을때 was-db connection success가 뜨도록 한번 구성해보세요. 서버는 3대를 다 새로 만드세요.
필요한 서버 3개
DB, WEB(10.10.3.80), TOMCAT
✅초기 설정
초기 설정
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
reboot
systemctl stop firewalld
systemctl disable firewalld
cat <<EOF> /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/centosplus/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=https://vault.centos.org/7.9.2009/contrib/x86_64/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
✅DB
yum install -y mariadb-server
systemctl restart mariadb
systemctl enable mariadb
mysql_secure_installation
[root@was-db ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
mysql -u root -p1234
MariaDB [(none)]> create database tomcatdb ;
MariaDB [(none)]> grant all privileges on tomcatdb.* to tomcatuser@'%' identified by '1234';
✅ tomcat
yum install -y java-11-openjdk wget unzip
https://tomcat.apache.org/download-1wge0.cgi
![](https://blog.kakaocdn.net/dn/2HyoI/btsL5swvxbg/7M69D0buHcA82gL65kcxZ1/img.png)
- 직접 복붙해야 잘 받아와짐
wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.34/bin/apache-tomcat-10.1.34.zip
unzip apache-tomcat-10.1.34.zip > /dev/null
mv apache-tomcat-10.1.34/ tomcat
cd tomcat/
chmod 777 -R /root/tomcat
sh ./bin/startup.sh
![](https://blog.kakaocdn.net/dn/BUmSo/btsL59X7N4P/k6K0jY2VcKQlKZ5lBkXvEk/img.png)
- 잘 받아와 지는걸 확인할 수 있음
https://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/
Sample Application
Sample Application The example app has been packaged as a war file and can be downloaded here (Note: make sure your browser doesn't change file extension or append a new one). The easiest way to run this application is simply to move the war file to your C
tomcat.apache.org
![](https://blog.kakaocdn.net/dn/cQalOO/btsL7hAenxa/BZRzi2GefHBKF3EUhlTeV0/img.png)
직접 복붙해야 잘 받아와짐
wget https://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/sample.war
[root@was-tom-db tomcat]# vi /root/tomcat/webapps/ROOT/test.jsp
![](https://blog.kakaocdn.net/dn/AI6GD/btsL5mb8BQL/nkscRdt0piPrN26y4JUnuK/img.png)
[root@was-tom-db tomcat]# ./bin/shutdown.sh
[root@was-tom-db tomcat]# ./bin/startup.sh
- DB 설정한 후
yum install -y mysql
# mysql 명령어 설치
mysql -u tomcatuser -p1234 -h 10.10.3.80
# db 접속 확인
![](https://blog.kakaocdn.net/dn/bgeXEk/btsL7kjN0zh/qM2Dyobs5dZiJkHB84tAsK/img.png)
cat <<EOF > dbtest.jsp
>
> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
> <%@ page import="java.sql.*"%>
> <h1>DB</h2>
> <%
> Connection conn=null;
> try{
> String Url="jdbc:mysql://10.10.3.90/tomcatdb";
> String Id="tomcatuser";
> String Pass="1234";
>
> Class.forName("com.mysql.jdbc.Driver");
> conn=DriverManager.getConnection(Url,Id,Pass);
> out.println("was-db Connection Success!");
> }catch(Exception e) {
> e.printStackTrace();
> }
> %>
>
> EOF
[root@tomcat tomcat]# mv dbtest.jsp /root/tomcat/webapps/ROOT/dbtest.jsp
https://mvnrepository.com/artifact/mysql/mysql-connector-java/8.0.23
![](https://blog.kakaocdn.net/dn/4wncg/btsL7uNk6bT/pgkkhnAN2XWA4pqFBJPkD0/img.png)
wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.23/mysql-connector-java-8.0.23.jar
mv mysql-connector-java-8.0.23.jar /root/tomcat/lib
[root@was-tom-db tomcat]# ./bin/shutdown.sh
[root@was-tom-db tomcat]# ./bin/startup.sh
![](https://blog.kakaocdn.net/dn/olxAD/btsL47fxSew/TZ20hx0WCBCEaLzbKrYBf1/img.png)
✅ WEB
yum install -y httpd
[root@was-db ~]# systemctl restart httpd
[root@was-db ~]# systemctl enable httpd
[root@was-db ~]# echo 'was-db connection success' > /var/www/html/index.html
[root@was-db ~]# curl 10.10.3.80
was-db connection success
[root@was-db ~]# vi /etc/httpd/conf/httpd.conf
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost *:80> # 80번 포트로 들어오는 모든 ip에 대한 설정
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /tomcat http://211.183.3.88:8080/
ProxyPassReverse /tomcat http://211.183.3.88:8080/
</VirtualHost>
[root@was-db ~]# systemctl restart httpd
[root@was-db ~]# curl localhost:80/jsp/dbtest.jsp
![](https://blog.kakaocdn.net/dn/rglDL/btsL6jzuMNd/mNnVDdQCgZ6Qh2U3Uxkn80/img.png)
'AWS Cloud School 8기 > 서버가상화_클라우드 이미지' 카테고리의 다른 글
ACL(ACcess-List) (0) | 2025.02.09 |
---|---|
VyOS/ (VyOS nat 해제) (0) | 2025.02.06 |
3-Tier Architecture (3계층 아키텍처)/ Reverse Proxy (리버스 프록시) (0) | 2025.02.06 |
Proxy[정방향 프록시 (Forward Proxy)], SSH (0) | 2025.02.05 |
VM 8 + DNS + DB + WP 실습(코드만) (0) | 2025.02.03 |