728x90

인터페이스 이중화


- 기존에는 하나의 인터페이스에 하나의 IP 주소 할당 및 사용

- 인터페이스 문제 발생 시 서비스 제공에 지장

- 인터페이스마다 주소가 다르면 접근이 어려움

- 인터페이스 여러 개를 묶어서 사용하는 형태 ===> 본딩 / 티밍 두 가지 방식 존재

 


네트워크 티밍


티밍이란?

- RHEL7 버전부터 제공 (기존의 본딩 방식에서 변경 가능)

- 본딩에 비해 사용자(관리자) 입장에서 편의성 제공

- 인터페이스 장애에 대한 대비

- 효율성 증대

- IP 주소에 대한 부담 감소

- 여러 개의 인터페이스에 대해 IP 주소를 하나만 설정

- 목적:  인터페이스에 문제가 발생하더라도 네트워크가 끊어지지 않도록 하기위함

 

 

러너

- 티밍 구성 시 동작 방식 지정 (트래픽 처리 방식)

- 러너 방식

러너 설명
broadcast 각각의 인터페이스마다 패킷 전달
roundrobin
하나씩 번갈아가면서 패킷 전달
loadbalance 처리량(상태)에 따라 부하분산 기능 제공
active-backup 장애 복구 방식의 기능만 제공
LACP 네트워크 장비(스위치)에서 설정해둔 방식으로 동작

 


 

인터페이스 준비


NAT 네트워크 카드 두 개 설정

> 가상 머신 전원 끄기

> 가상 머신 속성

> 네트워크

> 어댑터 총 3개 설정: NAT 네트워크 2개, 호스트 전용 어댑터 1개

 

 

 

 

 


인터페이스 아키텍처


- 팀 인터페이스를 활성화하더라도 포트 인터페이스는 활성화되지 않음

- 포트 인터페이스 활성화 시 팀 인터페이스 자동 활성화

- 포트 인터페이스 비활성화 시 팀 인터페이스 활성화 유지

- 팀 인터페이스 비활성화 시 모든 포트 인터페이스 비활성화

 

 


인터페이스 설정


NAT 네트워크 비활성화 (enp0s3, enp0s9)

# 연결된 인터페이스 확인

[root@team ~]# nmcli c s
NAME                UUID                                  TYPE      DEVICE
Wired connection 1  a97fc47b-0dd9-3d92-a146-17b8947a836c  ethernet  enp0s9
enp0s8              12fddb3e-080a-4945-9673-80141255a31b  ethernet  enp0s8
virbr0              c1ec0042-e850-4398-8e21-7411149e676d  bridge    virbr0
enp0s3              f093169b-ee0b-4740-9f54-4056c6c3d1bf  ethernet  --

# NAT 네트워크 비활성화
[root@team ~]# nmcli con down enp0s3
[root@team ~]# nmcli con down Wired connection 1

# 인터페이스 상태 확인
[root@team ~]# nmcli dev status
DEVICE      TYPE      STATE         CONNECTION
enp0s8      ethernet  connected     enp0s8
virbr0      bridge    connected     virbr0
enp0s3      ethernet  disconnected  --
enp0s9      ethernet  disconnected  --
lo          loopback  unmanaged     --
virbr0-nic  tun       unmanaged     --

 

 

팀 인터페이스 생성 (team01: 가상 인터페이스)

# type: team / team-slave

 1) team: 팀 인터페이스

 2) team-slave: 포트 인터페이스


# config: 러너 방식 (json 문법)

***작성 시 주의: 입력 시 오타에 대한 오류가 발생하지 않음

 

[root@team ~]# nmcli connection add type team con-name team01 ifname team01 config '{"runner": {"name": "activebackup"}}'
Connection 'team01' (7cbad7b0-7802-4fe1-b1d8-1c561d42059e) successfully added.

 

team01 가상 인터페이스는 생성되었으나 실제 IP 주소가 할당되지 않은 상태

 

 

생성한 팀 인터페이스에 IP 주소 정적 할당

