Thứ Ba, 21 tháng 2, 2023

Cài đặt MySQL theo mô hình Active-Standby

MASTER192.168.29.137

BACKUP192.168.29.159

--VIP: 192.168.1.44 (virtual IP)

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

B1: stop mysql

            --systemctl status mysqld

            systemctl stop mysqld

            --systemctl start mysqld

           

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

B2: Gỡ gói và xóa toàn bộ data cũ    

yum remove galera* mysql* rsync lsof policycoreutils-python -y

rm -rf /etc/mysql

rm -rf /var/lib/mysql

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

B3: cài lại các gói

yum -y install galera-4 mysql-wsrep-8.0 rsync lsof policycoreutils-python

 

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

B4: cấu hình /etc/my.cnf

--NODE1: 192.168.29.137

[mysqld]

server-id = 1                                                        #trên MASTER

log-bin=mysql-bin

binlog-ignore-db =  mysql,information_schema #Ignore the library that writes the binglog log

auto-increment-increment = 2                                        #Field change increment value

auto-increment-offset = 1                                        #Initial field ID is 1

slave-skip-errors = all #Ignore all copy errors

           

--NODE2: 192.168.29.159

[mysqld]

server-id = 2

log-bin=mysql-bin

binlog-ignore-db =  mysql,information_schema #Các DB cần chuyển giữa 2 node

auto-increment-increment = 2                                        #Field change increment value

auto-increment-offset = 1                                        #Initial field ID is 1

slave-skip-errors = all #Ignore all copy errors

           

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

B5: restart lại mysql   

service mysqld restart

           

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

B6: tìm pass root tạm thời của mysql

           grep 'temporary password' /var/log/mysqld.log -- tìm pass root tạm thời của mysql

 

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

B7: vào mysql đổi pass mới

            ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin$123';

            FLUSH PRIVILEGES;

           

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

B8: Tạo user để cả 2 NODE đồng bộ (trên cả 2 NODE đều tạo)

create user 'binhtv'@'%' identified by 'Admin$321';

GRANT ALL PRIVILEGES ON *.* TO 'binhtv'@'%';

grant replication slave on *.* to 'binhtv'@'%';

FLUSH PRIVILEGES;

           

B9: cấu hình đồng bộ

            MASTER: 192.168.29.137

  show master status; --vào user binhtv show

 

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

            NODE BACKUP : 192.168.29.159

           

            --VÀO USER BINHTV

         stop slave;

         CHANGE MASTER TO MASTER_HOST = '192.168.29.137', MASTER_USER = 'binhtv', MASTER_PASSWORD = 'Admin$321', MASTER_LOG_FILE = 'mysql-bin.000002', MASTER_LOG_POS = 1771;

         start slave;

            --NOTE: MASTER_LOG_FILE = 'mysql-bin.000002', MASTER_LOG_POS = 1771 lấy ở show trên node MASTER(FILE và position)

           

           

        SHOW MASTER STATUS;        --user binhtv show

          

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

            MASTER : 192.168.29.137

         stop slave;

         CHANGE MASTER TO MASTER_HOST = '192.168.29.159', MASTER_USER = 'binhtv', MASTER_PASSWORD = 'Admin$321', MASTER_LOG_FILE = 'mysql-bin.000002', MASTER_LOG_POS = 1770;

         start slave;

            --NOTE: MASTER_LOG_FILE = 'mysql-bin.000002', MASTER_LOG_POS = 1770 lấy ở show trên node BACKUP(FILE và position) 

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

           show slave status\G    -- trên cả 2node (trong DB)


B10: Test đồng bộ trên 2 node

            create database example;

            create table example.dummy (`id` varchar(10));

            create database example1;

            create table example1.dummy (`id` varchar(10));           

Tham khảo

https://www.programmerall.com/article/3044766357/

https://www.digitalocean.com/community/tutorials/how-to-set-up-mysql-master-master-replication

=============================
* KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE trực tiếp từ tôi giúp bạn bước đầu trở thành những chuyên gia DBA, đủ kinh nghiệm đi thi chứng chỉ OA/OCP, đặc biệt là rất nhiều kinh nghiệm, bí kíp thực chiến trên các hệ thống Core tại VN chỉ sau 1 khoá học.
* CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
* Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile/Zalo: 0902912888
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: http://bit.ly/ytb_binhoraclemaster
👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhoracle
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
oracle tutorial, học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,sql tutorial, khóa học pl/sql tutorial, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail,oracle RAC, ASM, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, postgresql tutorial, mysql tutorial, mariadb tutorial, sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master