首页 > 数据库 > mysql教程 > Percona XtraDB Cluster安装部署手册_MySQL

Percona XtraDB Cluster安装部署手册_MySQL

WBOY
发布: 2016-05-31 08:48:56
原创
1350 人浏览过

 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

序号

名称

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

用途 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

优先级 88

advert_int 1

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

身份验证{

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

协议TCP

real_server192.168.0.7 3306

权重 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

权重 3

# notification_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 (圣地亚哥)

Ø 新建目录:

#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 安装包准备

安装光盘包目录下: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

安装

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 | | 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 #

端口                           = 3306

套接字                       =/data/munion_db/mysql.sock

[mysqld]

一般#

用户                           = mysql

默认存储引擎         = InnoDB

跳过名称解析

字符集服务器           = utf8

套接字                      =/data/munion_db/mysql .sock -恢复                 = 强制,备份

# 安全 #

最大允许数据包             = 16M

最大连接错误数             = 1000000

跳过名称-解析

sysdate-is-now                 = 1

innodb                        = FORCE

# 数据存储 #

datadir                        = /data/munion_db

# 二进制日志记录 #

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

expire-logs-days               = 14

sync-binlog                    = 1

# 复制 #

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

slave-net-timeout              = 60

# 缓存和限制 #

tmp-table-size = 250m

max-heap-table-size = 250m

query-cache-type = 0

QUERY-CACHECACHE SIZE SIZE = 0

最大连接数                = 2000

线程缓存大小              = 100

打开文件限制               = 65535

表定义缓存= 4096

表打开缓存               = 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-每个表文件          = 1

innodb-buffer-pool-size        = 25G

innodb_buffer_pool_instances   = 24

innodb_thread_sleep_delay      = 4 0

innodb_change_buffer_max_size = 50

innodb_adaptive_hash_index     = 1

init_connect='SET autocommit=0'

wait_timeout=100

#interactive_timeout=100

# 日志 #

日志错误                      =/data/munion_db/mysql-error.log

不使用索引的日志查询 = 1

慢查询日志                 = 1

慢查询日志文件            = /data/munion_db/mysql-slow.日志

wsrep的#config

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-v 2

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

#其他配置

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

配置第三两个节点

[mysql]

# CLIENT #

port                          = 3306

socket                        =/data/mun ion_db/mysql.sock

[mysqld]

# 一般 #

用户                          = mysql

默认存储引擎         = InnoDB

跳过名称解析

字符集服务器           = utf8

套接字                       =/data/munion_db/mysql.sock

pid 文件                       =/data/munion _db/mysql.pid

# MyISAM #

密钥缓冲区大小                = 32M

myisam-recover                = FORCE,BACKUP

# 安全 #

最大允许数据包             = 16M

最大连接错误数             = 1000000

跳过名称解析

sysdate-is-now                 = 1

innodb                         = 力量

# 数据存储 #

datadir                        = /data/munion_db

# 二进制日志 #

log-bin                        = /data/munion _db/mysql-bin

过期日志天数               = 14

sync-binlog                   = 1

# 复制#

中继日志                     =/data/munion_db/relay-bin

slave-net-timeout              = 60

# 缓存和限制 #

tmp-table-size                 = 32M

max-heap-table-size            = 32M

查询缓存类型               = 0

查询缓存大小              = 0

最大连接数                = 3000

线程缓存大小              = 100

打开文件限制               = 65535

表定义缓存         = 4096

表打开缓存               = 3000

# IN NODB#

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_time输出=100

# 日志 #

日志错误                      =/data/munion_db/mysql-error.log

未使用索引的日志查询 = 1

慢查询日志                 = 1

慢查询日志文件            = /data/munion_db/mysql-slow.log

#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

#其他配置

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

LVS Keepali ved 动画

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

#!/bin/bash

# 描述:配置 realserver lo 并应用 noarp

SNS_VIP= 192.168.0.110

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

case "$1" in

start)

ifconfig lo: 0 $SNS_VIP 网络掩码 255.255.255.255 广播 $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"

;;

停止)

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 已停止"

;;

*)

echo "用法: $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。

来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板