作者在2014Oracle数据库嘉年华中有幸听到了关于去哪网的MySQL数据库基于PXC的高可用架构设计主题。 MySQL和Oracle是完全不同的两种数据库,Oracle重于管理,而MySQL更重要的是架构设计。笔者对MySQL以及新技术也是充满了好奇,索性回来自己搭建一个测试环境
作者在2014Oracle数据库嘉年华中有幸听到了关于去哪网的MySQL数据库基于PXC的高可用架构设计主题。
MySQL和Oracle是完全不同的两种数据库,Oracle重于管理,而MySQL更重要的是架构设计。笔者对MySQL以及新技术也是充满了好奇,索性回来自己搭建一个测试环境。
操作系统:CentOS 6.6
软件版本:5.5.39-36.0-55 PerconaXtraDB Cluster (GPL)
节点信息:
pxc1 | 192.168.0.200 |
pxc2 | 192.168.0.201 |
pxc3 | 192.168.0.202 |
安装过程
安装PXC,这里使用的是Percona以及EPEL的官方repositories :
http://www.percona.com/doc/percona-server/5.5/installation/yum_repo.html?id=repositories:yum
http://fedoraproject.org/wiki/EPEL
yum installhttp://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm yum installhttp://mirrors.ustc.edu.cn/fedora/epel/6/i386/epel-release-6-8.noarch.rpm yum -y install Percona-XtraDB-Cluster-serverPercona-XtraDB-Cluster-client Percona-Server-shared-compat percona-xtrabackup
每台机器开启PXC,之后添加SST账户:
DELETE FROM mysql.user WHERE user=''; GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'localhost' IDENTIFIED BY 'sstuser';; FLUSH PRIVILEGES;
每个节点关闭PXC。编辑第一个节点的PXC设置。
[mysqld] server_id=1 wsrep_provider=/usr/lib64/libgalera_smm.so wsrep_cluster_address="gcomm://192.168.0.200,192.168.0.201,192.168.0.202" wsrep_sst_auth=sstuser:sstuser wsrep_provider_options="gcache.size=4G" wsrep_cluster_name=Percona wsrep_sst_method=xtrabackup wsrep_node_name=pxc1 wsrep_slave_threads=4 log_slave_updates innodb_locks_unsafe_for_binlog=1 innodb_autoinc_lock_mode=2
开启第一个节点(如果集群关闭,每次拥有正确信息的节点使用此命令开启集群)
[root@pxc1 ~]# service mysql bootstrap-pxc Bootstrapping PXC (Percona XtraDBCluster)Starting MySQL (Percona XtraDB Cluster)..[ OK ]
编辑另外两个节点的my.cnf配置文件需要修改的内容:
server_id=2 wsrep_node_name=pxc2
将其他两个节点加入到集群中
service mysql start
至此,集群安装结束。
遇到的问题
以下是配置过程中的报错信息以及解决方法:
现象:
开启PXC节点的时候遇到
Failed to read output of: 'ip addr show | grep -E '^[ ]*inet' | grep -m1global | awk '{ print $2 }' | sed -e 's/\/.*//'' ........ 141120 22:46:35 [ERROR] WSREP: Permission denied 141120 22:46:35 [ERROR] WSREP: failed to open gcomm backend connection: 13:error while trying to listen 'tcp://0.0.0.0:4567?socket.non_blocking=1', asioerror 'Permission denied': 13 (Permission denied)
原因:
由于开启了SELINUX。
解决方法:
编辑文件/etc/sysconfig/selinux
把SELINUX设为disabled
重启后就会忽略selinux,或者直接执行命令
setenforce 0
立即生效。
现象:
添加节点到集群中的时候遇到
last inactive check morethan PT1.5S ago (PT3.50529S), skipping check
卡在这里
原因:
iptables
解决方法:
关闭iptables
chkconfig iptables off
service iptables stop
简单测试
[root@pxc1 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.5.39-36.0-55 Percona XtraDB Cluster (GPL), Release rel36.0, Revision 824, WSREP version 25.11, wsrep_25.11.r4023 Copyright (c) 2009-2014 Percona LLC and/or its affiliates Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 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> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 2 | +--------------------+-------+ 1 row in set (0.00 sec) mysql> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set (0.00 sec) mysql> create database dexdb ; Query OK, 1 row affected (0.01 sec) mysql> use dexdb Database changed mysql> create table dextb (id int ,name char(10)) engine=innodb ; Query OK, 0 rows affected (0.03 sec) mysql> insert into dextb values (1,'22') ; Query OK, 1 row affected (0.01 sec) mysql> insert into dextb values (1,'22') ; Query OK, 1 row affected (0.00 sec) mysql> commit ; Query OK, 0 rows affected (0.00 sec) mysql> select * from dextb ; +------+------+ | id | name | +------+------+ | 1 | 22 | | 1 | 22 | +------+------+ 2 rows in set (0.00 sec) [root@pxc2 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.5.39-36.0-55 Percona XtraDB Cluster (GPL), Release rel36.0, Revision 824, WSREP version 25.11, wsrep_25.11.r4023 Copyright (c) 2009-2014 Percona LLC and/or its affiliates Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 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> show database ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1 mysql> show databases ; +--------------------+ | Database | +--------------------+ | information_schema | | dexdb | | mysql | | performance_schema | | test | +--------------------+ 5 rows in set (0.01 sec) mysql> use dexdb 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 mysql> select * from dextb ; +------+------+ | id | name | +------+------+ | 1 | 22 | | 1 | 22 | +------+------+ 2 rows in set (0.00 sec) [root@pxc3 ~]# service mysql start MySQL (Percona XtraDB Cluster) is not running, but lock file (/var/lock/subsys/mysql) exists[FAILED] Starting MySQL (Percona XtraDB Cluster).....[ OK ] [root@pxc3 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.5.39-36.0-55 Percona XtraDB Cluster (GPL), Release rel36.0, Revision 824, WSREP version 25.11, wsrep_25.11.r4023 Copyright (c) 2009-2014 Percona LLC and/or its affiliates Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 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> use dexdb 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 mysql> select * from dextb ; +------+------+ | id | name | +------+------+ | 1 | 22 | | 1 | 22 | +------+------+ 2 rows in set (0.00 sec)

mysql'sblobissuilableforstoringbinarydatawithinareldatabase, whilenosqloptionslikemongodb, redis, and cassandraofferflexible, scalablesolutionsforunstuctureddata.blobissimplerbutcanslowwownperformance를 사용하는 것들보업 betterscal randaysand

TOADDAUSERINMYSQL, 사용 : CreateUser'UserName '@'host'IdentifiedBy'Password '; 여기서'showTodoitseciRely : 1) ChoosetheHostCareLyTocon trolaccess.2) setResourcelimitswithOptionslikemax_queries_per_hour.3) Usestrong, iriquepasswords.4) enforcessl/tlsconnectionswith

toavoidcommonmistakeswithstringdatatypesinmysql, stroundStringTypenuances, chooseTherightType, andManageEncodingAndCollationSettingSefectively.1) usecharforfixed-lengthstrings, varcharvariable-length, andtext/blobforlargerdata.2) setcarcatter

