Table of Contents
 Percona XtraDB Cluster安装部署手册
应用部署方案
环境准备
服务器列表
列表
配置网易的YUM源
LVS安装
Keepalived安装
配置
Percona XtraDB Cluster安装
安装说明
安装准备
安装Percona XtraDB Cluster
配置第一个节点
配置第二个节点
LVS+Keepalived配合脚本
启动相关服务
测试
Home Database Mysql Tutorial Percona XtraDB Cluster安装部署手册_MySQL

Percona XtraDB Cluster安装部署手册_MySQL

May 31, 2016 am 08:48 AM

 Percona XtraDB Cluster安装部署手册

编写此文档,供PerconaXtraDB Cluster部署时使用。

系统维护人员及实施人员。

通过阅读该手册,让读者明确PerconaXtraDB Cluster的安装、配置和维护情况,为后续数据库运维工作提供指导。

应用部署方案

环境准备

服务器列表

序号

IP

用途

HOSTNAME

操作系统

1

192.168.0.7

Percona XtraDB Cluster

RedHat 6.3

2

192.168.0.9

Percona XtraDB Cluster

RedHat 6.3

3

192.168.0.15

LVS+Keepalived

RedHat 5.6

4

192.168.0.17

LVS+Keepalived

RedHat 5.6

列表

序号

名称

IP

1

LVS-DR-VIP

192.168.0.110

2

LVS-DR-Master

192.168.0.15

3

LVS-DR-BACKUP

192.168.0.17

4

MySQL1-Realserver

192.168.0.7

5

MySQL2-Realserver

192.168.0.9

6

GateWay

192.168.0.1

配置网易的YUM源

1. 导入证书(证书的位置http://mirrors.163.com/centos/)

rpm -importhttp://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-5

2. 使用网易的源

cd /etc/yum.repos.d/

wgethttp://mirrors.163.com/.help/CentOS5-Base-163.repo

3. 修改文件(把所有$releasever替换成5,保存)

vim CentOS5-Base-163.repo

4. 更新yum

yum -y update

LVS安装

1.    安装

yum install ipvsadm –y

Installing : ipvsadm-1.25-9.el6.i686 1/1

Installed:

ipvsadm.i686 0:1.25-9.el6

Complete!

2.   Ipvsadm命令参数

-C 清除表中所有的记录

ipvsadm -A -t 192.168.3.187:80 -s rr

-A --add-service在服务器列表中新添加一条新的虚拟服务器记录

-t 表示为tcp服务

-u 表示为udp服务

-s --scheduler 使用的调度算法, rr | wrr | lc | wlc | lblb |lblcr | dh | sh | sed | nq 默认调度算法是 wlc

ipvsadm -a -t 192.168.3.187:80 -r 192.168.200.10:80 -m-w 1

-a --add-server 在服务器表中添加一条新的真实主机记录

-t --tcp-service 说明虚拟服务器提供tcp服务

-u --udp-service 说明虚拟服务器提供udp服务

-r --real-server 真实服务器地址

-m --masquerading 指定LVS工作模式为NAT模式

-w --weight 真实服务器的权值

-g --gatewaying 指定LVS工作模式为直接路由器模式(也是LVS默认的模式)

-i --ipip 指定LVS的工作模式为隧道模式

-p 会话保持时间,定义流量呗转到同一个realserver的会话存留时间

调度算法

rr 轮询 round robin, wrr 加强轮询 weighted round robin,

新的请求被轮流分配到RealServer上,它假设服务器处理性能都相同,不管服务器当前的连接数和响应速度,不适合服务器性能不同的集群,这会导致服务器间的负载不平衡

dh 目的地址散列调度destination hashing

Keepalived安装

1.    gcc

安装命令:yum install gcc gcc-c++

2.    openssl-devel ,openssl

安装命令:yum install openssl-developenssl

3.    源码内核的

安装命令:yum install kernel-devel kernel

建立软连接:ln -s /usr/src/kernels/内核名称/   /usr/src/linux

4.    popt-devel,libnl-devel

安装命令:yum install popt-devellibnl-devel

5.    安装keepalived

#wgethttp://www.keepalived.org/software/keepalived-1.2.12.tar.gz

#tar xvzf keepalived-1.2.12.tar.gz

#cd keepalived-1.2.12

#uname –r

# ln -sv /usr/src/kernels/`uname-r`-`uname -m`/ /usr/src/linux # 必须做不然,编译会出错

#./configure --sysconf=/usr/local/keepalived--prefix=/usr/local/keepalived

# make && make install

#cp/usr/local/keepalived/sbin/keepalived /usr/sbin/

#cp/usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

#cp /usr/local/keepalived/etc/rc.d/init.d/keepalived/etc/init.d/

#mkdir /etc/keepalived

#vi/etc/keepalived/keepalived.conf

#chkconfig --add keepalived

#chkconfig keepalived on #做成系统服务

#service keepalivedstart|stop|status

配置

1.    主服务器配置keepalived.conf

global_defs{

notification_email {

duhj@c-sunrise.com

}

notification_email_from duhj@c-sunrise.com

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id mysql-ha

}

vrrp_instanceVI_1 {

state MASTER

interface eth0

virtual_router_id 51

priority 100

advert_int 1

nopreempt  #不抢占,只在priority高的节点上设置

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.0.110

}

}

