카테고리 없음

SW 개발보안 8일차 - Docker

ajh 2026. 5. 19. 16:41

tomcat manager 설정

[root@docker ~]# docker exec -it tomcat9.0 bash
root@1806de65757a:/usr/local/tomcat# apt update
root@1806de65757a:/usr/local/tomcat# apt -y install vim
root@1806de65757a:/usr/local/tomcat# vi conf/tomcat-users.xml
~~~ ~~~
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->

  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-status"/>
  <role rolename="admin-gui"/>
  <user username="admin" password="tomcat1234" roles="manager-gui,manager-script,manager-status,admin-gui"/>
</tomcat-users>
  
root@1806de65757a:/usr/local/tomcat# cp -r /usr/local/tomcat/webapps.dist/manager /usr/local/tomcat/webapps/

manager는 기본적으로 localhost에서만 접속 가능하도록 제한되어 있기 때문에 192.168.100.1에서 접속할 수 있도록 설정한다.
root@1806de65757a:/usr/local/tomcat# vi /usr/local/tomcat/webapps/manager/META-INF/context.xml
~~~ ~~~
         allow="127.0.0.0/8,::1/128,192.168.100.1/24" />
~~~ ~~~
</Context>
root@1806de65757a:/usr/local/tomcat# exit


Rocky Linux 9 Docker Host에서 실행한다.
[root@docker ~]# docker restart tomcat9.0

 

http://192.168.100.24:8080/manager/html


1. 가상머신 생성
  . 배포판: Rocky Linux 9
  . VM이름: RockyLinux9-Docker2
2. 네트워크 설정
  . set_ip.sh 스크립트를 이용한다.
  . IP주소: 192.168.100.25/24
  . 기본 게이트웨이: 192.168.100.2
  . DNS 서버: 168.126.63.1 168.126.63.2
3. Rocky Linux 9 에서 Docker 설치하기
  . install_docker.sh 스크립트를 이용한다.
4. Docker network 생성
  . tomcatoracle 네트워크 생성
5. oracle11gxe 컨테이너 생성
  . tomcatoracle 네트워크
    - 고정 IP주소: 172.20.20.2
6. tomcat9.0 컨테이너 생성  
  . tomcatoracle 네트워크
    - 고정 IP주소: 172.20.20.3
7. jdbc 드라이버 연동
8. jumsu.war 설정
  . DB 접속
    - String dbhost = "jdbc:oracle:thin:@oracle11gxe:1521:XE";
9. nginx 를 이용한 리버스 프록시 설정

    - 고정 IP주소: 172.20.20.4
 . Client (80/tcp)  -> http://192.168.100.25  -> Nginx Proxy -> Tomcat:8080
 . Client (443/tcp) -> https://192.168.100.25 -> Nginx Proxy -> Tomcat:8080 
10. 웹페이지 접속
  . http://192.168.100.25:8080/jumsu/index.jsp
  . http://192.168.100.25/jumsu/index.jsp
  . https://192.168.100.25/jumsu/index.jsp


Rocky Linux 9에서 Docker 설치 

 

네트워크 관련 정보가 저장되는 파일
/etc/NetworkManager/system-connections/ens160.nmconnection

[root@localhost ~]# cat /etc/NetworkManager/system-connections/ens160.nmconnection
[connection]
id=ens160
uuid=3ecf5a48-89e4-3200-ae13-13df17bf86ca
type=ethernet
autoconnect-priority=-999
interface-name=ens160
timestamp=1779151805

[ethernet]

[ipv4]
address1=192.168.100.25/24
dns=1.2.3.4;2.3.4.5;
gateway=192.168.100.2
method=manual

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]


[root@localhost ~]# nmcli connection show
NAME     UUID                                  TYPE      DEVICE
ens160   3ecf5a48-89e4-3200-ae13-13df17bf86ca  ethernet  ens160
docker0  ea7f66c6-a144-4f9a-9347-1581d72c7603  bridge    docker0
lo       cc0855cf-e6a1-4245-8103-d69006f53711  loopback  lo