[root@team ~]# nmcli con mod team01 ipv4.addresses 10.0.2.110/24
[root@team ~]# nmcli con mod team01 ipv4.gateway 10.0.2.1
[root@team ~]# nmcli con mod team01 ipv4.dns 8.8.8.8
[root@team ~]# nmcli con mod team01 ipv4.method manual
[root@team ~]# nmcli con up team01
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/14)

[root@team ~]# teamdctl team01 state
...
ipv4.method:                            manual
ipv4.dns:                               8.8.8.8
ipv4.dns-search:                        --
ipv4.dns-options:                       ""
ipv4.dns-priority:                      0
ipv4.addresses:                         10.0.2.110/24
ipv4.gateway:                           10.0.2.1
...

 

 

포트 인터페이스 생성 (team01-port1, team01-port2: 물리 인터페이스)

-> DHCP 서버에서 IP 주소를 할당받음

 

[root@team ~]# nmcli connection add type team-slave con-name team01-port1 ifname enp0s3 master team01
Connection 'team01-port1' (217bee6c-051c-4eaf-868a-04843ff07741) successfully added.

[root@team ~]# nmcli connection add type team-slave con-name team01-port2 ifname enp0s9 master team01
Connection 'team01-port2' (042b8ca2-9fbf-4506-8295-cd4751098371) successfully added.

 

팀/포트 인터페이스 활성화

*** 팀 인터페이스 활성화를 위해서는 반드시 포트 인터페이스 활성화 필요


[root@team ~]# nmcli con up team01-port1
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)

[root@team ~]# nmcli con up team01-port2
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/12)

[root@team ~]# nmcli con up team01
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)

 

 

참고: 설정한 러너 변경

1) nmcli con mod team01 team.config '{"runner .... 

2) 별도의 json 형태의 파일을 이용 가능

-> nmcli con mod team01 team.config FILE

/usr/share/doc/team-XXX/example_configs/ 에서 참고

nmcli con mod team01 team.config '{"runner": {"name": "roundrobin"}}'

 

728x90
728x90

이전 실습에 이어 구성

/etc/haproxy/haproxy.cfg 파일 수정

tcp 모드로 설정해야 http, mysql 동시 구성 가능

[root@haproxy ~]# vi /etc/haproxy/haproxy.cfg
      4         pidfile         /var/run/haproxy.pid
      5         maxconn         255
      6         user            haproxy
      7         group           haproxy
      8         daemon
      9
     10 defaults
     11         mode            tcp
     12         log             global
     13         timeout connect 30s
     14         timeout server  60s
     15         timeout client  60s
     16
     17 frontend        loadbalancer_db
     18         bind *:3306
     19         default_backend mariadb
     20
     21 backend mariadb
     22         balance roundrobin
     23         server  db01    10.0.2.10:3306  check
     24         server  db02    10.0.2.20:3306  check
     25
     26
     27 frontend        loadbalancer_web
     28         bind *:80
     29         default_backend web
     30
     31 backend web
     32         balance roundrobin
     33         server  web01    10.0.2.30:80  check
     34         server  web02    10.0.2.31:80  check

 

로드밸런서에서 작동 확인

 

 

* 주의

tcp 동작 모드로 할 경우 웹 서버의 로드밸런싱 속도가 느려짐

http 동작 모드로 변경하면 정상 속도로 돌아옴

728x90
728x90

L4 로드밸런서 구성


L4 로드밸런서로 MariaDB 로드밸런싱 구성

- HAProxy 에서 기본 방식은 http/https 로드밸런서 기능 (L7)
- 데이터베이스와 같은 서비스들도 로드밸런서가 필요할 수 있음
- L4 로드밸런서를 이용해서 부하분산 지원
- TCP/UDP 각 포트 번호에 따라 부하분산 설정 가능

 


 

DB 서버 구성


패키지 설치 및 기본 보안 설정

yum install -y mariadb-server

systemctl enable --now mariadb

mysql_secure_installation

 

사용자 및 테이블 구성

DB 1

