프로필사진 글목록 방명록 이웃추가
Today:     Yesterday:     Total:

JunToday.com

Rocky Linux 9.4에 Galera Cluster MaxScale 사용. 본문

생활속의 IT 노하우/리눅스

Rocky Linux 9.4에 Galera Cluster MaxScale 사용.

JunToday 2024. 11. 21. 17:02
728x90

<테스트 구성환경>

서버 :

node1 - IP : 10.10.10.10

node2  - IP : 10.10.10.20

node3  - IP : 10.10.10.30

maxscale  - IP : 10.10.10.40

OS : Rocky Linux release 9.4 (Blue Onyx) 5.14.0-427.13.1.el9_4.x86_64

=======<< 모든서버공통세팅 >>=======

** selinux disabled 설정

(## selinux를 disabled 적용하려면 재부팅이 필요하므로 setenforce 0로 적용하자.)

** selinux config에서 selinux disabled 설정.
vi /etc/selinux/config
<수정전>
SELINUX=enforcing

<수정후>
SELINUX=disabled

------------------------------------------------------------------------

** selinux 상태 확인.
sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          disabled
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      33

------------------------------------------------------------------------

** selinux Current mode를 enforcing에서 permissive로 변경.
setenforce 0

------------------------------------------------------------------------

** selinux Current mode 변경 확인.
sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          disabled
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      33

** firewalld 실행상태 확인 및 포트 허용.

** firewalld 실행상태 확인.
firewall-cmd --state
running

------------------------------------------------------------------------

** MariaDB 포트(TCP 3306) 허용.
firewall-cmd --permanent --add-service=mysql
success

------------------------------------------------------------------------

** Galera Cluster 포트(TCP 4567, 4568, 4444), MaxScale 포트(4006) 허용.
firewall-cmd --permanent --add-port={4567,4568,4444,4006}/tcp
success

------------------------------------------------------------------------

** firewalld 정책 적용.
firewall-cmd --reload
success

------------------------------------------------------------------------

** firewalld 정책 확인.
firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens192
  sources:
  services: cockpit dhcpv6-client mysql ssh
  ports: 4567/tcp 4568/tcp 4444/tcp 4006/tcp
  protocols:
  forward: yes
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

** /etc/hosts에 각 서버 IP정보 추가.

vi /etc/hosts
10.10.10.10 node1
10.10.10.20 node2
10.10.10.30 node3
10.10.10.40 maxscale

** MariaDB repo_setup 실행.

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash

 

=======<< node1~3 서버 >>=======

** MariaDB-server, MariaDB-client 설치.

** 대소문자 유의하여 설치.(소문자로만 입력하면 설치가 안된다.)
dnf install MariaDB-server MariaDB-client

** 설치내역
설치되었습니다:
  MariaDB-client-11.5.2-1.el9.x86_64                        MariaDB-client-compat-11.5.2-1.el9.noarch
  MariaDB-common-11.5.2-1.el9.x86_64                        MariaDB-server-11.5.2-1.el9.x86_64
  MariaDB-server-compat-11.5.2-1.el9.noarch                 MariaDB-shared-11.5.2-1.el9.x86_64
  boost-program-options-1.75.0-8.el9.x86_64                 galera-4-26.4.19-1.el9.x86_64
  perl-File-Copy-2.34-481.el9.noarch                        perl-Sys-Hostname-1.23-481.el9.x86_64
  socat-1.7.4.1-5.el9_4.2.x86_64

완료되었습니다!

** MariaDB 서비스 enable.

systemctl enable mariadb.service

** libgalera_smm.so 파일 위치 확인.

find / -name libgalera_smm.so
find: ‘/run/user/1000/gvfs’: 허가 거부
/usr/lib64/galera-4/libgalera_smm.so

** Galera Cluster 구성을 위해 MariaDB 설정파일 수정.

vi /etc/my.cnf.d/server.cnf
<수정전>
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server

<수정후>
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
wsrep_cluster_name='test-galera'
wsrep_cluster_address='gcomm://node1 IP,node2 IP,node3 IP'
wsrep_node_address='이 서버의 IP'
wsrep_node_name='노드명'
wsrep_sst_method=rsync
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0

# this is only for embedded server

** 기준DB설정 및 MariaDB 실행.

** node1을 기준 DB로 설정하므로 node1에서 명령어 실행.(명령어를 실행하면 MariaDB가 함께 실행됨.)
galera_new_cluster

** 나머지 노드에서 MariaDB 실행.

** node2와 node3에서 MariaDB 실행 명령어.
systemctl start mariadb.service

** 각 노드의 MariaDB root 패스워드 변경.

mysqladmin -u root password
mysqladmin: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb-admin' instead
New password: 패스워드입력
Confirm new password: 패스워드재입력

** MariaDB root로 로그인하여 galera 연동 확인.

mysql -u root -p
mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead
Enter password: 패스워드입력

MariaDB [(none)]> show global status like 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| wsrep_cluster_size | 3     |
+--------------------+-------+
1 row in set (0.002 sec)
** 노드의 숫자가 맞는지 확인.

MariaDB [(none)]> show status like 'wsrep_%';
** wsrep_local_state_uuid가 각 노드가 같은지 확인.
** wsrep_incoming_addresses에 각 노드 IP주소가 있는지 확인.

** galera cluster 각 노드에 복제가 되는지 확인.
** 모든 노드가 read/write가 되는 상태이므로 아무 노드에서 database 생성.
** node2에서 아래처럼 생성.
MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.007 sec)