[root@localhost ~]# nmcli c s
NAME     UUID                                  TYPE      DEVICE
ens160   3ecf5a48-89e4-3200-ae13-13df17bf86ca  ethernet  ens160
docker0  ea7f66c6-a144-4f9a-9347-1581d72c7603  bridge    docker0
lo       cc0855cf-e6a1-4245-8103-d69006f53711  loopback  lo


IP주소를 변경한다.
[root@localhost ~]# nmcli connection modify ens160 ipv4.addresses 192.168.100.26/24
[root@localhost ~]# grep -A 5 ipv4 /etc/NetworkManager/system-connections/ens160.nmconnection
[ipv4]
address1=192.168.100.26/24
dns=168.126.63.1;168.126.63.2;
gateway=192.168.100.2
method=manual

DNS 정보를 변경한다.
[root@localhost ~]# nmcli con mo ens160 ipv4.dns "1.1.1.1 1.1.1.2"
[root@localhost ~]# grep -A 5 ipv4 /etc/NetworkManager/system-connections/ens160.nmconnection
[ipv4]
address1=192.168.100.26/24
dns=1.1.1.1;1.1.1.2;
gateway=192.168.100.2
method=manual

 

기본 게이트웨이를 변경한다.
[root@localhost ~]# nmcli con mo ens160 ipv4.gateway 1.1.1.5
[root@localhost ~]# grep -A 5 ipv4 /etc/NetworkManager/system-connections/ens160.nmconnection
[ipv4]
address1=192.168.100.26/24
dns=1.1.1.1;1.1.1.2;
gateway=1.1.1.5
method=manual

 

IP주소: 고정IP 설정, DHCP 자동 IP 설정
[root@localhost ~]# nmcli con mo ens160 ipv4.method auto
[root@localhost ~]# grep -A 5 ipv4 /etc/NetworkManager/system-connections/ens160.nmconnection
[ipv4]
address1=192.168.100.26/24
dns=1.1.1.1;1.1.1.2;
gateway=1.1.1.5
method=auto

[root@localhost ~]# nmcli con mo ens160 ipv4.method manual
[root@localhost ~]# grep -A 5 ipv4 /etc/NetworkManager/system-connections/ens160.nmconnection
[ipv4]
address1=192.168.100.26/24
dns=1.1.1.1;1.1.1.2;
gateway=1.1.1.5
method=manual


Rocky Linux 9에서 네트워크 설정 스크립트 

-- set_ip.sh --

#!/bin/bash
# 프로그램 설명: 네트워크 정보 설치 스크립트

CON_NAME="ens160"
IPADDR="192.168.100.25/24"
GATEWAY="192.168.100.2"
DNS1="168.126.63.1"
DNS2="168.126.63.2"
HOSTNAME="docker.linuxmaster.net"

nmcli con mod $CON_NAME ipv4.addresses $IPADDR
nmcli con mod $CON_NAME ipv4.gateway $GATEWAY
nmcli con mod $CON_NAME ipv4.dns "$DNS1 $DNS2"
nmcli con mod $CON_NAME ipv4.method manual

nmcli con down "$CON_NAME"
nmcli con up "$CON_NAME"

hostnamectl set-hostname $HOSTNAME

SERVER_IP=$(hostname -I)
echo "$SERVER_IP $HOSTNAME" >> /etc/hosts


가상머신을 새롭게 생성하고 로그인해서 wget 패키지를 설치한다.
dnf -y install wget 

wget 192.168.7.101/set_ip.sh
chmod 755 set_ip.sh
./set_ip.sh
exit
su -

[root@docker ~]# cat /etc/NetworkManager/system-connections/ens160.nmconnection
[connection]
id=ens160
uuid=3ecf5a48-89e4-3200-ae13-13df17bf86ca
type=ethernet
autoconnect-priority=-999
interface-name=ens160
timestamp=1779154637

[ethernet]

[ipv4]
address1=192.168.100.25/24
dns=168.126.63.1;168.126.63.2;
gateway=192.168.100.2
method=manual