# 사용자 권한 설정
MariaDB [(none)]> GRANT select,insert ON *.* TO remote@'%' identified by '123';
MariaDB [(none)]> flush privileges;

# 데이터베이스 설정
MariaDB [(none)]> CREATE database examdb;
MariaDB [(none)]> use examdb;
MariaDB [examdb]> CREATE table test_tab ( id int(2), name varchar(5) );
MariaDB [examdb]> INSERT INTO test_tab(id,name) VALUE(1,'KIM');
MariaDB [examdb]> SELECT * FROM test_tab;
+------+------+
| id   | name |
+------+------+
|    1 | KIM  |
+------+------+

 

DB 2

MariaDB [(none)]> GRANT select,insert ON *.* TO remote@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> CREATE database examdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> use examdb;
Database changed
MariaDB [examdb]> CREATE table test_tab (id int(2), name varchar(5));
Query OK, 0 rows affected (0.06 sec)

MariaDB [examdb]> INSERT INTO test_tab(id,name) VALUE(2,'DB2');
Query OK, 1 row affected (0.02 sec)

MariaDB [examdb]> select * from test_tab;
+------+------+
| id   | name |
+------+------+
|    2 | DB2  |
+------+------+
1 row in set (0.00 sec)

MariaDB [examdb]> exit

 

방화벽 설정

firewall-cmd --add-service=mysql
firewall-cmd --add-service=mysql --permanent

 

외부 서버에서 두 개의 DB 서버에 원격 접속이 되는지 확인

1. 방화벽 설정: mysql 명령어 사용을 위한 작업

yum install -y mariadb
 
firewall-cmd --add-service=mysql
firewall-cmd --add-service=mysql --permanent

firewall-cmd --list-services
dhcpv6-client http mysql ssh

 

2. DB 1에 접속

mysql -u remote -h 10.0.2.10 -p
MariaDB [(none)]> use examdb;
MariaDB [examdb]> select * from test_tab;
+------+------+
| id   | name |
+------+------+
|    1 | KIM  |
+------+------+
1 row in set (0.00 sec)

 

3. DB 2에 접속

mysql -u remote -h 10.0.2.20 -p

MariaDB [(none)]> use examdb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [examdb]> select * from test_tab;
+------+------+
| id   | name |
+------+------+
|    2 | DB2  |
+------+------+
1 row in set (0.00 sec)

 

 


로드밸런서 구성


설정 파일 생성

vi /etc/haproxy/haproxy.cfg

      1 global
      2         log             127.0.0.1 local2
      3         chroot          /var/lib/haproxy
      4         pidfile         /var/run/haproxy.pid
      5         maxconn         255
      6         user            haproxy
      7         group           haproxy
      8         daemon
      9
     10 defaults
     11         mode            tcp
     12         log             global
     13         timeout connect 30s
     14         timeout server  60s
     15         timeout client  60s
     16
     17 frontend        loadbalancer_db
     18         bind *:3306
     19         default_backend mariadb
     20
     21 backend mariadb
     22         balance roundrobin
     23         server  db01    10.0.2.10:3306  check
     24         server  db02    10.0.2.20:3306  check

 

부울 값 수정

semanage boolean -m  haproxy_connect_any --on
semanage boolean -l | grep haproxy_connect_any

 

 

서비스 재시작

systemctl restart haproxy

 

원격 접속하여 로드밸런싱 확인

1. 로드밸런서 서버에서 myql 방화벽 설정

yum install mariadb -y

firewall-cmd --add-service=mysql
firewall-cmd --add-service=mysql --permanent
firewall-cmd --list-services
dhcpv6-client http https mysql ssh

 

* 방화벽 설정이 되지 않았을 경우 아래와 같은 에러 발생

 

2. mysql -u remote -h 로드밸런서IP 주소 -p

mysql -u remote -h 10.0.2.50 -p
MariaDB [(none)]> use examdb;
No connection. Trying to reconnect...
Connection id:    12
Current database: *** NONE ***

Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [examdb]> select * from test_tab;
+------+------+
| id   | name |
+------+------+
|    2 | DB2  |
+------+------+

 

 

