메뉴 닫기

mariadb 이중화

mariadb 이중화 진행하기 

– 호스트 설정
sudo vim /etc/hosts
127.0.0.1 localhost
10.101.0.17 node1
10.101.0.7 node2
10.101.0.9 node3

-방화벽 설정 

iptables -I INPUT -s 115.68.0.0/16 -j ACCEPT

– mariadb 설치 진행 

sudo apt update
sudo apt -y install mariadb-server mariadb-client

– mysql 설정 진행 

sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
… Success!

Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
… Success!

By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
… Success!

Cleaning up…

All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

– 이중화 설정

vi /etc/mysql/mariadb.cnf

– node1 설정 추가
[galera]
wsrep_on = ON
wsrep_cluster_name = “MariaDB Galera Cluster”
wsrep_provider = /usr/lib/galera/libgalera_smm.so
wsrep_cluster_address = “gcomm://node1, node2, node3 ip
binlog_format = row
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
bind-address = 0.0.0.0
wsrep_node_address=”10.101.x.x”
wsrep_node_name=”node1
wsrep_sst_auth=root:”passwd

– node2 설정 추가

[galera]
wsrep_on = ON
wsrep_cluster_name = “MariaDB Galera Cluster”
wsrep_provider = /usr/lib/galera/libgalera_smm.so
wsrep_cluster_address = “gcomm://node1, node2, node3 ip
binlog_format = row
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
bind-address = 0.0.0.0
wsrep_node_address=”10.101.x.x”
wsrep_node_name=”node2
wsrep_sst_auth=root:”passwd

-node3 설정 추가

[galera]
wsrep_on = ON
wsrep_cluster_name = “MariaDB Galera Cluster”
wsrep_provider = /usr/lib/galera/libgalera_smm.so
wsrep_cluster_address = “gcomm://node1, node2, node3 ip
binlog_format = row
default_storage_engine = InnoDB
innodb_autoinc_lock_mode = 2
bind-address = 0.0.0.0
wsrep_node_address=”10.101.x.x”
wsrep_node_name=”node3
wsrep_sst_auth=root:”passwd

– 설정 완료 후 node1 진행

sudo galera_new_cluster
sudo systemctl restart mariadb

-node2 node3 데몬 실행
sudo systemctl restart mariadb

– error 발생시 

1.
2022-01-05 15:33:03 0 [ERROR] WSREP: gcs/src/gcs_core.cpp:gcs_core_open():208: Failed to open backend connection: -110 (Connection timed out)
2022-01-05 15:33:03 0 [ERROR] WSREP: gcs/src/gcs.cpp:gcs_open():1457: Failed to open channel ‘MariaDB Galera Cluster’ at ‘gcomm://10.101.0.17,10.101.0.7’: -110 (Connection timed out)
2022-01-05 15:33:03 0 [ERROR] WSREP: gcs connect failed: Connection timed out
2022-01-05 15:33:03 0 [ERROR] WSREP: wsrep::connect(gcomm://10.101.0.17,10.101.0.7) failed: 7
2022-01-05 15:33:03 0 [ERROR] Aborting

-> sudo galera_new_cluster 명령어 작성 후 리스타트

2.
Apr 24 16:12:40 ubuntu1 mysqld[8844]: 2017-04-24 16:12:40 140660766763264 [ERROR] WSREP: It may not be safe to bootstrap the cluster from this node. It was not the last one to leave th
Apr 24 16:12:40 ubuntu1 mysqld[8844]: 2017-04-24 16:12:40 140660766763264 [ERROR] WSREP: wsrep::connect(gcomm://) failed: 7
Apr 24 16:12:40 ubuntu1 mysqld[8844]: 2017-04-24 16:12:40 140660766763264 [ERROR] Aborting

-> sudo rm -rf galera.cache grastate.dat wsrep_sst_binlog.tar

– 이중화 확인 

MariaDB [(none)]> SHOW STATUS LIKE ‘wsrep%’;
+——————————-+————————————————+
| Variable_name | Value |
+——————————-+————————————————+
| wsrep_applier_thread_count | 1 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 0.000000 |
| wsrep_causal_reads | 0 |
| wsrep_cert_deps_distance | 0.000000 |
| wsrep_cert_index_size | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_cluster_conf_id | 3 |
| wsrep_cluster_size | 3 |
| wsrep_cluster_state_uuid | 86679ccd-6df4-11ec-a35d-af12742a039d |
| wsrep_cluster_status | Primary |
| wsrep_cluster_weight | 2 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 0.000000 |
| wsrep_connected | ON |
| wsrep_desync_count | 0 |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0.000806387/0.00172045/0.00488128/0.00158473/5 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_sent | 0 |
| wsrep_gcomm_uuid | d9974063-6df4-11ec-94cb-c2d5b2b5d910 |
| wsrep_incoming_addresses | 10.101.0.17:3306,10.101.0.9:3306 |
| wsrep_last_committed | 0 |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_cached_downto | 18446744073709551615 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_commits | 0 |
| wsrep_local_index | 1 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_avg | 0.000000 |
| wsrep_local_recv_queue_max | 1 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_send_queue_max | 1 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_local_state_uuid | 86679ccd-6df4-11ec-a35d-af12742a039d |
| wsrep_open_connections | 0 |
| wsrep_open_transactions | 0 |
| wsrep_protocol_version | 9 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 3.29(ra60e019) |
| wsrep_ready | ON |
| wsrep_received | 3 |
| wsrep_received_bytes | 215 |
| wsrep_repl_data_bytes | 0 |
| wsrep_repl_keys | 0 |
| wsrep_repl_keys_bytes | 0 |
| wsrep_repl_other_bytes | 0 |
| wsrep_replicated | 0 |
| wsrep_replicated_bytes | 0 |
| wsrep_rollbacker_thread_count | 1 |
| wsrep_thread_count | 2 |
+——————————-+————————————————+

– 이중화 확인 test 진행

root@node1:~# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.5.9-MariaDB-1:10.5.9+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> create database test1;
Query OK, 1 row affected (0.003 sec)

root@node2:~# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 45
Server version: 10.5.9-MariaDB-1:10.5.9+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| test1 |
+——————–+
4 rows in set (0.001 sec)

root@node3:~# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 46
Server version: 10.5.9-MariaDB-1:10.5.9+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| performance_schema |
| test1 |
+——————–+
4 rows in set (0.001 sec)

 

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x