카테고리 없음

AWS- 7/8일 Cloud 3Tier 아키텍처 구성 발표 (2/2)

클라우디아랩 2021. 7. 8. 18:13

IP 리스트

 

 

5. web-01, web-02에 web server 구성

 

web-01, web-02 각각 EC2에 web 서버 설치

#sudo su

#yum update

#yum -y install httpd

#systemctl start httpd

#systemctl enable httpd

 

 

index.html 파일 생성

[web-01]# vi /var/www/html/index.html

<h1> web-01 </h1>

 

[web-02]# vi /var/www/html/index.html

<h1> web-02 </h1>

 

 

DNS 이름에 복사 모양 클릭

 

 

F5를 계속누르면 web server가 로드 밸런싱함

 

 

 

 

6. was-01, was-02에 was server 구성

 

자바 설치

#sudo su

# yum update

# yum -y install java-1.8.0-openjdk

# yum -y install java-1.8.0-openjdk-devel.x86_64

# javac -version

 

자바 환경구성

# vi /etc/profile (맨 아래쪾에 붙여넣기)

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.amzn2.0.1.x86_64/jre
export CATALINA_HOME=/usr/local/src/tomcat9.0
export CLASSPATH=$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

 

변경 내용 적용

# source /etc/profile

 

톰캣 설치

# wget https://downloads.apache.org/tomcat/tomcat-9/v9.0.48/bin/apache-tomcat-9.0.48.tar.gz

# tar xvzf apache-tomcat-9.0.48.tar.gz

# ls

# mv apache-tomcat-9.0.48 /usr/local/src/tomcat9.0

 

vi 에디터로 server.xml 편집

# vi /usr/local/src/tomcat9.0/conf/server.xml

<Connector port="8080" protocol="HTTP/1.1"
        URIEncoding="UTF-8"         //추가
               connectionTimeout="20000"
               redirectPort="8443" />

 

톰캣 시작

# /usr/local/src/tomcat9.0/bin/startup.sh

 

 

대상 그룹이 상태가 변하는데 1~3분 정도 걸림

 

 

 

 

 

7. WAS와 Proxy 설정을 통한 WEB-WAS 연동 (mod proxy 사용)

 

 

was-01, was-02 에서 was 연동 설정

 

로드발란서에서 int-elb 의 dns 이름 복사

 

#sudo su

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

 

Include conf.modules.d/*.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so

 

 

(맨 아래쪽에 붙여넣기)

<VirtualHost *:80>              // ext-alb dns 이름 복사 넣기
ServerName ex-alb-913834992.ap-northeast-2.elb.amazonaws.com
ErrorLog logs/counterjp.fureweb.com-error_log
ProxyRequests Off  //리버스 프록시 모드 off
ProxyPreserveHost On  //was로 리다이렉트 시 host 정보도 같이 전달
<Proxy *>
Order deny,allow  //명령어 우선순위
Allow from all  // 서버 접근 허용
</Proxy>                      //int-alb dns 이름 복사한 것 넣기
ProxyPass / http://internal-int-alb-491861152.ap-northeast-2.elb.amazonaws.com:8080/
ProxyPassMatch ^/(.*\.do)$ http://internal-int-alb-491861152.ap-northeast-2.elb.amazonaws.com:8080/
ProxyPassMatch ^/(.*\.jsp)$ http://internal-int-alb-491861152.ap-northeast-2.elb.amazonaws.com:8080/
ProxyPassReverse / http://internal-int-alb-491861152.ap-northeast-2.elb.amazonaws.com:8080/

</VirtualHost>

 

아파치 데몬 재시작

#systemctl restart httpd

 

톰캣 접속된 홈페이지를 볼 수 있다.

 

 

 

 

8. DB 설정

 

db-01 EC2에 접속하여 설정

# sudo su

#yum update

#yum -y install mysql-server
#systemctl restart mysqld

 

mysql 설치

# wget yum -y install http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

# yum -y install mysql-community-server

 

mysql 암호 초기화

# cat /var/log/mysqld.log | grep root@localhost

... A temporary password is generated for root@localhost: 135156<

# mysql_secure_installation

Enter password for user root: 135156<

..

New password: 입력

Re-enter new password: 입력

..

Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password: 입력
Re-enter new password: 입력

..

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

...

Remove anonymous users? (Press y|Y for Yes, any other key for No) :y

...

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :y

...

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y

...

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

...

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

 

DB 설정

# mysql -u root -p

 

DB접속 계정 만들기

mysql> create user 'admin'@'%' identified by 'Root!234';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on test.* to 'admin'@'%';
Query OK, 0 rows affected (0.00 sec)

 

데이터베이스 생성

mysql> create database test;
Query OK, 1 row affected (0.00 sec)

mysql> use test;
Database changed

 

샘플데이터 만들기

mysql> create table user (userID int, userPassword int);
Query OK, 0 rows affected (0.02 sec)

mysql> insert  into user values (1, 1111);
Query OK, 1 row affected (0.01 sec)

mysql> insert  into user values (2, 2222);
Query OK, 1 row affected (0.00 sec)

mysql> insert  into user values (3, 3333);
Query OK, 1 row affected (0.01 sec)

mysql> select * from user;
+--------+--------------+
| userID | userPassword |
+--------+--------------+
|      1 |         1111 |
|      2 |         2222 |
|      3 |         3333 |
+--------+--------------+
3 rows in set (0.00 sec)

 

mysql> exit
Bye

 

DB포트 오픈 확인

[root@ip-10-1-12-224 ec2-user]# netstat -nlp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      547/mysqld

 

 

 

 

 

 

9. WAS 와 DB 연동 설정

was-01, was-02 EC2에서 jsp 새 파일 생성

 

# sudo su

# vi /usr/local/src/tomcat9.0/webapps/ROOT/dbcon.jsp

 

<%@ page import = "java.sql.*" %>
<%
                Statement stm = null;
        ResultSet rs = null;
        Class.forName("com.mysql.jdbc.Driver");
        String myUrl = "jdbc:mysql://10.1.12.224:3306/test";
        Connection conn = DriverManager.getConnection(myUrl, "admin", "Root!234");
        try {
                        stm = conn.createStatement();
                if(stm.execute("select * from user")) {
                                rs = stm.getResultSet();
                }
                        while(rs.next()) {
                        out.println(rs.getString("userID"));
                        out.println(rs.getString("userPassword"));
                        out.write("<br>");
        }
        rs.close();
        stm.close();
        }
catch(Exception e) {
                out.println("rs.next() ERROR");
}
conn.close();
%>

 

was-01, was-02 EC2에서 세팅 (DB 연결)

# wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-8.0.22.tar.gz

# tar xvzf mysql-connector-java-8.0.22.tar.gz
# cp mysql-connector-java-8.0.22.jar /usr/lib/jvm/jre/lib/ext/

#/usr/local/src/tomcat9.0/bin/shutdown.sh

#/usr/local/src/tomcat9.0/bin/startup.sh

 

 

 

 

웹 브라우저에서  F5로 계속 눌려보면 로드발란싱하면서 DB에서 가져와서 웹 페이지에서 확인 가능

 

 

 

 

 

 

 

 

 

참고:

아파치 설정
https://honeywater97.tistory.com/90?category=1179725

 

톰캣 설정
https://cloudest.tistory.com/48

 

3티어 아키텍처

https://pearlluck.tistory.com/84?category=855676