3. DB 1과 DB 2로 번갈아가며 접속됨

 

728x90
728x90

HAProxy 로그 기록 방식 정의


 

vi /etc/rsyslog.conf

      6 #### MODULES ####
      ....
     14 # Provides UDP syslog reception
     15 $ModLoad imudp
     16 $UDPServerRun 514
     17 $AllowedSender UDP, 127.0.0.1

...

     47 #### RULES ####
...
     55 *.info;mail.none;authpriv.none;cron.none;local2.none    /var/log/messages
     56
     57 #HAProxy log
     58 local2.*                                                /var/log/haproxy.log
     
     
systemctl restart rsyslog

ls /var/log
# haproxy.log 파일이 아직 생성되지 않음

systemctl restart haproxy

# haproxy.log 파일이 생성됨
ls /var/log
haproxy.log

 

728x90
728x90

인증서 생성 및 웹 서버 연동


- 기존에 웹 서버 구성 시 http 대신 https를 사용하듯이

- 보안을 위해서 추가 구성 진행

- 로드밸런서 자체에 인증서 적용 진행

 

구성 순서

1. 로드밸런서 구성

2. 인증서 준비 (통합 인증서=개인키+인증서)

3. 설정에서 인증서 등록

 


인증서 통합 생성


 

# 개인키와 인증서 통합 생성
openssl req -x509 -nodes -newkey rsa:2048 -keyout /etc/pki/tls/certs/haproxy.pem -out /etc/pki/tls/certs/haproxy.pem -days 365


# 정보 입력
Country Name (2 letter code) [XX]:KR
State or Province Name (full name) []:Seoul
Locality Name (eg, city) [Default City]:Seoul
Organization Name (eg, company) [Default Company Ltd]:goorm
Organizational Unit Name (eg, section) []:k8s
Common Name (eg, your name or your server's hostname) []:haproxy.goorm.com
Email Address []:root@goorm.com




# 접근 권한 변경: 나만 접근 가능하도록
chmod 600 /etc/pki/tls/certs/haproxy.pem
ls -l /etc/pki/tls/certs
total 4
-rw-------. 1 root root 1704 May 26 14:15 haproxy.pem

 


 

인증서 등록


vi /etc/haproxy/haproxy.cfg

      9 #---------------------------------------------------------------------
     10 # Global settings
     11 #---------------------------------------------------------------------
     12 global
		...
		...
     35     maxsslconn          40
     36     tune.ssl.default-dh-param 2048


     62 #---------------------------------------------------------------------
     63 # main frontend which proxys to the backends
     64 #---------------------------------------------------------------------
     65
     66 frontend loadbalancer
     67         ...
     68         bind *:443 ssl crt /etc/pki/tls/certs/haproxy.pem
     	...
        
        
systemctl restart haproxy

firewall-cmd --add-service=https
firewall-cmd --add-service=https --permanent

 

https://로드밸런서 IP 주소 접속

 

 

728x90
728x90

로드밸런서 상태 체크


- 브라우저/터미널을 통해 확인 가능

- 로드밸런서 자체의 상태 및 백엔드에 대한 정보 확인


브라우저로 확인


로드밸런서 상태 체크 설정

vi /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------

frontend loadbalancer
        bind *:80
        default_backend         web

        stats enable
        stats auth admin:123
        stats hide-version
        stats show-node
        stats refresh 60s
        stats uri /haproxy?stats

backend web
        balance         roundrobin
        server          web01 10.0.2.30:80 check
        server          web02 10.0.2.31:80 check

 

로드밸런서 주소/haproxy?stats 로 접속

사용자 이름: admin / 비밀번호: 123

 

 

 


터미널로 확인


 

yum install -y socat

vi /etc/haproxy/haproxy.conf
# 기본 설정 값
global
	stats socket /var/lib/haproxy/stats

systemctl restart haproxy
728x90
728x90

실습 환경


  LB WEB 1 WEB 2 NFS DB
IPv4 (enp0s8) 192.168.56.50 192.168.56.10 192.168.56.20 192.168.56.11 192.168.56.6
IPv4 (enp0s3) 10.0.2.50 10.0.2.30 10.0.2.31 10.0.2.40 10.0.2.10
HOSTNAME haproxy.goorm.com web01.goorm.com web02.goorm.com nfs.goorm.com master.goorm.com
DNS 8.8.8.8
GW 192.168.56.1
10.0.2.1
OS CentOS 7

 

 


아키텍처


 

 


구성 순서


 

1. 기본 웹서버 구성 (2대)
index.html 파일에 각 시스템의 호스트네임을 입력해두고 해당 시스템 접속 확인

2. haproxy 를 이용한 로드밸런서 구성
백앤드 서버를 1번에서 만든 웹서버 2대로 각각 지정
로드밸런서 서버로 접속해서 확인

3. NFS 연동 추가
1) 웹서버들의 /var/www/html 디렉토리를 NFS 서버에서 제공하도록 설정
2) 이 때, 구분을 위해 공유 디렉토리를 2개 설정해서 
각 시스템에 공유하기
ex) /content1 은 web01 에 공유
/content2 는 web02 에 공유

