Mysql上的RAC:Percona XtraDB Cluster负载均衡集群安装部署手册

 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

配置网易的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 {

[email protected]

}

notification_email_from [email protected]

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 {

[email protected]

}

notification_email_from [email protected]

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。

Mysql上的RAC:Percona XtraDB Cluster负载均衡集群安装部署手册,布布扣,bubuko.com

时间: 2024-12-24 07:53:03

Mysql上的RAC:Percona XtraDB Cluster负载均衡集群安装部署手册的相关文章

Linux 高可用负载均衡集群的部署

高可用负载均衡集群 ipvs 负载均衡常用的有四种模式 DR NAT TUN FULLNET 实验环境:准备四台rhel6.5的虚拟机四台.一台作为调度器server1,两台作为real server(server3,4),heartbeat服务关闭 172.25.50.10 server1.example.com 172.25.50.20 server2.example.com 172.25.50.30 server3.example.com 172.25.50.250 real50.exam

percona xtradb cluster 5.5集群生产环境安装之二

一.安装PXC要求 1.强烈推荐3个节点以上且硬件配置一样,一个节点性能受影响,整体受影响,遵循木桶效应 2.如果DDL语句有问题将破坏集群 3.创建数据库表引擎必须是INNODB,否则复合sql语句无法同步 4.创建数据库表必须要有主键索引,否则集群中有一台数据库会down掉 二.在线安装 yum remove -y mysql-libs rpm -qa |grep  Percona-Server |grep -v compat |xargs rpm -e --nodeps yum insta

percona xtradb cluster 5.5集群生产环境安装之一

服务器准备: 服务器 内存 CPU SSD ip OS DB1 32GB 4核 300GB 10.0.10.10/32 centos6.5 x64 DB2 32GB 4核 300GB 10.0.10.11/32 centos6.5 x64 DB3 32GB 4核 300GB 10.0.10.12/32 centos6.5 x64 一.CPU参数调整 在服务器的BIOS设置cpu发挥最大的性能 1.选择Performance Per Watt Optimized(DAPC)模式,发挥CPU最大性能

Nginx + Tomcat 反向代理 负载均衡 集群 部署指南

转载请注明出处:http://blog.csdn.net/smartbetter/article/details/53535435 Nginx是一种服务器软件,也是一种高性能的http和反向代理服务器,同时还是一个代理邮件服务器.也就是说,我们在Nginx上可以发布网站,可以实现负载均衡(提高应答效率,避免服务器崩溃),还可以作为邮件服务器实现收发邮件等功能.而最常见的就是使用Nginx实现负载均衡. Nginx与其他服务器的性能比较: Tomcat服务器面向Java语言,是重量级的服务器,而N

集群主要分成三大类 (高可用集群, 负载均衡集群,科学计算集群)

转自:http://blog.csdn.net/nick_php/article/details/52187905 高可用集群( High Availability Cluster) 负载均衡集群(Load Balance Cluster) 科学计算集群(High Performance Computing Cluster) 1.高可用集群(High Availability Cluster) 常见的就是2个节点做成的HA集群,有很多通俗的不科学的名称,比如"双机热备", "

Galera Cluster 实现mysql的高可用 (Percona XtraDB Cluster)

Galera Cluster 实现mysql的高可用 (Percona XtraDB Cluster) # 基础搭建 # 设备:三台主机 192.168.47.101 192.168.47.102 192.168.47.103 # centos7 系统 关闭防火墙 selinux # 设置清华源用于下载 cat >/etc/yum.repos.d/pxe.repo <<eof [percona] name=percona baseurl=https://mirrors.tuna.tsin

percona XTRADB Cluster 5.6在ubuntu安装

installing-perconaXTRADB Cluster 5.6 in-ubuntu-13-10-wheezy First of all, I would recommend login as root so that you don't have tosudo every time you hit the command and give the root password. 1.  $ su - $ su - Now you should be logged in as root.

实战:ansible自动化部署nginx+keepalived+mysql负载均衡集群

一.目的 使用ansible自动化部署nginx+keepalived+mysql负载均衡集群. 二.拓扑规划 三.详细步骤 1.环境的搭建 (1).安装ansible,同时配置私钥免密码进行通信 [[email protected] ~]# ssh-keygen  -t rsa #-t表示使用的加密类型,其中rsa1表示version1版本,rsa.dsa.ecdsa的加密对于的是version2版本 Generating public/private rsa key pair. #这里询问你

18.6 负载均衡集群介绍;18.7 LVS介绍;18.9 LVS NAT模式搭建(上);18.10 LVS NAT模式搭建(下)

扩展: lvs 三种模式详解 http://www.it165.net/admin/html/201401/2248.html lvs几种算法 http://www.aminglinux.com/bbs/thread-7407-1-1.html 关于arp_ignore和 arp_announce http://www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html lvs原理相关的   http://blog.csdn.net/pi9nc/