[ipv6]
addr-gen-mode=eui64
method=auto

[proxy]


Rocky Linux 9 에서 Docker 설치하기

Docker를 설치하는 자동화 스크립트를 이용한다.

-- install_docker.sh --
#!/bin/bash
# 프로그램 설명: Docker를 설치하는 자동화 스크립트

dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker.service
systemctl status docker --no-pager

[root@docker ~]# chmod 755 install_docker.sh
[root@docker ~]# ./install_docker.sh


Rocky Linux 9 에서 Docker 설치하기

Docker를 설치하는 자동화 스크립트를 이용한다.
-- install_docker.sh --
#!/bin/bash
# 프로그램 설명: Docker를 설치하는 자동화 스크립트
dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
systemctl enable --now docker.service
systemctl status docker --no-pager
#docker version
ip -br -4 a


Docker network 생성 스크립트 제작하기
-- docker_create_network.sh --
#!/bin/sh
# 프로그램 설명: Docker network 생성 스크립트

SUBNET="172.20.20.0/24"
GATEWAY="172.20.20.1"
NETWORK_NAME="tomcatoracle"

docker network create --driver bridge \
  --subnet $SUBNET \
  --gateway $GATEWAY \
  $NETWORK_NAME 2>/dev/null || true

docker network ls
ip -br -4 a


Oracle 11gXE 이미지/컨테이너 생성 스크립트 제작하기
-- oracle11gxe_create.sh --
#!/bin/sh
# 프로그램 설명: oracle11gxe 이미지를 설치하는 스크립트

docker run -d --restart=always -p 1521:1521 \
--network tomcatoracle --ip 172.20.20.2 \
--name oracle11gxe oracleinanutshell/oracle-xe-11g

docker inspect oracle11gxe | grep -i ipadd
docker ps

dnf -y install wget
wget linuxmaster.net/scott.sql.txt
docker cp scott.sql.txt oracle11gxe:/root

cat << EOF
아래 내용은 수동으로 설정해야 합니다.
[root@docker ~]# docker exec -it oracle11gxe bash
root@f23d35c94108:/# sqlplus sys/oracle as sysdba
SQL> @/root/scott.sql.txt
SQL> exit
root@f23d35c94108:/# exit
EOF

[root@docker ~]# chmod 755 oracle11gxe_create.sh
[root@docker ~]# ./oracle11gxe_create.sh
[root@docker ~]# docker exec -it oracle11gxe bash
root@f23d35c94108:/# sqlplus sys/oracle as sysdba
SQL> @/root/scott.sql.txt
SQL> exit
root@f23d35c94108:/# exit
EOF


Oracle 11gXE 이미지/컨테이너 save 하기
명령어 설명
  . docker commit 
    - 컨테이너 상태를 이미지로 저장한다.
  . oracle11gxe 
    - 저장할 대상 컨테이너의 이름이다.
  . oracle11gxe-scott:v1
    - 새로 만들 이미지 이름과 태그명이다.
    - 이미지 이름과 태그명은 자유롭게 지정할 수 있다.
[root@docker ~]# docker commit oracle11gxe oracle11gxe-scott:v1

oracle11gxe-scott:v1 이미지를 tar 파일로 저장한다.
[root@docker ~]# docker save -o oracle11gxe-scott-v1.tar oracle11gxe-scott:v1

생성된 이미지 파일을 확인한다.
[root@docker ~]# ll oracle11gxe-scott-v1.tar
-rw-------. 1 root root 806931456 May 19 11:52 oracle11gxe-scott-v1.tar
[root@docker ~]# docker rm -f oracle11gxe
[root@docker ~]# docker rmi oracleinanutshell/oracle-xe-11g:latest

docker run -d --restart=always -p 1521:1521 \
--network tomcatoracle --ip 172.20.20.2 \
--name oracle11gxe oracle11gxe-scott:v1 
SQLDeveloper 에서 docker의 oracle11gxe-scott으로 접속한다.

기존 오라클 컨테이너와 이미지를 지워준다