4. DB 연동
NFS 서버에서 제공하는 컨텐츠 파일을 php 파일로 작성해서
DB서버와 연동하기 ( php 파일은 기존 실습 참고 )

 

 


WEB 서버 구성


Apache


yum install -y httpd

systemctl enable --now httpd

firewall-cmd --add-service=http
firewall-cmd --add-service=http --permanent

echo "<h1>This Webserver hostname is $HOSTNAME</h1>" > /var/www/html/index.html

 

WEB1 주소로 접속: 192.168.56.10

 

WEB2 주소로 접속: 192.168.56.20

 

 


로드밸런서 구성


yum install -y haproxy

cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak

vi /etc/haproxy/haproxy.cfg

	 60 #---------------------------------------------------------------------
     61 # main frontend which proxys to the backends
     62 #---------------------------------------------------------------------
     63
     64 frontend lb
     65         bind *:80
     66         default_backend         web
     67         option                  forwardfor
     68
     69 backend web
     70         balance         roundrobin
     71         server          web01 10.0.2.30:80
     72         server          web02 10.0.2.31:80

systemctl enable --now haproxy
firewall-cmd --add-service=http

 

로드밸런서 주소로 접속: 192.168.56.50

 

 

 

 


NFS 서버 구성


NFS 서버

yum list nfs-utils

Installed Packages
nfs-utils.x86_64                                        1:1.3.0-0.68.el7.1                                         @updates
Available Packages
nfs-utils.x86_64                                        1:1.3.0-0.68.el7.2                                         updates


mkdir /content1 /content2

vi /etc/exports
/content1       10.0.2.30/32(rw,sync)
/content2       10.0.2.31/32(rw,sync)

exportfs -r
exportfs

/content1       10.0.2.30/32
/content2       10.0.2.31/32

echo "<h1>This is NFS Server with WEB1</h1>" > /content1/index.html
echo "<h1>This is NFS Server with WEB2</h1>" > /content2/index.html

systemctl enable --now nfs-server
firewall-cmd --add-service=nfs
firewall-cmd --add-service=nfs --permanent

vi /etc/sysconfig/nfs
14 RPCNFSDARGS="-V4.2"

 

WEB 클라이언트

ls -lZd /var/www/html/index.html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/index.html

# WEB1
vi /etc/fstab
10.0.2.40:/content1     /var/www/html   nfs     rw,sync,sec=sys,v4.2,context="unconfined_u:object_r:httpd_sys_content_t:s0"     0       0

# WEB2
10.0.2.40:/content2     /var/www/html   nfs     rw,sync,sec=sys,v4.2,context="unconfined_u:object_r:httpd_sys_content_t:s0"
     0       0
     
mount -a

 

WEB1 주소로 접속: 192.168.56.10

 