virtual_server192.168.0.110 3306 {

delay_loop 2

lb_algo wrr

lb_kind DR

persistence_timeout 60

protocol TCP

real_server 192.168.0.7 3306

weight 3

# notify_down /root/sh/mysql.sh

TCP_CHECK {

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 3306

}

}

real_server 192.168.0.9 3306

weight 3

# notify_down /root/sh/mysql.sh

TCP_CHECK {

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 3306

}

}

}

2.    从服务器配置/etc/keepalived/keepalived.conf

global_defs {

notification_email {

duhj@c-sunrise.com

}

notification_email_from duhj@c-sunrise.com

smtp_server 127.0.0.1

smtp_connect_timeout 30

router_id mysql-ha

}

vrrp_instanceVI_1 {

state BACKUP

interface eth0

virtual_router_id 51

priority 88

advert_int 1

nopreempt  #不抢占,只在priority高的节点上设置

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.0.110

}

}

virtual_server192.168.0.110 3306 {

delay_loop 2

lb_algo wrr

lb_kind DR

persistence_timeout 60

protocolTCP

real_server192.168.0.7 3306

weight 3

#notify_down /root/sh/mysql.sh

TCP_CHECK {

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 3306

}

}

real_server 192.168.0.9 3306

weight 3

# notify_down /root/sh/mysql.sh

TCP_CHECK {

connect_timeout 10

nb_get_retry 3

delay_before_retry 3

connect_port 3306

}

}

}s

Percona XtraDB Cluster安装

安装说明

安装准备

Ø 服务器版本查看

# cat /etc/redhat-release

Red Hat Enterprise Linux Server release 6.4 (Santiago)

Ø 新建目录:

#mkdir -p /softwares

Ø 下载RPM包

l 下载XTRADB Cluster包

wget http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-56-5.6.15-25.5.759.rhel5.x86_64.rpm

wgethttp://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-56-debuginfo-5.6.15-25.5.759.rhel5.x86_64.rpm

wgethttp://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel6/x86_64/Percona-XtraDB-Cluster-client-56-5.6.15-25.5.759.rhel6.x86_64.rpm

wget

http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-devel-56-5.6.15-25.5.759.rhel5.x86_64.rpm

wgethttp://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-full-56-5.6.15-25.5.759.rhel5.x86_64.rpm

wgethttp://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-galera-3-3.4-1.213.rhel5.x86_64.rpm

wget

http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-galera-3-debuginfo-3.4-1.213.rhel5.x86_64.rpm

wget

http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-server-56-5.6.15-25.5.759.rhel5.x86_64.rpm

wget

http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-shared-56-5.6.15-25.5.759.rhel5.x86_64.rpm

wget

http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster-56/LATEST/RPM/rhel5/x86_64/Percona-XtraDB-Cluster-test-56-5.6.15-25.5.759.rhel5.x86_64.rpm

l 下载XTRABACKUP包

wgethttp://www.percona.com/redir/downloads/XtraBackup/LATEST/binary/redhat/5/x86_64/percona-xtrabackup-2.2.3-4982.el5.x86_64.rpm

wget

http://www.percona.com/redir/downloads/XtraBackup/LATEST/binary/redhat/5/x86_64/percona-xtrabackup-debuginfo-2.2.3-4982.el5.x86_64.rpm

wget

ttp://www.percona.com/redir/downloads/XtraBackup/LATEST/binary/redhat/5/x86_64/percona-xtrabackup-test-2.2.3-4982.el5.x86_64.rpm

Ø 安装依赖包

l 安装包准备

安装光盘package目录下:perl-DBD-MySQL-4.013-3.el6.x86_64.rpm

wgethttp://repo.webtatic.com/yum/el6/x86_64/libmysqlclient16-5.1.69-1.w6.x86_64.rpm