** node1과 node3에서 database가 생성되었는지 확인.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
| testdb             |
+--------------------+
6 rows in set (0.003 sec)

** 이번엔 node1에서 node2에서 생성한 'testdb' drop.
MariaDB [(none)]> drop database testdb;
Query OK, 0 rows affected (0.012 sec)

** node2와 node3에서 'testdb'가 drop되었는지 확인.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.002 sec)

** maxscale 유저 생성 및 권한부여.

** 전체 노드가 read/write 상태이므로 아무 노드에 maxscale 유저를 생성해준다.
** node1에서 생성함.
mysql -u root -p
mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead
Enter password: 패스워드 입력

MariaDB [(none)]> CREATE USER 'maxscale'@'10.10.10.40' IDENTIFIED BY '패스워드 입력';
Query OK, 0 rows affected (0.011 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.user TO 'maxscale'@'10.10.10.40';
Query OK, 0 rows affected (0.013 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.db TO 'maxscale'@'10.10.10.40';
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.tables_priv TO 'maxscale'@'10.10.10.40';
Query OK, 0 rows affected (0.006 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.columns_priv TO 'maxscale'@'10.10.10.40';
Query OK, 0 rows affected (0.006 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.procs_priv TO 'maxscale'@'10.10.10.40';
Query OK, 0 rows affected (0.005 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.proxies_priv TO 'maxscale'@'10.10.10.40';
Query OK, 0 rows affected (0.006 sec)

MariaDB [(none)]> GRANT SELECT ON mysql.roles_mapping TO 'maxscale'@'10.10.10.40';
Query OK, 0 rows affected (0.069 sec)

MariaDB [(none)]> GRANT SHOW DATABASES ON *.* TO 'maxscale'@'10.10.10.40';
Query OK, 0 rows affected (0.006 sec)

 

=======<< maxscale 서버 >>=======

** maxscale 설치.

dnf install maxscale

** 설치내역
설치되었습니다:
  libmicrohttpd-1:0.9.72-5.el9.x86_64                    librdkafka-1.6.1-102.el9.x86_64
  maxscale-24.02.3-1.rhel.9.x86_64                       nodejs-1:16.20.2-8.el9_4.x86_64
  nodejs-docs-1:16.20.2-8.el9_4.noarch                   nodejs-full-i18n-1:16.20.2-8.el9_4.x86_64
  nodejs-libs-1:16.20.2-8.el9_4.x86_64                   npm-1:8.19.4-1.16.20.2.8.el9_4.x86_64
  unixODBC-2.3.9-4.el9.x86_64

완료되었습니다!

** maxscale.cnf 수정.

vi /etc/maxscale.cnf
<수정전>
[maxscale]
threads=auto

[server1]
type=server
address=127.0.0.1
port=3306

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1
user=monitor_user
password=monitor_pw
monitor_interval=2s

[Read-Only-Service]
type=service
router=readconnroute
servers=server1
user=service_user
password=service_pw
router_options=slave

[Read-Write-Service]
type=service
router=readwritesplit
servers=server1
user=service_user
password=service_pw

[Read-Only-Listener]
type=listener
service=Read-Only-Service
protocol=mariadbprotocol
port=4008

[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=mariadbprotocol
port=4006

<수정후>
[maxscale]
threads=auto
admin_host=0.0.0.0
admin_secure_gui=false

[server1]
type=server
address=10.10.10.10
port=3306
protocol=MariaDBBackend

[server2]
type=server
address=10.10.10.20
port=3306
protocol=MariaDBBackend

[server3]
type=server
address=10.10.10.30
port=3306
protocol=MariaDBBackend

#[MariaDB-Monitor]
[Galera-Monitor]
type=monitor
module=galeramon
servers=server1,server2,server3
user=maxscale
password=maxscale패스워드
monitor_interval=2000ms

#[Read-Only-Service]
#type=service
#router=readconnroute
#servers=server1
#user=service_user
#password=service_pw
#router_options=slave

#[Read-Write-Service]
[Splitter-Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=maxscale
password=maxscale패스워드

#[Read-Only-Listener]
#type=listener
#service=Read-Only-Service
#protocol=mariadbprotocol
#port=4008

#[Read-Write-Listener]
[Splitter-Listener]
type=listener
service=Splitter-Service
protocol=MariaDBClient
port=3306

** maxscale 서비스 상태 확인 및 서비스 실행.

systemctl status maxscale
○ maxscale.service - MariaDB MaxScale Database Proxy
     Loaded: loaded (/usr/lib/systemd/system/maxscale.service; enabled; preset: disabled)
     Active: inactive (dead)

11월 19 15:21:45 maxscale systemd[1]: /usr/lib/systemd/system/maxscale.service:20: PIDFile= references a path below >
11월 19 15:21:45 maxscale systemd[1]: /usr/lib/systemd/system/maxscale.service:20: PIDFile= references a path below >

systemctl start maxscale

** maxscale과 cluster 확인.

maxctrl list servers
┌─────────┬───────────────┬──────┬─────────────┬─────────────────────────┬──────┬────────────────┐
│ Server  │ Address       │ Port │ Connections │ State                   │ GTID │ Monitor        │
├─────────┼───────────────┼──────┼─────────────┼─────────────────────────┼──────┼────────────────┤
│ server1 │ 10.10.10.10   │ 3306 │ 0           │ Slave, Synced, Running  │      │ Galera-Monitor │
├─────────┼───────────────┼──────┼─────────────┼─────────────────────────┼──────┼────────────────┤
│ server2 │ 10.10.10.20   │ 3306 │ 0           │ Slave, Synced, Running  │      │ Galera-Monitor │
├─────────┼───────────────┼──────┼─────────────┼─────────────────────────┼──────┼────────────────┤
│ server3 │ 10.10.10.30   │ 3306 │ 0           │ Master, Synced, Running │      │ Galera-Monitor │
└─────────┴───────────────┴──────┴─────────────┴─────────────────────────┴──────┴────────────────┘

maxctrl list services
┌──────────────────┬────────────────┬─────────────┬───────────────────┬───────────────────────────┐
│ Service          │ Router         │ Connections │ Total Connections │ Targets                   │
├──────────────────┼────────────────┼─────────────┼───────────────────┼───────────────────────────┤
│ Splitter-Service │ readwritesplit │ 0           │ 0                 │ server1, server2, server3 │
└──────────────────┴────────────────┴─────────────┴───────────────────┴───────────────────────────┘

maxctrl show server server1
┌─────────────────────┬──────────────────────────────────────────────┐
│ Server              │ server1                                      │
├─────────────────────┼──────────────────────────────────────────────┤
│ Source              │ /etc/maxscale.cnf                            │
├─────────────────────┼──────────────────────────────────────────────┤
│ Address             │ 10.10.10.10                                  │
├─────────────────────┼──────────────────────────────────────────────┤
│ Port                │ 3306                                         │
├─────────────────────┼──────────────────────────────────────────────┤
│ State               │ Slave, Synced, Running                       │
├─────────────────────┼──────────────────────────────────────────────┤
│ Version             │ 11.5.2-MariaDB                               │
├─────────────────────┼──────────────────────────────────────────────┤
│ Uptime              │ 6523                                         │
├─────────────────────┼──────────────────────────────────────────────┤
│ Last Event          │ slave_up                                     │
├─────────────────────┼──────────────────────────────────────────────┤
│ Triggered At        │ Tue, 19 Nov 2024 07:33:44 GMT                │
├─────────────────────┼──────────────────────────────────────────────┤
│ Services            │ Splitter-Service                             │
├─────────────────────┼──────────────────────────────────────────────┤
│ Monitors            │ Galera-Monitor                               │
├─────────────────────┼──────────────────────────────────────────────┤
│ Master ID           │ 0                                            │
├─────────────────────┼──────────────────────────────────────────────┤
│ Node ID             │ 2                                            │
├─────────────────────┼──────────────────────────────────────────────┤
│ Slave Server IDs    │                                              │
├─────────────────────┼──────────────────────────────────────────────┤
│ Current Connections │ 0                                            │
├─────────────────────┼──────────────────────────────────────────────┤
│ Total Connections   │ 0                                            │
├─────────────────────┼──────────────────────────────────────────────┤
│ Max Connections     │ 0                                            │
├─────────────────────┼──────────────────────────────────────────────┤
│ Statistics          │ {                                            │
│                     │     "active_operations": 0,                  │
│                     │     "adaptive_avg_select_time": "0ns",       │
│                     │     "connection_pool_empty": 0,              │
│                     │     "connections": 0,                        │
│                     │     "failed_auths": 0,                       │
│                     │     "max_connections": 0,                    │
│                     │     "max_pool_size": 0,                      │
│                     │     "persistent_connections": 0,             │
│                     │     "response_time_distribution": {          │
│                     │         "read": {                            │
│                     │             "distribution": [                │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.000001",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.000010",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.000100",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.001000",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.010000",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.100000",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "1.000000",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "10.000000",     │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "100.000000",    │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "1000.000000",   │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "10000.000000",  │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "100000.000000", │
│                     │                     "total": 0               │
│                     │                 }                            │
│                     │             ],                               │
│                     │             "operation": "read",             │
│                     │             "range_base": 10                 │
│                     │         },                                   │
│                     │         "write": {                           │
│                     │             "distribution": [                │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.000001",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.000010",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.000100",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.001000",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.010000",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "0.100000",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "1.000000",      │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "10.000000",     │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "100.000000",    │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "1000.000000",   │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "10000.000000",  │
│                     │                     "total": 0               │
│                     │                 },                           │
│                     │                 {                            │
│                     │                     "count": 0,              │
│                     │                     "time": "100000.000000", │
│                     │                     "total": 0               │
│                     │                 }                            │
│                     │             ],                               │
│                     │             "operation": "write",            │
│                     │             "range_base": 10                 │
│                     │         }                                    │
│                     │     },                                       │
│                     │     "reused_connections": 0,                 │
│                     │     "routed_packets": 0,                     │
│                     │     "total_connections": 0                   │
│                     │ }                                            │
├─────────────────────┼──────────────────────────────────────────────┤
│ Parameters          │ {                                            │
│                     │     "address": "10.10.10.10",                │
│                     │     "disk_space_threshold": null,            │
│                     │     "extra_port": 0,                         │
│                     │     "max_routing_connections": 0,            │
│                     │     "monitorpw": null,                       │
│                     │     "monitoruser": null,                     │
│                     │     "persistmaxtime": "0ms",                 │
│                     │     "persistpoolmax": 0,                     │
│                     │     "port": 3306,                            │
│                     │     "priority": 0,                           │
│                     │     "private_address": null,                 │
│                     │     "proxy_protocol": false,                 │
│                     │     "rank": "primary",                       │
│                     │     "replication_custom_options": null,      │
│                     │     "socket": null,                          │
│                     │     "ssl": false,                            │
│                     │     "ssl_ca": null,                          │
│                     │     "ssl_cert": null,                        │
│                     │     "ssl_cert_verify_depth": 9,              │
│                     │     "ssl_cipher": null,                      │
│                     │     "ssl_key": null,                         │
│                     │     "ssl_verify_peer_certificate": false,    │
│                     │     "ssl_verify_peer_host": false,           │
│                     │     "ssl_version": "MAX"                     │
│                     │ }                                            │
└─────────────────────┴──────────────────────────────────────────────┘

** MaxGUI는 "http://10.10.10.40:8989"로 접속.

** MaxGUI 기본 로그인은 사용자명 "admin", 패스워드 "mariadb"이다.

** 만일 MaxGUI에서 admin 계정의 패스워드를 변경한 후 "maxctrl" 명령어 실행 시 다음과 같은 에러가 발생하는 경우.

maxctrl list servers
Error: Server at http://127.0.0.1:8989 responded with 401 Unauthorized to `GET servers`
{
    "errors": [
        {
            "detail": "Access denied"
        }
    ]
}

** MaxGUI에서 변경한 admin 정보를 명령어에 포함해야 한다.

maxctrl --user='admin' --password='변경한 패스워드' list servers
728x90
Comments