WEB2 주소로 접속: 192.168.56.20

 

로드밸런서 주소로 접속: 192.168.56.50

 

 


 

DB 서버 구성


패키지 설치 및 기본 보안 설정

yum install -y mariadb-server

systemctl enable --now mariadb

mysql_secure_installation

 

사용자 및 테이블 구성

 

# 사용자 권한 설정
MariaDB [(none)]> GRANT select,insert ON *.* TO remote@'%' identified by '123';
MariaDB [(none)]> flush privileges;

# 데이터베이스 설정
MariaDB [(none)]> CREATE database examdb;
MariaDB [(none)]> use examdb;
MariaDB [examdb]> CREATE table test_tab ( id int(2), name varchar(5) );
MariaDB [examdb]> INSERT INTO test_tab(id,name) VALUE(1,'KIM');
MariaDB [examdb]> SELECT * FROM test_tab;
+------+------+
| id   | name |
+------+------+
|    1 | KIM  |
+------+------+

 


 

PHP 구성


WEB 1


 

 

php 동작 확인, 부울 값 활성화

# php 패키지 설치 및 설정 파일 수정
yum install -y php php-pear php-mbstring php-fpm php-mysql

vi /etc/httpd/conf.d/php.conf
      4 <FilesMatch \.php$>
      5         SetHandler "proxy:fcgi://127.0.0.1:9000"
      
systemctl restart httpd php-fpm

# 부울 값 활성화
semanage boolean -l | grep httpd_can_network_connect_db
httpd_can_network_connect_db   (off  ,  off)  Allow httpd to can network connect db

semanage boolean -m httpd_can_network_connect_db --on

semanage boolean -l | grep httpd_can_network_connect_db
httpd_can_network_connect_db   (on   ,   on)  Allow httpd to can network connect db

NFS


 

 

/content1에서 작업

info.php 파일 생성

echo "<?php phpinfo(); ?>" > /content1/info.php

 

웹 브라우저에서 접속 확인

http://192.168.56.10/info.php

 

 

db.php 파일 생성

vi /content1/db.php

<?php
$conn = mysqli_connect('10.0.2.10','remote','123','examdb');

$sql = "SELECT * FROM test_tab";

$result = mysqli_query($conn,$sql);
  while($row = mysqli_fetch_array($result)){
    echo $row['id'].''.$row['name'].'<br>';
  }
?>

 

 

웹 브라우저에서 접속 확인

http://192.168.56.10/info.php

 

728x90
728x90

실습 개요

로드밸런서

- 작업 부하에 대한 부분을 분산해주는 역할

- 일반적으로 네트워크 트래픽에 대한 로드밸런싱 구성

- L4 로드밸런서와 L7 로드밸런서로 구분 가능

- 인증서 관리에 대한 편의 제공 (SSL/TLS 설정)

- proxy 서버를 통한 기능 구현 가능(nginx, pen, squid, haproxy 등)

 

구성 순서

1. 패키지 설치: haproxy

2. 서비스 설정: /etc/haproxy/haproxy.conf

3. 서비스 활성화: haproxy

4. 방화벽 설정: http(웹 서비스를 설정하는 시스템은 아니지만 실제 접속하는 사용자들이 80 포트로 요청하기 때문)

 

 


haproxy 구성

패키지 설치

yum install -y haproxy

 

서비스 설정

1. 원본 파일 수정 전 복사

ls /etc/haproxy/
haproxy.cfg

cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak

 

2. 설정 파일 수정

vi /etc/haproxy/haproxy.cfg


60 #-----------------------------------------------------------
61 # main frontend which proxys to the backends
62 #-----------------------------------------------------------
63
64 frontend lb
65         bind *:80
66         default_backend         web
67         option                  forwardfor
68
69 backend web
70         balance         roundrobin
71         server          web01 10.0.2.30:80 check

 

서비스 활성화

systemctl enable --now haproxy

 

방화벽 설정

firewall-cmd --add-service=http

 

 

728x90

+ Recent posts