mysqloffersechar, varchar, text, anddenumforstringdata.usecharforfixed-lengthstrings, varcharerforvariable 길이, 텍스트 forlarger 텍스트, andenumforenforcingdataantegritystofvalues.

mysqlblob 요청 최적화는 다음 전략을 통해 수행 할 수 있습니다. 1. Blob 쿼리의 빈도를 줄이거나 독립적 인 요청을 사용하거나 지연로드를 사용하십시오. 2. 적절한 Blob 유형 (예 : TinyBlob)을 선택하십시오. 3. Blob 데이터를 별도의 테이블로 분리하십시오. 4. 응용 프로그램 계층에서 블로브 데이터를 압축합니다. 5. Blob Metadata를 색인하십시오. 이러한 방법은 실제 애플리케이션에서 모니터링, 캐싱 및 데이터 샤딩을 결합하여 성능을 효과적으로 향상시킬 수 있습니다.

MySQL 사용자를 추가하는 방법을 마스터하는 것은 데이터베이스 관리자 및 개발자가 데이터베이스의 보안 및 액세스 제어를 보장하기 때문에 데이터베이스 관리자 및 개발자에게 중요합니다. 1) CreateUser 명령을 사용하여 새 사용자를 만듭니다. 2) 보조금 명령을 통해 권한 할당, 3) FlushPrivileges를 사용하여 권한이 적용되도록하십시오.

ChooseCharfixed-lengthdata, varcharforvariable-lengthdata, andtextforlargetextfields.1) charisefficientsconsentent-lengthdatalikecodes.2) varcharsuitsvariable-lengthdatalikeNames, 밸런싱 플렉스 및 성능

MySQL에서 문자열 데이터 유형 및 인덱스를 처리하기위한 모범 사례는 다음과 같습니다. 1) 고정 길이의 Char, 가변 길이의 Varchar 및 큰 텍스트의 텍스트와 같은 적절한 문자열 유형 선택; 2) 인덱싱에 신중하고, 과도한 인덱싱을 피하고, 공통 쿼리에 대한 인덱스를 만듭니다. 3) 접두사 인덱스 및 전체 텍스트 인덱스를 사용하여 긴 문자열 검색을 최적화합니다. 4) 인덱스를 작고 효율적으로 유지하기 위해 인덱스를 정기적으로 모니터링하고 최적화합니다. 이러한 방법을 통해 읽기 및 쓰기 성능의 균형을 맞추고 데이터베이스 효율성을 향상시킬 수 있습니다.


핫 AI 도구

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

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

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

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

Dreamweaver Mac版
시각적 웹 개발 도구

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.