본문 바로가기
Cloud/Azure

AKS(Azure Kubernetes Service) 3Tire - 2

by 팡팡마트 2023. 11. 6.
728x90

1. was container 구성

[가상머신에 java 설치]

# mkdir /usr/bin/java

# cd /usr/bin/java

# wget https://download.java.net/java/GA/jdk18.0.2/f6ad4b4450fd4d298113270ec84f30ee/9/GPL/openjdk-18.0.2_linux-x64_bin.tar.gz

# tar xvzf openjdk-18.0.2_linux-x64_bin.tar.gz

 

환경변수추가

# vi /etc/profile

페이지 하단에 추가

export JAVA_HOME=/usr/bin/java/jdk-18.0.2
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/tools.jar

 

변경내용 적용

# source /etc/profile

 

변경확인

# echo $JAVA_HOME

 

[DB설정]

# mysql -h [mysql 엔드포인트] -u [계정명] -p

# mysql > create database petclinic;

 

[펫클리닉 설치]

# yum install git

# git clone https://github.com/spring-projects/spring-petclinic.git

 

GitHub - spring-projects/spring-petclinic: A sample Spring-based application

A sample Spring-based application. Contribute to spring-projects/spring-petclinic development by creating an account on GitHub.

github.com

# cd spring-petclinic

# vi src/main/resources/application-mysql.properties

JDBC 연결 확인하여 수정

spring.datasource.url=${MYSQL_URL:jdbc:mysql://[mysql endpoint]:3306/petclinic}
spring.datasource.username=${MYSQL_USER:[ID]}
spring.datasource.password=${MYSQL_PASS:[PW]}

 

[펫클리닉 빌드]

git clone 디렉토리에서 빌드 실행

#  ./mvnw package

 

[was Dockerfile 생성]

Docker용 디렉토리 생성

# mkdir was

jar 파일 복사

# cp /home/azure/spring-petclinic/target/spring-petclinic-3.1.0-SNAPSHOT.jar /home/azure/was/

#vi Dockerfile

FROM openjdk:18
ADD spring-petclinic-3.1.0-SNAPSHOT.jar /spring-petclinic-3.1.0-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=mysql", "/spring-petclinic-3.1.0-SNAPSHOT.jar"]

 

[was 컨테이너 빌드]

# docker build -t was:1 .

# docker run --name was -d -p 8080:8080 was:1

# docker ps

 

2. web container 구성

[web Dockerfile 생성]

# mkdir web

# vi Dockerfile

FROM centos:7

RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
RUN sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
RUN yum install -y httpd && yum clean all
RUN echo "Hello Docker" > /var/www/html/index.html
CMD ["/usr/sbin/httpd", "-DFOREGROUND"]

 

[web 컨테이너 빌드]

# docker build -t web:1 .

# docker run --name web -d -p 80:80 web:1

# docker ps

web,was 컨테이너 확인

 

3. web-was 연동

reverse proxy 사용

was 컨테이너 ip확인

# docker inspect was | grep IPAddress

web 컨테이너로 이동

# docker exec -it web /bin/bash

conf파일 수정

# vi /etc/httpd/conf/httpd.conf

페이지 하단에 추가

<VirtualHost *:80>

 ServerName localhost

 ProxyRequests Off

 ProxyPreserveHost On

  <Proxy *>

    Order deny,allow

     Allow from all

  </Proxy>

     ProxyPass / http://172.17.0.2:8080/ disablereuse=on

     ProxyPassReverse / http://172.17.0.2:8080/

</VirtualHost>

# exit

 

재시작

# docker restart web

 

VM의 ip로 접속하면 was 페이지로 리다이렉트

 

**이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

728x90