[root@docker ~]# docker rm -f oracle11gxe
[root@docker ~]# docker rmi oracleinanutshell/oracle-xe-11g:latest


Tomcat9 컨테이너 생성 스크립트

-- tomcat9.0_create.sh --

#!/bin/sh
# 프로그램 설명: Tomcat9.0 컨테이너를 생성성하는 스크립트

IPADDRESS=$(hostname -I | awk '{print $1}')
CONTAINER_NAME="tomcat9.0"
TOMCAT_USER="admin"
TOMCAT_PASSWD="1234"
ALLOW_IP="127.0.0.0/8,::1/128,192.168.100.1/24"

# tomcat 9.0 이미지 및 컨테이너 생성
docker run -d --restart=always \
--network tomcatoracle --ip 172.20.20.3 \
-p 8080:8080 -p 8009:8009 \
-e LC_ALL=C.UTF-8 \
-v /home/tomcat:/usr/local/tomcat/webapps/ROOT/ \
--name tomcat9.0 \
tomcat:9.0

# docker inspect tomcat9.0 | grep -i ipadd

# JDBC 드라이버 설치
cat << EOF > /home/tomcat/jdbcdrivertest.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.sql.*" %>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>::: Oracle JDBC 드라이버 테스트 :::</title>
</head>
<body>

<%
try {
    Class.forName("oracle.jdbc.OracleDriver");
    out.println("드라이버 로드 성공<br>");
} catch (Exception e) {
    out.println("드라이버 로드 실패<br>");
    //out.println(e);
}
%>

</body>
</html>
EOF

dnf -y install lynx > /dev/null 2>&1

docker cp oracle11gxe:/u01/app/oracle/product/11.2.0/xe/jdbc/lib/ojdbc6.jar .
docker cp ojdbc6.jar tomcat9.0:/usr/local/tomcat/lib
docker restart tomcat9.0

lynx --dump http://192.168.100.25:8080/jdbcdrivertest.jsp

cat << EOF > /home/tomcat/getemp.jsp
<%--
파일명: getemp.jsp
프로그램 설명: EMP 테이블의 내용을 출력한다.
--%>

<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%!
  // 변수 선언
  String dbhost = "jdbc:oracle:thin:@oracle11gxe:1521:XE";
  //String dbhost = "jdbc:oracle:thin:@172.20.20.2:1521:XE";
  String dbuser = "scott";
  String dbpass = "tiger";
  String query = "SELECT * FROM EMP";
  String title = "::: EMP 테이블 출력하기 :::";

  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
%>

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title> <%=title%> </title>
  <style>
    table {
      margin-left:auto;
      margin-right:auto;
      width: 800px;
      border: 1px solid #444444;
      border-collapse: collapse;
    }
    tr, td {
      border: 1px solid #444444;
      padding: 7px;
    }
   </style>
</head>
<body>

<table>

<tr align="center">
  <td align="center" colspan="8"> 테이블명: EMP (사원 테이블) </td>
</tr>

<tr align="center" bgcolor="#ffffff">
  <td align="center"> 사원 번호 </td>
  <td align="center"> 사원 이름 </td>
  <td align="center"> 사원 직책 </td>
  <td align="center"> 직속 상관 </td>
  <td align="center"> 입사일 </td>
  <td align="center"> 급여 </td>
  <td align="center"> 추가 수당 </td>
  <td align="center"> 부서 번호 </td>
</tr>

