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
'쿠버네티스 교육 > 프로젝트' 카테고리의 다른 글
220527_1_세미 프로젝트_웹 서비스 구축_네트워크 티밍 (0) | 2022.05.27 |
---|---|
220526_5_세미 프로젝트_웹 서비스 구축_L4, L7 로드밸런서 구성 (0) | 2022.05.26 |
220526_3_세미 프로젝트_웹 서비스 구축_HAProxy 로그 기록 방식 정의 (0) | 2022.05.26 |
220526_2_세미 프로젝트_웹 서비스 구축_로드밸런서 SSL 인증서 적용 (0) | 2022.05.26 |
220526_1_세미 프로젝트_웹 서비스 구축_로드밸런서 상태 체크 (0) | 2022.05.26 |