wget     http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/socat-1.7.2.4-1.el6.rf.x86_64.rpm

wget

http://mirror.centos.org/centos/6/os/x86_64/Packages/nc-1.84-22.el6.x86_64.rpm

l 安装

rpm -ivhlibmysqlclient16-5.1.69-1.w6.x86_64.rpm

rpm -ivhperl-DBD-MySQL-4.013-3.el6.x86_64.rpm socat-1.7.2.4-1.el6.rf.x86_64.rpmnc-1.84-22.el6.x86_64.rpm

Ø 删除原有软件包

rpm -qa | grep mysql  | xargs sudo rpm -e –nodeps

安装Percona XtraDB Cluster

Ø 安装percona-xtrabackup

rpm -ivhpercona-xtrabackup-2.1.9-744.rhel6.x86_64.rpm

Ø 安装Percona-XtraDB-Cluster-galera

rpm -ivhPercona-XtraDB-Cluster-galera-3-3.5-1.216.rhel6.x86_64.rpmPercona-XtraDB-Cluster-galera-3-debuginfo-3.5-1.216.rhel6.x86_64.rpm

Ø 安装Percona-XtraDB-Cluster-client

rpm -ivhPercona-XtraDB-Cluster-client-56-5.6.15-25.5.759.rhel6.x86_64.rpm

Ø 安装libmysqlclient16-5.1.69-1.w6.x86_64

rpm -ivhlibmysqlclient16-5.1.69-1.w6.x86_64.rpm

Ø 安装Percona-XtraDB-Cluster-server

rpm -ivhPercona-XtraDB-Cluster-server-56-5.6.15-25.5.759.rhel6.x86_64.rpm

配置第一个节点

1、编辑配置文件

find / -name 'my-default.cnf'

cp my-default.cnf /etc/my.cnf

vi /etc/my.cnf

[mysql]

# CLIENT #

port                           = 3306

socket                         =/data/munion_db/mysql.sock

[mysqld]

# GENERAL #

user                           = mysql

default-storage-engine         = InnoDB

skip-name-resolve

character-set-server           = utf8

socket                         =/data/munion_db/mysql.sock

pid-file                       =/data/munion_db/mysql.pid

# MyISAM #

key-buffer-size                = 32M

myisam-recover                 = FORCE,BACKUP

# SAFETY #

max-allowed-packet             = 16M

max-connect-errors             = 1000000

skip-name-resolve

sysdate-is-now                 = 1

innodb                         = FORCE

# DATA STORAGE #

datadir                        = /data/munion_db

# BINARY LOGGING #

log-bin                        =/data/munion_db/mysql-bin

expire-logs-days               = 14

sync-binlog                    = 1

# REPLICATION #

relay-log                      =/data/munion_db/relay-bin

slave-net-timeout              = 60

# CACHES AND LIMITS #

tmp-table-size                 = 250M

max-heap-table-size            = 250M

query-cache-type               = 0

query-cache-size               = 0

max-connections                = 2000

thread-cache-size              = 100

open-files-limit               = 65535

table-definition-cache         = 4096

table-open-cache               = 6000

# INNODB #

innodb-flush-method            = O_DIRECT

innodb-log-files-in-group      = 4

innodb-log-file-size           = 1g

innodb_log_buffer_size         = 30M

innodb-flush-log-at-trx-commit = 2

innodb-file-per-table          = 1

innodb-buffer-pool-size        = 25G

innodb_buffer_pool_instances   = 24

innodb_thread_sleep_delay      = 40

innodb_change_buffer_max_size  = 50

innodb_adaptive_hash_index     = 1

init_connect='SET autocommit=0'

wait_timeout=100

#interactive_timeout=100

# LOGGING #

log-error                      =/data/munion_db/mysql-error.log

log-queries-not-using-indexes  = 1

slow-query-log                 = 1

slow-query-log-file            = /data/munion_db/mysql-slow.log

#config for wsrep

wsrep_provider=/usr/lib64/libgalera_smm.so

wsrep_cluster_address=gcomm://10.25.141.55,10.25.141.56

binlog_format=ROW

default_storage_engine=InnoDB

innodb_autoinc_lock_mode=2

wsrep_node_address=10.25.141.55

wsrep_sst_method=xtrabackup-v2

wsrep_cluster_name=my_centos_cluster

wsrep_sst_auth="sstuser:s3cret"

wsrep_slave_threads=8

wsrep_provider_options='gcs.max_packet_size=10485760;gcache.size=2147483648;replicator.commit_order=3'

wsrep_max_ws_rows=10485760