<%
      try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
      } catch (ClassNotFoundException e ) {
            e.printStackTrace();
        }
        try {
            conn = DriverManager.getConnection(dbhost, dbuser, dbpass);
            stmt = conn.createStatement();
            rs = stmt.executeQuery(query);

            // EMP 테이블에서 자료가 없을 때 까지 출력한다.
            while (rs.next())
            {
                // EMP 테이블에서 자료를 가져오는 부분
                String EMPNO    = rs.getString("EMPNO");  // 컬럼명으로 가져오기
                String ENAME    = rs.getString("ENAME");
                String JOB      = rs.getString("JOB");
                String MGR      = rs.getString(4);  // 컬럼의 순서로 가져오기
                String HIREDATE = rs.getString(5);
                String SAL      = rs.getString(6);
                String COMM     = rs.getString(7);
                String DEPTNO   = rs.getString(8);

                // 가져온 데이터를 브라우저에 출력하는 부분
                out.print("<tr align=\"center\" bgcolor=\"#ffffff\">" +
                          "<td>" + EMPNO    + "</td>" +
                          "<td>" + ENAME    + "</td>" +
                          "<td>" + JOB      + "</td>" +
                          "<td>" + MGR      + "</td>" +
                          "<td>" + HIREDATE + "</td>" +
                          "<td>" + SAL      + "</td>" +
                          "<td>" + COMM     + "</td>" +
                          "<td>" + DEPTNO   + "</td>" +
                          "</tr>");
            }
        } catch ( Exception e ) {
            e.printStackTrace();
        } finally {
            try {
                rs.close();
                stmt.close();
                conn.close();
            } catch ( Exception e ) {
                e.printStackTrace();
            }
        }
%>
</table>
</body>
</html>
EOF


echo "웹페이지 접속"
echo "http://$IPADDRESS:8080/getemp.jsp"


# tomcat-users.xml 파일 생성
cat << EOF > tomcat-users.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
<!--
  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary.

  Built-in Tomcat manager roles:
    - manager-gui    - allows access to the HTML GUI and the status pages
    - manager-script - allows access to the HTTP API and the status pages
    - manager-jmx    - allows access to the JMX proxy and the status pages
    - manager-status - allows access to the status pages only

  The users below are wrapped in a comment and are therefore ignored. If you
  wish to configure one or more of these users for use with the manager web
  application, do not forget to remove the <!.. ..> that surrounds them. You
  will also need to set the passwords to something appropriate.
-->
<!--
  <user username="admin" password="<must-be-changed>" roles="manager-gui"/>
  <user username="robot" password="<must-be-changed>" roles="manager-script"/>
-->
<!--
  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-status"/>
  <role rolename="admin-gui"/>

  <user username="$TOMCAT_USER" password="$TOMCAT_PASSWD" roles="manager-gui,manager-script,manager-status,admin-gui"/>

</tomcat-users>
EOF

# context.xml 파일 생성
cat << EOF > context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
  <Valve className="org.apache.catalina.valves.RemoteCIDRValve"
         allow="$ALLOW_IP" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>
EOF

# manager 복사
docker exec $CONTAINER_NAME cp -r /usr/local/tomcat/webapps.dist/manager /usr/local/tomcat/webapps/

# 생성된 설정파일을 컨테이너로 복사
docker cp tomcat-users.xml $CONTAINER_NAME:/usr/local/tomcat/conf/tomcat-users.xml
docker cp context.xml $CONTAINER_NAME:/usr/local/tomcat/webapps/manager/META-INF/context.xml

# tomcat 컨테이너 재시작
docker restart $CONTAINER_NAME


[root@docker ~]# chmod 755 tomcat9.0_create.sh
[root@docker ~]# ./tomcat9.0_create.sh

아래 주소로 접속해서 emp 테이블이 나오는지 확인한다.
http://192.168.100.25:8080/getemp.jsp


jumsu 애플리케이션 배포하기

jumsu.war 파일
  . jsp로 작성한 jumsu 애플리케이션
  . 컨테이너에 업로드하는 2가지 방법
    - Tomcat Manager로 업로드
    - 직접 webapps 디렉터리에 복사

webapps에 직접 복사하는 방법

jumsu.war 파일을 리눅스 서버로 원격 복사를한다.
C:\JAVAJSPDEVEL>scp jumsu.war admin@192.168.100.25:

업로드된 jumsu.war 파일을 tomcat9.0 컨테이너 안으로 docker cp를 한다.
[root@docker ~]# docker cp ~admin/jumsu.war tomcat9.0:/usr/local/tomcat/webapps

 

DB 설계
jumsu 애플리케이션에서 사용할 테이블을 생성한다.


