프로덕션 환경의 mysql 호스트에는 단일 장애 지점이 있으므로 mysql의 고가용성을 보장해야 합니다. 즉, 두 MySQL 서버 중 하나가 중단되면 다른 서버가 즉시 대신할 수 있습니다. 그 일.
마스터-슬레이브 복제의 원리
마스터는 각 트랜잭션이 데이터를 업데이트하기 전에 이러한 변경 사항을 보조 로그에 기록합니다. 스토리지 엔진은 MySQL 트랜잭션 커밋을 위한 바이너리 로그가 완료된 후 마스터 서버로부터 알림을 받습니다. 다음으로 슬레이브는 마스터의 바이너리 로그를 자신의 릴레이 로그에 복사해야 합니다. 먼저 슬레이브는 작업 스레드(I/O 스레드)를 시작합니다. I/O 스레드는 마스터에서 일반 연결을 연 다음 binlog 덤프 프로세스를 시작합니다. Binlog 덤프 프로세스는 마스터의 바이너리 로그에서 이벤트를 읽습니다. 마스터가 동기화된 경우 마스터가 새 이벤트를 생성할 때까지 기다립니다. 이러한 이벤트는 릴레이 로그에 기록됩니다. 이 프로세스의 마지막 단계는 SQL 슬레이브 스레드에 의해 처리됩니다. SQL 스레드는 릴레이 로그의 이벤트를 읽고 이러한 이벤트를 재현하여 슬레이브 데이터베이스의 데이터를 업데이트하여 마스터 데이터베이스의 데이터와의 일관성을 유지합니다. 릴레이 로그는 일반적으로 운영 체제의 캐시에 저장되므로 스레드가 I/O 스레드와 일치하는 한 릴레이 로그에는 오버헤드가 거의 없습니다.
환경 준비: 두 개의 MySQL 서버를 열고 네트워크 환경을 배포합니다.
마스터 배포
1. 호스트에 SSL/RSA 파일을 생성합니다
[root@master ~]# cd /usr/local/mysql/bin/ [root@master bin]# mysql_ssl_rsa_setup --user=mysql --basedir=/usr/llocal/mysql --datadir=/usr/local/mysql/data
2.
[root@master bin]# chmod +r /usr/local/mysql/data/server-key.pem [root@master bin]# service mysqld restart Shutting down MySQL.. [ 确定 ] Starting MySQL. [ 确定 ]
3. mysql에 로그인하여 SSL이 활성화되어 있는지 확인하고 복사 사용자를 생성합니다.
참고: mysql을 활성화하여 SSL 보안 연결을 지원합니다. 이는 주로 mysql 마스터-슬레이브 복제에 사용됩니다(근거리 통신망은 SSH가 아닌 연결이나 일반 텍스트 복제를 사용할 수 있지만 인터넷에는 SSL 연결을 사용하는 것이 좋습니다). 복제)
mysql> grant replication slave on *.* to rep@'192.168.8.3' identified by '123'; Query OK, 0 rows affected, 1 warning (0.07 sec)
4. 마스터가 바이너리 로그를 켜고, 다시 시작한 후 바이너리 로그 파일을 봅니다.
server_id는 고유해야 합니다.
[root@master ~]# vim /etc/my.cnf #添加下面内容 log-bin=mysql-bin service_id=1 [root@master ~]# service mysqld restart Shutting down MySQL.. [ 确定 ] Starting MySQL. [ 确定 ] [root@master ~]# mysql -uroot -p123 -e "show master status" mysql: [Warning] Using a password on the command line interface can be insecure. +------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+------------------+-------------------+ | mysql-bin.000001 | 154 | | | | +------------------+----------+--------------+------------------+-------------------+
5. 방화벽 구성, 실험 환경에서는 방화벽을 끌 수 있으며, 프로덕션 환경에서는 포트 3306을 허용하도록 방화벽 규칙을 구성해야 합니다.
[root@master ~]# firewall-cmd --permanent --add-port=3306/tcp success [root@master ~]# firewall-cmd --reload success
6. SSL 파일을 슬레이브에 복사
[root@master data]# scp ca.pem client-cert.pem client-key.pem root@192.168.8.3:/usr/local/mysql/data The authenticity of host '192.168.8.3 (192.168.8.3)' can't be established. ECDSA key fingerprint is SHA256:LFby9KMDz/kkPfOESbeJ7Qh+3hmQaX2W5gkDDMwSGHA. ECDSA key fingerprint is MD5:03:32:64:b4:c2:5b:6c:a4:e2:f0:7f:df:7a:35:19:80. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.8.3' (ECDSA) to the list of known hosts. root@192.168.8.3's password: ca.pem 100% 1112 232.5KB/s 00:00 client-cert.pem 100% 1112 240.4KB/s 00:00 client-key.pem 100% 1676 205.0KB/s 00:00
슬레이브를 배포합니다
1. SSL을 활성화하고 로그를 릴레이하고 SSL 파일에 읽기 권한을 부여한 후 mysql을 다시 시작합니다.
[root@slave ~]# vim /etc/my.cnf #添加下面内容 server_id=2 relay-log=relay-log ssl_ca=ca.pem ssl_cert=client-cert.pem ssl_key=client-key.pem [root@slave ~]# cd /usr/local/mysql/data [root@slave data]# ll ca.pem client-cert.pem client-key.pem -rw-r--r--. 1 mysql mysql 1112 3月 31 14:31 ca.pem -rw-r--r--. 1 mysql mysql 1112 3月 31 14:31 client-cert.pem -rw-------. 1 mysql mysql 1676 3月 31 14:31 client-key.pem [root@slave data]# chmod +r client-key.pem [root@slave ~]# service mysqld restart Shutting down MySQL.. [ 确定 ] Starting MySQL. [ 确定 ]
2. SSL이 성공적으로 켜져 있는지 확인하세요
[root@slave ~]# mysql -uroot -p123 -e "show variables like '%ssl%'" mysql: [Warning] Using a password on the command line interface can be insecure. +-------------------------------------+-----------------+ | Variable_name | Value | +-------------------------------------+-----------------+ | have_openssl | YES | | have_ssl | YES | | performance_schema_show_processlist | OFF | | ssl_ca | ca.pem | | ssl_capath | | | ssl_cert | client-cert.pem | | ssl_cipher | | | ssl_crl | | | ssl_crlpath | | | ssl_key | client-key.pem | +-------------------------------------+-----------------+
3. 마스터-슬레이브 복제를 구성하기 전에 SSL을 사용하여 슬레이브 mysql의 마스터 서버에 연결할 수 있습니다. + 사용 중인 SSL 프로토콜 Cipher는 ECDHE-RSA- 임을 알 수 있습니다. AES128-GCM-SHA256 슬레이브의 mysql 서비스에 로그인합니다.
[root@slave ~]# cd /usr/local/mysql/data [root@slave data]# mysql --ssl-ca=ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem -u rep -p123 -h 192.168.8.2 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.40-log MySQL Community Server (GPL) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> \s -------------- mysql Ver 14.14 Distrib 5.7.40, for linux-glibc2.12 (x86_64) using EditLine wrapper Connection id: 3 Current database: Current user: rep@192.168.8.3 SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256 Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.40-log MySQL Community Server (GPL) Protocol version: 10 Connection: 192.168.8.2 via TCP/IP Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3306 Uptime: 22 min 19 sec Threads: 1 Questions: 8 Slow queries: 0 Opens: 109 Flush tables: 1 Open tables: 102 Queries per second avg: 0.005 --------------
활성화 성공을 확인하세요.
SSL 마스터-슬레이브 복제 테스트1. 마스터에 로그인하고 데이터를 작성합니다mysql> exit Bye [root@slave data]# mysql -uroot -p123 #省略部分登录信息 mysql> change master to -> master_host='192.168.8.2', #masterIP -> master_user='rep', #master用户 -> master_password='123', #master密码 -> master_log_file='mysql-bin.000001', #master二进制日志文件 -> master_log_pos=154, #master位置 -> master_ssl=1, #masterssl -> master_ssl_cert='client-cert.pem', -> master_ssl_key='client-key.pem', -> master_ssl_ca='ca.pem'; Query OK, 0 rows affected, 2 warnings (0.07 sec) mysql> start slave; #启用从 Query OK, 0 rows affected (0.02 sec)

[root@master ~]# mysql -uroot -p123 #省略部分内容 mysql> create database bbs; Query OK, 1 row affected (0.01 sec) mysql> use bbs; Database changed mysql> create table tb1(id int, -> name varchar(20)); Query OK, 0 rows affected (0.02 sec) mysql> insert into tb1 values(1,'z3'); Query OK, 1 row affected (0.02 sec)
마지막으로 마스터인 z3를 볼 수 있습니다. 노예는 성공했습니다.
위 내용은 SSL 보안 연결을 기반으로 MySQL 마스터-슬레이브 복제를 구현하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于架构原理的相关内容,MySQL Server架构自顶向下大致可以分网络连接层、服务层、存储引擎层和系统文件层,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql的msi与zip版本的区别:1、zip包含的安装程序是一种主动安装,而msi包含的是被installer所用的安装文件以提交请求的方式安装;2、zip是一种数据压缩和文档存储的文件格式,msi是微软格式的安装包。

方法:1、利用right函数,语法为“update 表名 set 指定字段 = right(指定字段, length(指定字段)-1)...”;2、利用substring函数,语法为“select substring(指定字段,2)..”。

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

SublimeText3 영어 버전
권장 사항: Win 버전, 코드 프롬프트 지원!

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전