wsrep_max_ws_size=2147483648

#config for others

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

配置第二个节点

[mysql]

# CLIENT #

port                           = 3306

socket                         =/data/munion_db/mysql.sock

[mysqld]

# GENERAL #

user                           = mysql

default-storage-engine         = InnoDB

skip-name-resolve

character-set-server           = utf8

socket                         =/data/munion_db/mysql.sock

pid-file                       =/data/munion_db/mysql.pid

# MyISAM #

key-buffer-size                = 32M

myisam-recover                 = FORCE,BACKUP

# SAFETY #

max-allowed-packet             = 16M

max-connect-errors             = 1000000

skip-name-resolve

sysdate-is-now                 = 1

innodb                         = FORCE

# DATA STORAGE #

datadir                        = /data/munion_db

# BINARY LOGGING #

log-bin                        = /data/munion_db/mysql-bin

expire-logs-days               = 14

sync-binlog                    = 1

# REPLICATION #

relay-log                      =/data/munion_db/relay-bin

slave-net-timeout              = 60

# CACHES AND LIMITS #

tmp-table-size                 = 32M

max-heap-table-size            = 32M

query-cache-type               = 0

query-cache-size               = 0

max-connections                = 3000

thread-cache-size              = 100

open-files-limit               = 65535

table-definition-cache         = 4096

table-open-cache               = 3000

# INNODB #

innodb-flush-method            = O_DIRECT

innodb-log-files-in-group      = 4

innodb-log-file-size           = 1g

innodb_log_buffer_size         = 30M

innodb-flush-log-at-trx-commit = 2

innodb-file-per-table          = 1

innodb-buffer-pool-size        = 25G

innodb_buffer_pool_instances   = 12

innodb_thread_sleep_delay      = 40

init_connect='SET autocommit=0'

wait_timeout=100

interactive_timeout=100

# LOGGING #

log-error                      =/data/munion_db/mysql-error.log

log-queries-not-using-indexes  = 1

slow-query-log                 = 1

slow-query-log-file            = /data/munion_db/mysql-slow.log

#config for wsrep

wsrep_provider=/usr/lib64/libgalera_smm.so

wsrep_cluster_address=gcomm://10.25.141.55,10.25.141.56

binlog_format=ROW

default_storage_engine=InnoDB

innodb_autoinc_lock_mode=2

wsrep_node_address=10.25.141.56

wsrep_cluster_name=my_centos_cluster

#wsrep_sst_method=xtrabackup-v2

wsrep_sst_method=rsync

wsrep_sst_auth="sstuser:s3cret"

wsrep_slave_threads=8

wsrep_provider_options='gcs.max_packet_size=10485760;gcache.size=2147483648;replicator.commit_order=3'

wsrep_max_ws_rows=10485760

wsrep_max_ws_size=2147483648

#config for others

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

LVS+Keepalived配合脚本

#vi /etc/rc.d/init.d/realserver.sh

#!/bin/bash

# description: Config realserver lo andapply noarp

SNS_VIP=192.168.0.110

# /etc/rc.d/init.d/functions

case "$1" in

start)

ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP

/sbin/route add -host $SNS_VIP dev lo:0

echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

sysctl -p >/dev/null 2>&1

echo "RealServer Start OK"

;;

stop)

ifconfig lo:0 down

route del $SNS_VIP >/dev/null 2>&1

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce

echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore

echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce

echo "RealServer Stoped"

;;

*)

echo "Usage: $0 {start|stop}"

exit 1

esac

exit 0

启动相关服务

Ø 主备LVS

#servicekeepalived start #启动keepalived服务

Ø MySQL Cluster中的2台SQL节点

#cd /etc/rc.d/init.d/

#chmod 755 realserver.sh

#./realserver.sh

测试

方法一:

#telnet192.168.0.110 3306

方法二:

使用mysql的各种客户端工具连接mysql。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain InnoDB Full-Text Search capabilities. Explain InnoDB Full-Text Search capabilities. Apr 02, 2025 pm 06:09 PM

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Difference between clustered index and non-clustered index (secondary index) in InnoDB. Difference between clustered index and non-clustered index (secondary index) in InnoDB. Apr 02, 2025 pm 06:25 PM

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values ​​and pointers to data rows, and is suitable for non-primary key column queries.

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)? Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

How do you handle large datasets in MySQL? How do you handle large datasets in MySQL? Mar 21, 2025 pm 12:15 PM

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Explain different types of MySQL indexes (B-Tree, Hash, Full-text, Spatial). Apr 02, 2025 pm 07:05 PM

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

See all articles