[root@docker ~]#  cat << EOF > jumsu.sql 
DROP TABLE JUMSU PURGE;
DROP TABLE JUMSUMEMBER PURGE;
CREATE TABLE JUMSUMEMBER
(
    NO NUMBER(4),
    USERNAME VARCHAR2(30) NOT NULL,
    USERID VARCHAR2(30) NOT NULL,  
    USERPW VARCHAR2(20) NOT NULL,  
    REGDATE DATE,  
        CONSTRAINT JUMSUMEMBER_NO_PK PRIMARY KEY(NO),
        CONSTRAINT JUMSUMEMBER_USERID_UK UNIQUE(USERID)
);
DROP SEQUENCE JUMSUMEMBER_SEQ;
CREATE SEQUENCE JUMSUMEMBER_SEQ;
COMMENT ON TABLE JUMSUMEMBER IS '회원테이블';
COMMENT ON COLUMN JUMSUMEMBER.NO IS '번호';
COMMENT ON COLUMN JUMSUMEMBER.USERNAME IS '회원명';
COMMENT ON COLUMN JUMSUMEMBER.USERID IS '아이디';
COMMENT ON COLUMN JUMSUMEMBER.USERPW IS '비밀번호';
COMMENT ON COLUMN JUMSUMEMBER.REGDATE IS '가입날짜';
CREATE TABLE JUMSU
(
    NO NUMBER(4) NOT NULL, 
    USERID VARCHAR2(30) NOT NULL,  
    KOR NUMBER(3) NOT NULL, 
    ENG NUMBER(3) NOT NULL, 
    MATH NUMBER(3) NOT NULL,  
    TOTAL NUMBER(3) NOT NULL,  
    AVERAGE NUMBER(5,2) NOT NULL,  
    REGDATE DATE,  
    CONSTRAINT JUMSU_NO_PK PRIMARY KEY(no),
    CONSTRAINT JUMSU_USERID_FK FOREIGN KEY(userid) REFERENCES JUMSUMEMBER(userid)
);
DROP SEQUENCE JUMSU_SEQ;
CREATE SEQUENCE JUMSU_SEQ;
COMMENT ON TABLE JUMSU IS '점수테이블';
COMMENT ON COLUMN JUMSU.NO IS '번호';
COMMENT ON COLUMN JUMSU.USERID IS '아이디';
COMMENT ON COLUMN JUMSU.KOR IS '국어점수';
COMMENT ON COLUMN JUMSU.ENG IS '영어점수';
COMMENT ON COLUMN JUMSU.MATH IS '수학점수';
COMMENT ON COLUMN JUMSU.TOTAL IS '총점';
COMMENT ON COLUMN JUMSU.AVERAGE IS '평균';
COMMENT ON COLUMN JUMSU.REGDATE IS '가입날짜';
EOF

[root@docker ~]# docker cp jumsu.sql oracle11gxe:/root
[root@docker ~]# docker exec -it oracle11gxe bash
root@220afffe3067:/# sqlplus scott/tiger

이클립스에서 .war파일 수정하는 방법 

export -> web -> war로 war 수정할 war 파일 선택

수정하고 저장 후

export -> web -> war-> over write 선택 

.war 파일을 저장한 후 다시 리눅스로 올리면 된다


tomcat9.0을 tomcat9.0-jumsu:v1 저장하기

1. 이미지 저장
tomcat9.0-jumsu:v1 이미지를 tar 파일로 저장한다.
[root@docker ~]# docker commit tomcat9.0 tomcat9.0-jumsu:v1

[root@docker ~]# docker images

tomcat9.0-jumsu:v1 이미지를 tar 파일로 저장한다.
[root@docker ~]# docker save -o tomcat9.0-jumsu-v1.tar tomcat9.0-jumsu:v1
[root@docker ~]# ll tomcat9.0-jumsu-v1.tar
-rw-------. 1 root root 156632064 May 19 16:42 tomcat9.0-jumsu-v1.tar

[root@docker ~]# docker rm -f tomcat9.0
[root@docker ~]# docker rmi tomcat:9.0

2. 스크립트 생성 및 실행
Tomcat 컨테이너 생성 시 외부 포트로 공개하던 -p 8080:8080, -p 8009:8009 옵션을 제거하여 
외부에서 Tomcat으로 직접 접속하지 못하도록 구성한다.
이렇게 설정하면 사용자는 Tomcat의 8080 포트로 직접 접속할 수 없으며 
Nginx Reverse Proxy의 80/tcp 또는 443/tcp 포트를 통해서만 Tomcat 애플리케이션에 접근할 수 있다.
Tomcat 컨테이너는 Docker 내부 네트워크인 tomcatoracle 안에서만 통신 가능하도록 구성하고 
외부 요청은 반드시 Nginx Reverse Proxy를 거쳐 Tomcat 9.0 컨테이너의 8080 포트로 전달되도록 스크립트를 작성한다.

[root@docker ~]# vi tomcat9.0_create2.sh
#!/bin/sh
# 프로그램 설명: Tomcat9.0 (jumsu) 컨테이너를 생성하는 스크립트

IPADDRESS=$(hostname -I | awk '{print $1}')
CONTAINER_NAME="tomcat9.0"
TOMCAT_USER="admin"
TOMCAT_PASSWD="1234"
ALLOW_IP="127.0.0.0/8,::1/128,192.168.100.1/24"

# tomcat 9.0 이미지 및 컨테이너 생성
docker run -d --restart=always \
--network tomcatoracle --ip 172.20.20.3 \
-e LC_ALL=C.UTF-8 \
-v /home/tomcat:/usr/local/tomcat/webapps/ROOT/ \
--name tomcat9.0 \
tomcat9.0-jumsu:v1
# tomcat9.0-jumsu:v1 (New)
# tomcat:9.0 (Old)

[root@docker ~]# chmod 755 tomcat9.0_create2.sh
[root@docker ~]# ./tomcat9.0_create2.sh


Nginx Reverse Proxy로 Tomcat 8080 연결하기

프록시와 리버스프록시 차이
  . 리버스 프록시는 외부 요청의 "입구(게이트웨이)" 역할을 하면서 내부 서비스로 안전하게 라우팅해주는 프론트 서버이다.
  . 정방향(Forward) 프록시: 내부 사용자가 외부로 나갈 때 프록시 서버가 받아서 대신 나간다.
    e.g.) 회사에서 직원 PC → 프록시 서버 → 인터넷, iptables의 SNAT를 생각하자
  . 리버스(Reverse) 프록시: 외부 사용자가 내부 서버로 들어올 때 앞에서 프록시 서버가 대신 받는다.
    e.g.) 인터넷 사용자 → Nginx → 내부의 tomcat9.0, WordPress/DB/, iptables DNAT를 생각하자.

 

[root@docker ~]# vi nginx_proxy_create.sh

#!/bin/sh
mkdir -p /root/nginx-proxy/conf.d
cat << 'EOF' > /root/nginx-proxy/conf.d/tomcat.conf
server {
    listen 80;
    server_name 192.168.100.24;
    location / {
        proxy_pass http://tomcat9.0:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
EOF


docker run -d --name nginx-proxy \
--network tomcatoracle \
--ip 172.20.20.4 \
-p 80:80 \
-v /root/nginx-proxy/conf.d:/etc/nginx/conf.d:ro nginx

docker exec nginx-proxy nginx -t

 

접속 
Nginx Reverse Proxy를 통해 Tomcat 애플리케이션에 접속되는지 확인한다.
Tomcat의 8080 포트는 외부에 직접 공개하지 않고 Nginx의 80/tcp, 443/tcp 포트를 통해서만 접속하도록 구성한다.
http://192.168.100.25/jdbcdrivertest.jsp
드라이버 로드 성공

http://192.168.100.25/getemp.jsp

http://192.168.100.25/jumsu/ <-- 접속 O
https://192.168.100.25/jumsu/  <-- 접속 O
http://192.168.100.25:8080/jumsu/  <-- 접속 X