侧边栏壁纸
博主头像
飞云资料栈博主等级

行动起来,活在当下

  • 累计撰写 91 篇文章
  • 累计创建 7 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

集权对比.md

Fly
Fly
2021-11-14 / 0 评论 / 0 点赞 / 25 阅读 / 60478 字

һ���ԣ����нڵ������һ�¡�
A---�����ԣ�һ�������ڵ�ʧЧ����Ӱ���������
P---���������ԣ��ڵ�������ʧЧ����Ȼ���Դ�������
�κ�һ���ֲ�ʽϵͳ����Ҫ�����������е�������
MySQL Replication: �����Ժͷ���������
Percona XtraDB Cluster: һ���ԺͿ�����
���MySQL Replication������֤���ݵ�һ���ԣ���Percona XtraDB Cluster�ṩ����һ���ԡ�
Percona XtraDB Cluster�����
Percona XtraDB Cluster����XtraDB��Percona Server�Լ�����д���Ƽ�������ʹ��Galera 2.x library��������Ӧ���µ�ͨ�õĶ���ͬ�����Ʋ����
Galera 2.x��������
1.IST(Incremental State Transfer)����״̬���䡣����WAN�ر����á�
2.RSU(Rolling Schema Update)��ת���¼ܹ���������ֹ�Ա���в�����

��.��ʼ����
Ϊ��ʹ��XtraDB��Ⱥ����Ҫ��my.cnf�ļ�����������ѡ�
wsrep_provider -- a path to Galera library.
wsrep_cluster_address -- cluster connection URL.
binlog_format=ROW
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1

����IJ�����

wsrep_slave_threads #ָ���߳�����
wsrep_sst_method
4.��װXtraBackup SST����
Ϊ��ʹ��Percona XtraBackup��State Transfer method(�ڵ�����ݵĿ��ո�������)������ʹ��֧��Galera��Ϣ�Ľű�����ʽ��xtrabackup�������Դ�innobackupexԴ����еõ�innobackupex�ű���ͬʱ��my.cnf�ļ����ƶ���
wsrep_sst_method=xtrabackup

��.������ ��Innodb
1.Ŀǰ�ĸ��ƽ���֧��InnoDB�洢���档�κ�д����������ı�����mysql.*�����Ḵ�ơ�����DDL���ᱻ���Ƶģ���˴����û����ᱻ���ƣ�����insert into mysql.user...�����ᱻ���Ƶġ�
2.DELETE������֧��û�������ı�û�������ı��ڲ�ͬ�Ľڵ�˳�򽫲�ͬ�����ִ��SELECT...LIMIT... �����ֲ�ͬ�Ľ������
3.�ڶ���������LOCK/UNLOCK TABLES��֧�֡��Լ�������GET_LOCK(), RELEASE_LOCK()...
4.��ѯ��־���ܱ����ڱ��С����������ѯ��־��ֻ�ܱ��浽�ļ��С�
5.�������������С��wsrep_max_ws_rows��wsrep_max_ws_size���塣�κδ��Ͳ��������ܾ�������͵�LOAD DATA������
6.���ڼ�Ⱥ���ֹ۵IJ������ƣ�����commit�����ڸý׶���ֹ������������������ڼ�Ⱥ�в�ͬ�Ľڵ���ͬһ��д�벢�ύ��ʧ�ܵĽڵ㽫��ֹ�����ڼ�Ⱥ�������ֹ����Ⱥ���������������(Error: 1213 SQLSTATE: 40001 (ER_LOCK_DEADLOCK)).
7.XA����֧�֣��������ύ�Ͽ��ܻع���
8.������Ⱥ��д�����������������Ľڵ����ƣ������һ���ڵ��û�������ô������Ⱥ���ǻ����ġ�Ϊ���ȶ��ĸ�����Ҫ�����еĽڵ�Ӧʹ��ͳһ��Ӳ����
9.��Ⱥ�ڵ㽨������3����
10.���DDL��������⽫�ƻ���Ⱥ��
�ģ���Ⱥ�ڲ�����д������id�����������缯Ⱥ����̨������3 6 9�������Ƶ���
�壮�����������Ⱥÿһ���ڵ����־��Ҫ����ʱ�䳤�������ÿ���ڵ㶼����־���ݣ����ݱ��ݷ�ֹ��һ���ڵ��˳���Ⱥ�������ݿ�û�йҵ�Ȼ��haproxy�����ڷַ����������ݲ�һ�½������û�бȶ�ʮ���鷳ʹ��toad for mysql���бȶ���ʱ���ܶ���֮�Զ���֮�����Ⱥ�ӻ��Dz��ٵ�

һ.Mariadb��Ⱥ+haproxy+keepalived
���ߣ�zuoyuezong@126.com

ע��sysbench5.0 �汾�� sysbench4.2�汾���ԵĽ���������ͬ������ͬ�������Ƚ�
1.��װmariadb��Ⱥ
1.�������������£�

1��˫�� xeon e5-2680��CPU
[root@zyz_dba_test01 ~]# head -4 /proc/meminfo
MemTotal: 1922464 kB
MemFree: 79904 kB
Buffers: 159296 kB
Cached: 1366644 kB
2G�������ڴ�

2.ϵͳ��������
Red Hat Enterprise Linux Server release 6.4 (Santiago)
3.��Ⱥ�汾
mariadb-galera-10.0.17-linux-x86_64.tar.gz
Haproxy
Haproxy��һ����������ؾ�����������֧��4���7��ģʽ���ṩ��˷�����������飬�dz��ȶ����Ա�ǰ��Ҳʹ��Haproxy��ΪCDNϵͳ���ؾ�����

haproxy�汾��1.4.25

4.ip��ַ
10.21.3.106 node1
10.21.3.107 node2
10.21.3.108 node3
10.21.3.109 haproxy
���õ�ÿ̨��/etc/hosts�ļ���

5.��װ
1.node1 node2 node3 ִ�����²�����
ln -sf /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6
ln -sf /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6

2.�ļ�����һ��Ŀ¼��/usr/local/sc ��3̨�Ͻ�ѹ

tar -xf  /usr/local/src/mariadb-galera-10.0.17-linux-x86_64.tar.gz
mv   /usr/local/src/mariadb-galera-10.0.17-linux-x86_64 /usr/local/mysql
cd mysql/scripts
mkdir /data/db
useradd mariadb
chown mariadb:mariadb /data/db
./mysql_install_db --datadir=/data/db/ --basedir=/usr/local/mysql/ --user=mariadb

���·ֱ��node1 node2 node3�������ļ�

 cat  > /usr/local/mysql/my1.cnf  <<OO
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock
[mysqld]
port            = 3306
user=mariadb
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
log-bin=mysql-bin
binlog_format = ROW
server-id       = 1
innodb_autoinc_lock_mode = 2
wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_name = "my_mariadb_cluster"
wsrep_cluster_address="gcomm://"
wsrep_cluster_name='example_cluster'
wsrep_node_name = "cluster_node1"

wsrep_node_address = 10.21.3.106:4406
wsrep_sst_auth=tt:123
wsrep_node_name='node1'
wsrep_sst_method=rsync

[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
OO

Node2�����ļ�:

cat > /etc/my.cnf << PP
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock


[mysqld]
port            = 3306
user=mariadb
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
datadir=/data/db
log-bin=mysql-bin
binlog_format = ROW
server-id       = 2

innodb_autoinc_lock_mode = 2
wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_name = "my_mariadb_cluster"
wsrep_cluster_address="gcomm://10.21.3.106,10.21.3.108"
wsrep_cluster_name='example_cluster'
wsrep_node_name = "cluster_node2"
wsrep_node_address = 10.21.3.107:4406
wsrep_sst_auth=tt:123
wsrep_node_name='node2'
wsrep_sst_method=rsync
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
PP

Node3�����ļ���

cat > /etc/my.cnf << HH
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock


[mysqld]
port            = 3306
user=mariadb
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
datadir=/data/db
 max_connections=1000 
log-bin=mysql-bin

binlog_format = ROW

server-id       = 3

innodb_autoinc_lock_mode = 2

wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so

wsrep_cluster_name = "my_mariadb_cluster"

wsrep_cluster_address="gcomm://10.21.3.106,10.21.3.107"
wsrep_cluster_name='example_cluster'

wsrep_node_name = "cluster_node3"

wsrep_node_address = 10.21.3.108:4406
wsrep_sst_auth=tt:123
wsrep_node_name='node3'
wsrep_sst_method=rsync

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M

[mysqlhotcopy]
interactive-timeout
HH

˳���������ݿ�
Node2��node3�ϣ�node1����Ҫ��
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

Node1: /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my1.cnf --wsrep-new-cluster
Node2:service mysqld restart
Node3:serivce mysqld restart
����������һ̨����ɾ�����ݾ���ͬ��
6.ѹ������

CREATE TABLE  test.`sbtest` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `k` int(10) unsigned NOT NULL DEFAULT '0',
  `c` char(120) NOT NULL DEFAULT '',
  `pad` char(60) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  KEY `k` (`k`)
) ENGINE=InnoDB;
create table test.sbtest1  select * from  test.sbtest; create table test.sbtest2  select * from  test.sbtest;create table test.sbtest3  select * from  test.sbtest;create table test.sbtest4  select * from  test.sbtest;create table test.sbtest5  select * from  test.sbtest;create table test.sbtest6  select * from  test.sbtest;create table test.sbtest7 select * from  test.sbtest;create table test.sbtest8  select * from  test.sbtest;create table test.sbtest9  select * from  test.sbtest;create table test.sbtest10  select * from  test.sbtest;

create database sbtest;create table sbtest.sbtest  select * from  test.sbtest;create table sbtest.sbtest1  select * from  test.sbtest;create table sbtest.sbtest2  select * from  test.sbtest;create table sbtest.sbtest3  select * from  test.sbtest;create table sbtest.sbtest4  select * from  test.sbtest;create table sbtest.sbtest5  select * from  test.sbtest;create table sbtest.sbtest6  select * from  test.sbtest;create table sbtest.sbtest7  select * from  test.sbtest;create table sbtest.sbtest8  select * from  test.sbtest;create table sbtest.sbtest9  select * from  test.sbtest;create table sbtest.sbtest10  select * from  test.sbtest;

��װsysbench
[root@zyz_dba_test02~]#wget http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster/5.5.37-25.10/RPM/rhel6/x86_64/Percona-XtraDB-Cluster-shared-55-5.5.37-25.10.756.el6.x86_64.rpm
[root@zyz_dba_test02~]#yum -y install Percona-XtraDB-Cluster-shared-55-5.5.37-25.10.756.el6.x86_64.rpm
[root@zyz_dba_test02 ~]# rpm -ivh sysbench-0.5-2.el6_.x86_64.rpm
Preparing... ########################################### [100%]
1:sysbench ########################################### [100%]
���˰�װ���
sysbench --test=/usr/share/doc/sysbench/tests/db/select.lua --mysql-table-engine=innodb --oltp-table-size=1000000 --max-requests=0 --max-time=60 --num-threads=100 --oltp-tables-count=10 --report-interval=1 --mysql-host=10.21.3.108 --mysql-port=3306 --mysql-user=root --mysql-password=123 --mysql-db=test run
�����²���800������µ�QPS ��

CPU �Ѿ�ʹ��load 43.19

����ͼ���Կ��������������Ϸ���������ֻ���ܴﵽ14015.38

CPUռ�ø���0.3��ʱ��Ҳ��������ֵ��ʱ��ƽ��ֵ����5000

root@zyz_dba_test03 ~]# sysbench --test=/usr/share/doc/sysbench/tests/db/select.lua --mysql-table-engine=innodb --oltp-table-size=1000000 --max-requests=0 --max-time=60 --num-threads=1 --oltp-tables-count=10 --report-interval=1 --mysql-host=10.21.3.108 --mysql-port=3306 --mysql-user=root --mysql-password=123 --mysql-db=test run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1
Report intermediate results every 1 second(s)
Random number generator seed is 0 and will be ignored


Threads started!

[   1s] threads: 1, tps: 0.00, reads/s: 4603.85, writes/s: 0.00, response time: 0.34ms (95%)
[   2s] threads: 1, tps: 0.00, reads/s: 5050.07, writes/s: 0.00, response time: 0.28ms (95%)
[   3s] threads: 1, tps: 0.00, reads/s: 5080.91, writes/s: 0.00, response time: 0.28ms (95%)
[   4s] threads: 1, tps: 0.00, reads/s: 4807.06, writes/s: 0.00, response time: 0.28ms (95%)
[   5s] threads: 1, tps: 0.00, reads/s: 4794.00, writes/s: 0.00, response time: 0.29ms (95%)
[   6s] threads: 1, tps: 0.00, reads/s: 5018.65, writes/s: 0.00, response time: 0.28ms (95%)
[   7s] threads: 1, tps: 0.00, reads/s: 5119.29, writes/s: 0.00, response time: 0.28ms (95%)
[   8s] threads: 1, tps: 0.00, reads/s: 4835.05, writes/s: 0.00, response time: 0.30ms (95%)
[   9s] threads: 1, tps: 0.00, reads/s: 4900.95, writes/s: 0.00, response time: 0.30ms (95%)
[  10s] threads: 1, tps: 0.00, reads/s: 4981.05, writes/s: 0.00, response time: 0.28ms (95%)
[  11s] threads: 1, tps: 0.00, reads/s: 5090.04, writes/s: 0.00, response time: 0.27ms (95%)
[  12s] threads: 1, tps: 0.00, reads/s: 5091.90, writes/s: 0.00, response time: 0.27ms (95%)
[  13s] threads: 1, tps: 0.00, reads/s: 5085.02, writes/s: 0.00, response time: 0.28ms (95%)
[  14s] threads: 1, tps: 0.00, reads/s: 5111.03, writes/s: 0.00, response time: 0.28ms (95%)
[  15s] threads: 1, tps: 0.00, reads/s: 5062.60, writes/s: 0.00, response time: 0.29ms (95%)
[  16s] threads: 1, tps: 0.00, reads/s: 5044.30, writes/s: 0.00, response time: 0.28ms (95%)
[  17s] threads: 1, tps: 0.00, reads/s: 3402.04, writes/s: 0.00, response time: 0.28ms (95%)
[  18s] threads: 1, tps: 0.00, reads/s: 5106.10, writes/s: 0.00, response time: 0.28ms (95%)
[  19s] threads: 1, tps: 0.00, reads/s: 5096.99, writes/s: 0.00, response time: 0.27ms (95%)
[  20s] threads: 1, tps: 0.00, reads/s: 4992.88, writes/s: 0.00, response time: 0.28ms (95%)
[  21s] threads: 1, tps: 0.00, reads/s: 5110.09, writes/s: 0.00, response time: 0.28ms (95%)
[  22s] threads: 1, tps: 0.00, reads/s: 5148.97, writes/s: 0.00, response time: 0.28ms (95%)
[  23s] threads: 1, tps: 0.00, reads/s: 5077.03, writes/s: 0.00, response time: 0.28ms (95%)
[  24s] threads: 1, tps: 0.00, reads/s: 5065.69, writes/s: 0.00, response time: 0.28ms (95%)
[  25s] threads: 1, tps: 0.00, reads/s: 5071.30, writes/s: 0.00, response time: 0.28ms (95%)
[  26s] threads: 1, tps: 0.00, reads/s: 5095.95, writes/s: 0.00, response time: 0.28ms (95%)
[  27s] threads: 1, tps: 0.00, reads/s: 5141.07, writes/s: 0.00, response time: 0.27ms (95%)
[  28s] threads: 1, tps: 0.00, reads/s: 5095.01, writes/s: 0.00, response time: 0.28ms (95%)
[  29s] threads: 1, tps: 0.00, reads/s: 5130.99, writes/s: 0.00, response time: 0.28ms (95%)
[  30s] threads: 1, tps: 0.00, reads/s: 5040.05, writes/s: 0.00, response time: 0.29ms (95%)
[  31s] threads: 1, tps: 0.00, reads/s: 4992.92, writes/s: 0.00, response time: 0.29ms (95%)
[  32s] threads: 1, tps: 0.00, reads/s: 4390.00, writes/s: 0.00, response time: 0.28ms (95%)
[  33s] threads: 1, tps: 0.00, reads/s: 4949.77, writes/s: 0.00, response time: 0.28ms (95%)
[  34s] threads: 1, tps: 0.00, reads/s: 4619.22, writes/s: 0.00, response time: 0.28ms (95%)
[  35s] threads: 1, tps: 0.00, reads/s: 4519.03, writes/s: 0.00, response time: 0.28ms (95%)
[  36s] threads: 1, tps: 0.00, reads/s: 5154.03, writes/s: 0.00, response time: 0.28ms (95%)
[  37s] threads: 1, tps: 0.00, reads/s: 4816.98, writes/s: 0.00, response time: 0.28ms (95%)
[  38s] threads: 1, tps: 0.00, reads/s: 5111.99, writes/s: 0.00, response time: 0.28ms (95%)
[  39s] threads: 1, tps: 0.00, reads/s: 5146.03, writes/s: 0.00, response time: 0.27ms (95%)
[  40s] threads: 1, tps: 0.00, reads/s: 5025.99, writes/s: 0.00, response time: 0.27ms (95%)
[  41s] threads: 1, tps: 0.00, reads/s: 5105.00, writes/s: 0.00, response time: 0.27ms (95%)
[  42s] threads: 1, tps: 0.00, reads/s: 5053.86, writes/s: 0.00, response time: 0.28ms (95%)
[  43s] threads: 1, tps: 0.00, reads/s: 4647.15, writes/s: 0.00, response time: 0.29ms (95%)
[  44s] threads: 1, tps: 0.00, reads/s: 5068.91, writes/s: 0.00, response time: 0.29ms (95%)
[  45s] threads: 1, tps: 0.00, reads/s: 5105.05, writes/s: 0.00, response time: 0.28ms (95%)
[  46s] threads: 1, tps: 0.00, reads/s: 5094.96, writes/s: 0.00, response time: 0.27ms (95%)
[  47s] threads: 1, tps: 0.00, reads/s: 5066.08, writes/s: 0.00, response time: 0.27ms (95%)
[  48s] threads: 1, tps: 0.00, reads/s: 4955.88, writes/s: 0.00, response time: 0.27ms (95%)
[  49s] threads: 1, tps: 0.00, reads/s: 4237.05, writes/s: 0.00, response time: 0.28ms (95%)
[  50s] threads: 1, tps: 0.00, reads/s: 4958.96, writes/s: 0.00, response time: 0.29ms (95%)
[  51s] threads: 1, tps: 0.00, reads/s: 4997.98, writes/s: 0.00, response time: 0.29ms (95%)
[  52s] threads: 1, tps: 0.00, reads/s: 4984.12, writes/s: 0.00, response time: 0.29ms (95%)
[  53s] threads: 1, tps: 0.00, reads/s: 4818.93, writes/s: 0.00, response time: 0.28ms (95%)
[  54s] threads: 1, tps: 0.00, reads/s: 5099.00, writes/s: 0.00, response time: 0.28ms (95%)
[  55s] threads: 1, tps: 0.00, reads/s: 5079.00, writes/s: 0.00, response time: 0.28ms (95%)
[  56s] threads: 1, tps: 0.00, reads/s: 5119.94, writes/s: 0.00, response time: 0.27ms (95%)
[  57s] threads: 1, tps: 0.00, reads/s: 4636.10, writes/s: 0.00, response time: 0.29ms (95%)
[  58s] threads: 1, tps: 0.00, reads/s: 5023.99, writes/s: 0.00, response time: 0.28ms (95%)
[  59s] threads: 1, tps: 0.00, reads/s: 5041.95, writes/s: 0.00, response time: 0.29ms (95%)
[  60s] threads: 1, tps: 0.00, reads/s: 4971.98, writes/s: 0.00, response time: 0.29ms (95%)

OLTP test statistics:
    queries performed:
        read:                            297036
        write:                           0
        other:                           0
        total:                           297036
    transactions:                        0      (0.00 per sec.)
    deadlocks:                           0      (0.00 per sec.)
    read/write requests:                 297036 (4950.56 per sec.)
    other operations:                    0      (0.00 per sec.)

General statistics:
    total time:                          60.0005s
    total number of events:              297036
    total time taken by event execution: 59.5268s
    response time:
         min:                                  0.10ms
         avg:                                  0.20ms

         max:                                333.52ms
         approx.  95 percentile:               0.28ms

Threads fairness:
    events (avg/stddev):           297036.0000/0.00
execution time (avg/stddev):   59.5268/0.00

2���̵߳�ʱ��
``
sysbench --test=/usr/share/doc/sysbench/tests/db/select.lua --mysql-table-engine=innodb --oltp-table-size=1000000 --max-requests=0 --max-time=90 --num-threads=2 --oltp-tables-count=10 --report-interval=1 --mysql-host=10.21.3.108 --mysql-port=3306 --mysql-user=root --mysql-password=123 --mysql-db=test run

``

������������mysql5.6.24��ѹ��ͬһ������ ��װ��mysql��3307�˿�
���֤������mysql5.6.24��tps ��qps���ӵĸ�һЩ

Qps������̫��ʹ�õ���sysbench0.5�汾�� 0.4�汾�Ļ�mariadb ���Ե�tps���Ǻ�0.5�汾�бȽϴ��������������Ļ���ͬһ������mariadb10.0.17��Ⱥ��mysql5.6.24�ĵ�ʵ���ıȽϻ�ͷ�ᰲװ��mysql5.6.24��Ⱥ�����������ѹ��Ƚϣ�
TPS��

 
[root@zyz_dba_test03 ~]#  sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=9 --oltp-table-size=10 --rand-init=on --num-threads=1000  --oltp-read-only=off --report-interval=1 --rand-type=gaussian --max-time=3000 --max-requests=0 --mysql-host=10.21.3.108 --mysql-port=3307 --mysql-user=root --mysql-password=123 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 1000
Report intermediate results every 1 second(s)
Initializing random number generator from timer.

Random number generator seed is 0 and will be ignored


Threads started!

[   1s] threads: 1000, tps: 0.00, reads/s: 11258.02, writes/s: 7.00, response time: 0.00ms (95%)
[   2s] threads: 1000, tps: 217.97, reads/s: 5323.38, writes/s: 927.89, response time: 1956.38ms (95%)
[   3s] threads: 1000, tps: 380.05, reads/s: 5429.68, writes/s: 1501.19, response time: 2941.13ms (95%)
[   4s] threads: 1000, tps: 624.99, reads/s: 3677.92, writes/s: 2810.94, response time: 3578.21ms (95%)
[   5s] threads: 1000, tps: 280.01, reads/s: 5856.11, writes/s: 907.02, response time: 2867.24ms (95%)
[   6s] threads: 1000, tps: 230.97, reads/s: 4535.40, writes/s: 1125.85, response time: 2860.39ms (95%)
[   7s] threads: 1000, tps: 358.06, reads/s: 6401.04, writes/s: 1108.18, response time: 3526.11ms (95%)
[   8s] threads: 1000, tps: 293.91, reads/s: 4854.51, writes/s: 1237.62, response time: 4222.37ms (95%)

������1000���̵߳�����»����ܴﵽ300TPS
��100���̵߳�����»����ܴﵽ600��mariadb��Ⱥ�ؽ����ܴﵽ60���������ֹ10��
sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=9 --oltp-table-size=10 --rand-init=on --num-threads=100 --oltp-read-only=off --report-interval=1 --rand-type=gaussian --max-time=3000 --max-requests=0 --mysql-host=10.21.3.108 --mysql-port=3307 --mysql-user=root --mysql-password=123 run
����qps ����ͬ�⻷��mysql5.6.24��ǿ tps5.6.24ǿ̫��
2.Haproxy
Haproxy ������
HAProxy��һ����Դ�ġ������ܵģ�����TCP(���IJ�)��HTTP(��7��)Ӧ�õĸ��ؾ��������ʹ��HAProxy���Կ��ٿɿ���ʵ�ֻ���TCP��HTTPӦ�õĸ��ؾ�����������
��Ϊһ��רҵ�ĸ��ؾ�����������������ŵ㣺
1.�ɿ��Ժ��ȶ��Էdz��ã�������Ӳ������F5���ؾ����豸������
2.��߿���ͬʱά��40000-50000���������ӣ���λʱ�䴦��������������20000����������ݴ��������ɴ�10Gbps��
3.֧�ֶ��8�ָ��ؾ����㷨��ͬʱҲ֧��session����
4.֧�������������ܣ�ʹʵ��web���ؾ���������
5.��HAProxy 1.3�汾��ʼ֧�����Ӿܾ���ȫ͸������ȹ��ܣ���Щ�������������ؾ����������߱��ġ�
6.�й���ǿ��ļ��ҳ�棬ͨ����ҳ�����ʵʱ�˽�ϵͳ������״����
7.ӵ�й���ǿ���ACL֧�֡�
HAProxy�ǽ�������ϵͳ�ļ���������ʵ��������󻯵ģ����Ҫ�뷢��HAProxy�����������Ҫ�Բ���ϵͳ���ܽ����Ż���
HAProxy�dz���������Щ�������ر������Ҫ�־����ӻ��IJ���߲㴦����Ƶ�webϵͳ�������Ż���վ�����������վ�ȡ�
HAProxyҲ��������MySQL���ݿ⣨���������ĸ��ؾ��⡣
HAProxy�Ĺٷ��ĵ���ַ��
http://cbonte.github.io/haproxy-dconv/

1.��װ����

�����⼸��haproxy �����ص��� ���Ծ���51CTO�������˸���

yum -y install gcc 
[root@zyz_dba_test04 ~]# tar -xf haproxy-1.4.25 -C /usr/local/
[root@zyz_dba_test04 ~]# cd /usr/local/haproxy/
[root@zyz_dba_test04 haproxy]# useradd haproxy
[root@zyz_dba_test04 haproxy]# make TARGET=linux26 PREFIX=/usr/local/haproxy
[root@zyz_dba_test04 haproxy]# make install PREFIX=/usr/local/haproxy 
[root@zyz_dba_test04 haproxy]# mkdir /usr/local/haproxy/logs/ -p && mkdir /usr/local/haproxy/var/run/ -p && mkdir /usr/local/haproxy/var/chroot/ -p && mkdir /usr/local/haproxy/conf/ -p
[root@zyz_dba_test04 haproxy]#  cat  > /usr/local/haproxy/haproxy.cfg  << OO 
global
        log            127.0.0.1        local0
        log            127.0.0.1        local1 notice
        maxconn        94096
        user            haproxy      #�������е��û�
        group           haproxy      #���������
        nbproc          1
        pidfile         /usr/local/haproxy/var/run/haproxy1.pid

defaults
        log            global
        option         tcplog
        option         dontlognull
        retries         3
        option          redispatch
        maxconn         94096
        timeout         connect  50000ms
        timeout         client   50000ms
        timeout         server   50000ms

listen  mariadb-galera
        bind 10.21.3.109:3399  #�ͻ��˼����˿�
        mode tcp
        balance  leastconn  #�������ӵĸ��ؾ����㷨
        server   db1  10.21.3.106:3306 check
        server   db2  10.21.3.107:3306 check
        server   db3  10.21.3.108:3306 check
OO


����ҳ����

global
        log 127.0.0.1 local0 info #[err warning info debug]
        maxconn 40960
        user    haproxy
        group   haproxy
        daemon
        nbproc 3
        chroot  /usr/local/haproxy/var/chroot
        pidfile /usr/local/haproxy/var/run/haproxy.pid


defaults
        log            global
        option         tcplog
        option         dontlognull
        retries         3
        option          redispatch
        maxconn         94096
        timeout         connect  50000ms
        timeout         client   50000ms
        timeout         server   50000ms
        timeout check 2000

listen admin_stats
        bind 0.0.0.0:1080
        mode http
        log 127.0.0.1 local0 err #[err warning info debug]
        stats refresh 3s
        stats uri /admin?stats
        stats realm Gemini\ Haproxy
        stats auth admin:admin
        stats auth admin1:admin1


listen  mariadb-galera
        bind 10.1.166.45:3399  #�ͻ��˼����˿�
        mode tcp
        balance  leastconn  #�������ӵĸ��ؾ����㷨
        server   db1  10.1.166.45:3306 check
        server   db2  10.1.166.46:3306 check
        server   db3  10.1.166.47:3306 check
        server   db4  10.1.166.48:3306 check
        server   db5  10.1.166.49:3306 check

��nbproc�����������1��������
������������
1��/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
[WARNING] 217/202150 (2857) : Proxy ��chinaapp.sinaapp.com��: in multi-process mode, stats will be limited to process assigned to the current request.
����ʾ������Ϣ��nbproc�����������Ϊ1�򲻻���ʾ�������ȥ�������ʾ�����޸ı����ļ����ɡ� ��Դ������src/cfgparse.c�ҵ�������
if (nbproc > 1) {
if (curproxy->uri_auth) {

  • Warning(��Proxy ��%s��: in multi-process mode, stats will be limited to process assigned to the current request.\n��,
  • Warning(��Proxy ��%s��: in multi-process mode, stats will be limited to the process assigned to the current request.\n��,
    ����nbproc > 1��ֵ���ɡ�
    Ȼ�������ҵ�ʵ��о���û��ʲô���� ��˻�����listen admin_stats����
    ���Ͽ���

2.��������
[root@zyz_dba_test04 ~]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg &
�Ҽ�Ⱥ��һ̨��Ȩ

MariaDB [(none)]> grant all privileges on *.* to zuo@'%' identified by '123';
Query OK, 0 rows affected (0.00 sec)
[root@zyz_dba_test04 haproxy]# mysql -h 10.21.3.109  -uzuo -p123  --port 3399
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.0.17-MariaDB-wsrep-log MariaDB Server, wsrep_25.10.r4144

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

3.�˴�Ҳ���Խ�haproxy д�����

cat > /etc/init.d/haproxyd <<OO
#!/bin/bash
#chkconfig: 35 35 -
. /etc/init.d/functions
BASE="/usr/local/haproxy"
 
PROG=$BASE/sbin/haproxy
PIDFILE=$BASE/var/run/haproxy.pid
CONFFILE=$BASE/conf/haproxy.conf
 
case "$1" in
start)
         #$PROG  -f $CONFFILE >/dev/null 2>&1
         $PROG  -f $CONFFILE
       [ $?  -eq 0 ] && {
        action  "haproxy start is  OK..."  /bin/true
 } || action  "haproxy start is error..." /bin/false
         ;;
status)
         if [ !  -f $PIDFILE ]; then
                   echo  "pid not found"
                   exit  1
         fi
         for  pid in $(cat $PIDFILE); do
                   kill  -0 $pid
                   RETVAL="$?"
                   if  [ ! "$RETVAL" = "0" ]; then
                            echo  "process $pid died"
                            exit  1
                   fi
         done
         echo  "process is running"
         ;;
restart)
         kill  $(cat $PIDFILE)
        [ $? -eq 0 ] && {
        action  "haproxy stop is  OK..."  /bin/true
 } || action  "haproxy stop is error..." /bin/false
         #$PROG  -f $CONFFILE -sf $(cat $PIDFILE) >/dev/null 2>&1
         $PROG  -f $CONFFILE 
        [ $?  -eq 0 ] && {
        action  "haproxy start is  OK..."  /bin/true
 } || action  "haproxy start is error..." /bin/false
        ;;
stop)
         kill  $(cat $PIDFILE)
[ $? -eq 0 ] && {
        action  "haproxy stop is  OK..."  /bin/true
 } || action  "haproxy stop is error..." /bin/false
         ;;
*)
         echo  "USAGE: $0 start|restart|status|stop"
         exit 1
         ;;
esac
OO

chkconfig -add haproxy

ע��

��������´�
service haproxyd does not support chkconfig
���������
��/etc/init.d/haproxyd ������������䵽 #!/bin/bash֮������������ݣ�

chkconfig: 2345 10 90

description:haproxy

----����2345��Ĭ���������𣬼�����0-6��7������
----�ȼ�0��ʾ����ʾ�ػ�
----�ȼ�1��ʾ�����û�ģʽ
----�ȼ�2��ʾ�����������ӵĶ��û�������ģʽ
----�ȼ�3��ʾ�����������ӵĶ��û�������ģʽ
----�ȼ�4��ʾ��������
----�ȼ�5��ʾ����ͼ�ν���Ķ��û�ģʽ
----�ȼ�6��ʾ����������
----10���������ȼ���90��ͣ�����ȼ������ȼ���Χ��0-100������Խ�����ȼ�Խ�͡�
4.��־֧�ֹ������

vim /etc/rsyslog.conf

�����±�����
local0.* /usr/local/haproxy/logs/haproxy.log

������־����

/etc/init.d/rsyslog restart

MariaDB [(none)]>
��ʱ�Ѿ������ϼ�Ⱥ��
Ϊ��������ÿ�β�ѯ�Ƿ�ַ����ҽ�һ̨��Ⱥ����

[root@zyz_dba_test02 ~]# cat /etc/my.cnf 

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock


[mysqld]
port            = 3306
user=mariadb
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
datadir=/data/db

log-bin=mysql-bin
max_connections=2000

binlog_format = ROW

server-id       = 2

innodb_autoinc_lock_mode = 2

#wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so

#wsrep_cluster_name = "my_mariadb_cluster"

#wsrep_cluster_address="gcomm://10.21.3.106,10.21.3.108"
#wsrep_cluster_name='example_cluster'

#wsrep_node_name = "cluster_node2"

#wsrep_node_address = 10.21.3.107:4406
#wsrep_sst_auth=tt:123
#wsrep_node_name='node2'
#wsrep_sst_method=rsync

ע�͵�107�ļ�Ⱥ
����107�����ݿ�

[root@zyz_dba_test02 ~]# service  mysqld restart
Shutting down MySQL..
MariaDB [(none)]> drop database zyy;
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| haha               |
| information_schema |
| mysql              |
| performance_schema |
| sbtest             |
| test               |
+--------------------+
6 rows in set (0.01 sec)
��108��106�����ݿ⼯Ⱥ���������������
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| haha               |
| information_schema |
| mysql              |
| performance_schema |
| sbtest             |
| test               |
| zyz                |
+--------------------+
7 rows in set (0.00 sec)

��½109 Ҳ����haproxy ��̨������
�鿴����

[root@zyz_dba_test04 haproxy]# mysql -h 10.21.3.109  -uzuo -p123  --port 3399 -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| haha               |
| information_schema |
| mysql              |
| performance_schema |
| sbtest             |
| test               |
| zyz                |
+--------------------+
[root@zyz_dba_test04 haproxy]# mysql -h 10.21.3.109  -uzuo -p123  --port 3399 -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| haha               |
| information_schema |
| mysql              |
| performance_schema |
| sbtest             |
| test               |
| zyz                |
+--------------------+
[root@zyz_dba_test04 haproxy]# mysql -h 10.21.3.109  -uzuo -p123  --port 3399 -e "show databases;"
+--------------------+
| Database           |
+--------------------+
| haha               |
| information_schema |
| mysql              |
| performance_schema |
| sbtest             |
| test               |
+--------------------+

���������һ�β�ѯ����û��zyz˵������ѯ�IJ�ѯ��
4.ѹ�����ԱȽ�
1.�����ڼ�Ⱥ�е�ijһ̨��ѹ��

[root@zyz_dba_test03 ~]#  sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=9 --oltp-table-size=10 --rand-init=on --num-threads=12  --oltp-read-only=off --report-interval=1 --rand-type=gaussian --max-time=3000 --max-requests=0 --mysql-host=10.21.3.108 --mysql-port=3306 --mysql-user=zuo --mysql-password=123 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 12
Report intermediate results every 1 second(s)
Initializing random number generator from timer.

Random number generator seed is 0 and will be ignored


Threads started!

[   1s] threads: 12, tps: 43.16, reads/s: 721.72, writes/s: 185.70, response time: 376.98ms (95%)
[   2s] threads: 12, tps: 52.09, reads/s: 721.26, writes/s: 201.35, response time: 375.85ms (95%)
[   3s] threads: 12, tps: 48.00, reads/s: 681.00, writes/s: 194.00, response time: 328.68ms (95%)
[   4s] threads: 12, tps: 49.00, reads/s: 694.00, writes/s: 198.00, response time: 304.16ms (95%)
[   5s] threads: 12, tps: 53.00, reads/s: 717.01, writes/s: 206.00, response time: 398.44ms (95%)
[   6s] threads: 12, tps: 50.00, reads/s: 714.00, writes/s: 198.00, response time: 348.65ms (95%)
[   7s] threads: 12, tps: 48.00, reads/s: 688.00, writes/s: 200.00, response time: 360.53ms (95%)
[   8s] threads: 12, tps: 35.00, reads/s: 503.00, writes/s: 141.00, response time: 563.18ms (95%)
[   9s] threads: 12, tps: 40.00, reads/s: 597.95, writes/s: 181.99, response time: 404.09ms (95%)
[  10s] threads: 12, tps: 44.93, reads/s: 600.01, writes/s: 158.74, response time: 501.13ms (95%)
[  11s] threads: 12, tps: 52.09, reads/s: 716.23, writes/s: 207.35, response time: 312.56ms (95%)
[  12s] threads: 12, tps: 47.00, reads/s: 694.00, writes/s: 207.00, response time: 380.26ms (95%)
[  13s] threads: 12, tps: 48.00, reads/s: 633.01, writes/s: 166.00, response time: 401.20ms (95%)
[  14s] threads: 12, tps: 43.00, reads/s: 639.99, writes/s: 185.00, response time: 309.77ms (95%)
[  15s] threads: 12, tps: 51.00, reads/s: 670.02, writes/s: 193.01, response time: 401.92ms (95%)
[  16s] threads: 12, tps: 51.00, reads/s: 717.00, writes/s: 204.00, response time: 286.23ms (95%)

2.�ڲ�haproxy �ڲ��Ե�ʱ����3̨��Ⱥ�϶��鿴��cpu ѹ��

[root@zyz_dba_test03 ~]#  sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=9 --oltp-table-size=10 --rand-init=on --num-threads=12  --oltp-read-only=off --report-interval=1 --rand-type=gaussian --max-time=3000 --max-requests=0 --mysql-host=10.21.3.109 --mysql-port=3399 --mysql-user=zuo --mysql-password=123 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 12
Report intermediate results every 1 second(s)
Initializing random number generator from timer.

Random number generator seed is 0 and will be ignored


Threads started!

[   1s] threads: 12, tps: 108.05, reads/s: 1652.80, writes/s: 450.22, response time: 253.10ms (95%)
[   2s] threads: 12, tps: 126.00, reads/s: 1765.04, writes/s: 514.01, response time: 237.11ms (95%)
[   3s] threads: 12, tps: 92.00, reads/s: 1249.98, writes/s: 346.99, response time: 361.18ms (95%)
[   4s] threads: 12, tps: 146.00, reads/s: 2063.02, writes/s: 592.01, response time: 125.40ms (95%)
[   5s] threads: 12, tps: 135.98, reads/s: 1893.73, writes/s: 551.92, response time: 231.91ms (95%)
[   6s] threads: 12, tps: 105.01, reads/s: 1484.15, writes/s: 410.04, response time: 246.15ms (95%)
[   7s] threads: 12, tps: 132.00, reads/s: 1831.06, writes/s: 521.02, response time: 256.91ms (95%)
[   8s] threads: 12, tps: 133.00, reads/s: 1886.02, writes/s: 537.01, response time: 131.00ms (95%)
[   9s] threads: 12, tps: 89.99, reads/s: 1285.91, writes/s: 387.97, response time: 267.43ms (95%)
[  10s] threads: 12, tps: 116.01, reads/s: 1584.11, writes/s: 438.03, response time: 626.89ms (95%)
[  11s] threads: 12, tps: 139.00, reads/s: 1942.99, writes/s: 551.00, response time: 159.86ms (95%)
[  12s] threads: 12, tps: 115.00, reads/s: 1629.96, writes/s: 468.99, response time: 213.65ms (95%)
[  13s] threads: 12, tps: 140.00, reads/s: 1950.05, writes/s: 550.01, response time: 179.98ms (95%)
[  14s] threads: 12, tps: 122.99, reads/s: 1739.85, writes/s: 502.96, response time: 241.77ms (95%)
[  15s] threads: 12, tps: 126.01, reads/s: 1689.14, writes/s: 488.04, response time: 271.87ms (95%)
[  16s] threads: 12, tps: 148.00, reads/s: 2107.01, writes/s: 600.00, response time: 110.75ms (95%)
[  17s] threads: 12, tps: 139.00, reads/s: 1971.95, writes/s: 569.99, response time: 111.05ms (95%)

������haproxy������tps�Ͷ�д���������������õ��˼�Ⱥ

3.Keepalive
���������Ǹ�haproxy��һ���߿��÷�ֹhaproxy�ҵ���

Ȼ�����ڸ�ÿһ̨mariadb ����mycat ��ô���Ǹ��ؾ������·����
�ٸ�ÿһ̨��mariadb ���ɵ�mycat���ɸ߿���
���˻������

��.MySQL+galera+haproxy+keepalived
��վhttp://galeracluster.com/
1.����
1.GALERA��Ⱥ�ĺô�
Galera��ȺΪMySQL��̬ϵͳ�ṩ��һ���߿����������Եĸ��ơ� ʵ�ָ߿����Եĸ��ַ���ͨ��ֻ�ṩ��һЩ���Կ���ͨ��Galera��Ⱥ,ʹѡ��߿����Խ��������һ��Ȩ�⡣
ͨ��Galera��Ⱥ������������:
? �����Ķ����� ����д�κνڵ����κ�ʱ��
? ͬ������ û��slave�ͺ�,û�����ݶ�ʧ�ڽڵ������
? ����ϵ� ���нڵ�ӵ����ͬ��״̬�� ������ͬ�ڵ�֮������ݡ�
? ���̵߳�slave ��ø��õ����ܡ� �����κι������ء�
? û��vip�����ӹ���ת�Ʋ�����ʹ�á�No Master-Slave Failover(ʧЧ��Ԯ) Operations or Use of VIP
? �ȱ��� ����ת���ڼ�û��ͣ��ʱ��(��Ϊû�й���ת��)��
? �Զ��ڵ����� ����Ҫ�ֶ��������ݿⲢ���临�Ƶ��½ڵ㡣
? ֧��InnoDB��
? ͸����Ӧ�ó��� ����Ҫ(�����)����)Ӧ�ó���
? ����Ҫ����д�ķ��롣
�����һ���߿����Խ������,�Ƚ�׳�����������Ժ͸������뼴ʱ����ת�ơ�

2.��װmysql��Ⱥ
IP��������������ͬ�ر�selinux iptables
����
iptables --append INPUT --protocol tcp \ --source 10.21.3.106 --jump ACCEPT

iptables --apend INPUT --protocol tcp \ --source 10.21.3.107 --jump ACCEPT

iptables --append INPUT --protocol tcp \ --source 10.21.3.108--jump ACCEPT

Service save iptables

iptables-save > /etc/sysconfig/iptables

106 107 108��ִ�����°�װ���������ļ�Ϊ106��������106 Ϊnode1
yum -y install nmap
yum -y install perl-DBD-MySQL perl-Time-HiRes nc  install boost-program-options
 
rpm -ivh   percona-xtrabackup-2.1.8-733.rhel6.x86_64*.rpm
rpm -ivh galera-3-25.3.10-2.el6.x86_64.rpm 
tar -xf mysql-wsrep-5.6.23-25.10-linux-x86_64.tar.gz -C /usr/local/services/
cd /usr/local/services/
 mv mysql-wsrep-5.6.23-25.10-linux-x86_64/ mysql/
chown mysql. /data/db -R
[root@zyz_dba_test01 services]# cd mysql/
[root@zyz_dba_test01 mysql]#  ./scripts/mysql_install_db  --datadir=/data/db/ --basedir=/usr/local/services/mysql/ --user=mysql
yum remove postfix
 yum install postfix

cat  > /usr/local/mysql/my1.cnf  <<OO
[client]
port            = 3306
socket          = /tmp/mysql.sock
[mysqld]
port            = 3306
basedir=//usr/local/services/mysql
datadir=/data/db
user=mysql
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
log-bin=mysql-bin
binlog_format = ROW
server-id       = 1
innodb_autoinc_lock_mode = 2
wsrep_provider = /usr/local/services/mysql/lib/libgalera_smm.so
wsrep_cluster_name = "my_mariadb_cluster"
wsrep_cluster_address="gcomm://"
wsrep_cluster_name='example_cluster'
wsrep_node_name = "cluster_node1"

wsrep_node_address = 10.21.3.106:4406
wsrep_sst_auth=tt:123
wsrep_node_name='node1'
wsrep_sst_method=rsync

[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
OO


ln -sf /usr/lib64/galera-3/libgalera_smm.so /usr/local/services/mysql/lib/
ln -sf /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6
ln -sf /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6

 ./mysqld --defaults-file=/usr/local/services/mysql/my1.cnf --wsrep-new-cluster &

node2 node3 ������noede1�������ļ���ͬ����ֱ��service mysqld start��ʽ���� ��������һ��
��Ȼ�����Ұ�λ�û���/usr/local/services/mysql ��Ŀ�ľ��ǿ����е��˻���λ���Dz��ǾͲ�����

���˰�װ���

3.������̨��Լ�İ�װ����

tar -xf mysql-wsrep-5.6.23-25.10-linux-x86_64.tar.gz -C /usr/local/
yum -y install nmap
yum -y install perl-DBD-MySQL perl-Time-HiRes nc  install boost-program-options
cd /usr/local/mysql
cd scripts/
./mysql_install_db --datadir=/data/db/ --basedir=/usr/local/mysql/ --user=mysql
 rpm -ivh galera-3-25.3.10-2.el6.x86_64.rpm 
ln -sf /usr/lib64/galera-3/libgalera_smm.so /usr/local/mysql/lib/
ln -sf /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6
  ln -sf /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6

107(node2)��
cat > /etc/my.cnf << FF
# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock
[mysqld]
port            = 3306
user=mysql
datadir=/data/db
basedir=/usr/local/mysql
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
datadir=/data/db
log-bin=mysql-bin
max_connections=2000
binlog_format = ROW
server-id       = 2
innodb_autoinc_lock_mode = 2
wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_name = "my_mariadb_cluster"
wsrep_cluster_address="gcomm://10.21.3.106,10.21.3.108"
wsrep_cluster_name='example_cluster'
wsrep_node_name = "cluster_node2"
wsrep_node_address = 10.21.3.107:4406
wsrep_sst_auth=tt:123
wsrep_node_name='node2'
wsrep_sst_method=rsync

[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
FF


108��node3�ϣ�

cat > /etc/my.cnf << PP
# The follo#wing options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mysql.sock
[mysqld]
port            = 3306
user=mysql
datadir=/data/db
basedir=/usr/local/mysql
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
datadir=/data/db
 max_connections=10000 
log-bin=mysql-bin
binlog_format = ROW
server-id       = 3
innodb_autoinc_lock_mode = 2
wsrep_provider = /usr/local/mysql/lib/libgalera_smm.so
wsrep_cluster_name = "my_mariadb_cluster"
wsrep_cluster_address="gcomm://10.21.3.106,10.21.3.107"
wsrep_cluster_name='example_cluster'
wsrep_node_name = "cluster_node3"
wsrep_node_address = 10.21.3.108:4406
wsrep_sst_auth=tt:123
wsrep_node_name='node3'
wsrep_sst_method=rsync
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
PP

��service mysqld start ����
4.��װhaproxy
���������haproxy��װ������
5.sysbench ѹ��

[root@zyz_dba_test03 ~]# sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=9 --oltp-table-size=100000 --rand-init=on --num-threads=10  --oltp-read-only=off --report-interval=1 --rand-type=gaussian --max-time=60 --max-requests=0 --mysql-host=10.21.3.109 --mysql-port=3399 --mysql-user=zuo --mysql-password=123 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 10
Report intermediate results every 1 second(s)
Initializing random number generator from timer.

Random number generator seed is 0 and will be ignored


Threads started!

[   1s] threads: 10, tps: 0.00, reads/s: 140.15, writes/s: 24.03, response time: 0.00ms (95%)
[   2s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[   3s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[   4s] threads: 10, tps: 41.00, reads/s: 684.03, writes/s: 199.01, response time: 3345.15ms (95%)
[   5s] threads: 10, tps: 101.01, reads/s: 1525.09, writes/s: 414.02, response time: 425.57ms (95%)
[   6s] threads: 10, tps: 118.99, reads/s: 1866.91, writes/s: 510.98, response time: 224.47ms (95%)
[   7s] threads: 10, tps: 101.00, reads/s: 1605.98, writes/s: 444.99, response time: 209.35ms (95%)
[   8s] threads: 10, tps: 124.99, reads/s: 1941.91, writes/s: 520.97, response time: 246.74ms (95%)
[   9s] threads: 10, tps: 91.00, reads/s: 1503.08, writes/s: 422.02, response time: 328.29ms (95%)
[  10s] threads: 10, tps: 128.00, reads/s: 2021.01, writes/s: 539.00, response time: 133.14ms (95%)
[  11s] threads: 10, tps: 57.00, reads/s: 849.94, writes/s: 252.98, response time: 446.58ms (95%)
[  12s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  13s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  14s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  15s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  16s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  17s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  18s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  19s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  20s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  21s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  22s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)
[  23s] threads: 10, tps: 0.00, reads/s: 0.00, writes/s: 0.00, response time: 0.00ms (95%)

����û ��������Խ��˭������mysql װmariadb��Ⱥ���ֱ������ʧ��

��.Percona XtraDB Cluster
1.��װ����
������������Ļ���
106 node1
107 node2
108 node3
109 haproxy
�����3307�˿�
��������percona��Ⱥ���

useradd mysql
mkdir /opt/data
chown mysql. /opt/data
chown 777 /opt
chown mysql. /opt
 tar -xf /opt/Percona-XtraDB-Cluster-5.6.24-rel72.2-25.11..Linux.x86_64.tar.gz 
mv /opt/Percona-XtraDB-Cluster-5.6.24-rel72.2-25.11..Linux.x86_64 /opt/percona
rpm -ivh Percona-XtraDB-Cluster-galera-3-3.11-1.rhel6.x86_64.rpm


[root@zyz_dba_test03 opt]# cat /etc/my.cnf 

# The follo#wing options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3307
socket          = /opt/mysql.sock


[mysqld]
port            = 3307
user=mysql
datadir=/opt/data
basedir=/opt/percona
socket          = /opt/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
 max_connections=10000 
log-bin=mysql-bin
binlog_format = ROW
server-id       = 3
innodb_autoinc_lock_mode = 2
wsrep_provider = /usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_name = "my_mariadb_cluster"
wsrep_cluster_address="gcomm://10.21.3.106,10.21.3.107"
wsrep_cluster_name='example_cluster'
wsrep_node_name = "cluster_node3"
wsrep_node_address = 10.21.3.108:4406 #д�Լ���IP
wsrep_sst_auth=tt:123
wsrep_node_name='node3'
wsrep_sst_method=rsync
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout

��̨���������������õ�

106 
wsrep_cluster_address="gcomm://"

�����ͬ����δ���ɫ�Ķ�һ��
����node1��node3��˳������

Node1:
/opt/percona/bin/mysqld --defaults-file=/opt/my.cnf --wsrep-new-cluster
Node2 Node3:
cp /opt/percona/support-files/mysql.server  /etc/init.d/percona
vi /etc/init.d/percona
�ҵ�basedir��datadir�ij�����
basedir=/opt/percona
datadir=/opt/data

2.��haproxy
����������Ʒ�ʽһ��
3.ѹ������
֮���һ��ӹ�ֻҪ����ij�Ա��mysql tps����0�ij���

 


    response time:
         min:                                226.48ms
         avg:                               1265.01ms
         max:                               9628.06ms
         approx.  95 percentile:            3422.12ms

Threads fairness:
    events (avg/stddev):           47.7656/7.15
    execution time (avg/stddev):   60.4241/0.28
RECORD LOCKS space id 26 page no 7 n bits 144 index `GEN_CLUST_INDEX` of table `sbtest`.`sbtest9` trx id 166278 lock_mode X locks rec but not gap

��106�Ƕ˳��ִ��������X����Ϣ
ȫ�ֶ���percona cluster��Ա��ѹ��
���ش�Լ��1.5���ҵ������

[root@zyz_dba_test03 ~]# sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=9 --oltp-table-size=10 --rand-init=on --num-threads=12  --oltp-read-only=off --report-interval=1 --rand-type=gaussian --max-time=3000 --max-requests=0 --mysql-host=10.21.3.109 --mysql-port=3399 --mysql-user=zuo --mysql-password=123 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 12
Report intermediate results every 1 second(s)
Initializing random number generator from timer.

Random number generator seed is 0 and will be ignored


Threads started!

[   1s] threads: 12, tps: 77.96, reads/s: 1175.45, writes/s: 315.88, response time: 499.33ms (95%)
[   2s] threads: 12, tps: 128.00, reads/s: 1843.01, writes/s: 522.00, response time: 123.21ms (95%)
[   3s] threads: 12, tps: 114.00, reads/s: 1584.98, writes/s: 455.99, response time: 235.69ms (95%)
[   4s] threads: 12, tps: 127.85, reads/s: 1796.83, writes/s: 510.38, response time: 117.66ms (95%)
[   5s] threads: 12, tps: 128.16, reads/s: 1755.14, writes/s: 511.62, response time: 136.57ms (95%)
[   6s] threads: 12, tps: 131.00, reads/s: 1870.00, writes/s: 526.00, response time: 114.94ms (95%)
[   7s] threads: 12, tps: 123.00, reads/s: 1722.00, writes/s: 486.00, response time: 178.42ms (95%)
[   8s] threads: 12, tps: 121.00, reads/s: 1687.01, writes/s: 479.00, response time: 159.86ms (95%)
[   9s] threads: 12, tps: 132.00, reads/s: 1860.99, writes/s: 526.00, response time: 114.49ms (95%)
[  10s] threads: 12, tps: 127.00, reads/s: 1764.00, writes/s: 512.00, response time: 139.46ms (95%)
[  11s] threads: 12, tps: 104.00, reads/s: 1458.99, writes/s: 432.00, response time: 132.42ms (95%)
[  12s] threads: 12, tps: 97.00, reads/s: 1399.99, writes/s: 390.00, response time: 328.78ms (95%)
[  13s] threads: 12, tps: 107.00, reads/s: 1459.03, writes/s: 420.01, response time: 143.78ms (95%)
[  14s] threads: 12, tps: 102.80, reads/s: 1417.27, writes/s: 403.22, response time: 134.78ms (95%)
[  15s] threads: 12, tps: 93.17, reads/s: 1345.47, writes/s: 373.69, response time: 387.39ms (95%)
[  16s] threads: 12, tps: 118.01, reads/s: 1597.14, writes/s: 471.04, response time: 208.28ms (95%)
[  17s] threads: 12, tps: 128.00, reads/s: 1820.00, writes/s: 508.00, response time: 110.98ms (95%)
[  18s] threads: 12, tps: 121.00, reads/s: 1716.99, writes/s: 486.00, response time: 147.89ms (95%)
[  19s] threads: 12, tps: 109.00, reads/s: 1514.02, writes/s: 438.00, response time: 159.00ms (95%)
[  20s] threads: 12, tps: 127.00, reads/s: 1752.99, writes/s: 505.00, response time: 133.38ms (95%)
[  21s] threads: 12, tps: 126.00, reads/s: 1787.01, writes/s: 514.00, response time: 120.00ms (95%)
[  22s] threads: 12, tps: 132.00, reads/s: 1843.00, writes/s: 521.00, response time: 112.32ms (95%)
[  23s] threads: 12, tps: 126.00, reads/s: 1773.98, writes/s: 509.00, response time: 120.40ms (95%)
[  24s] threads: 12, tps: 126.00, reads/s: 1776.00, writes/s: 504.00, response time: 120.00ms (95%)
[  25s] threads: 12, tps: 71.00, reads/s: 999.94, writes/s: 299.98, response time: 129.95ms (95%)
[  26s] threads: 12, tps: 85.00, reads/s: 1190.03, writes/s: 327.01, response time: 907.28ms (95%)
[  27s] threads: 12, tps: 110.99, reads/s: 1540.87, writes/s: 455.96, response time: 206.11ms (95%)
[  28s] threads: 12, tps: 127.01, reads/s: 1740.19, writes/s: 487.05, response time: 140.26ms (95%)
[  29s] threads: 12, tps: 126.00, reads/s: 1789.04, writes/s: 507.01, response time: 113.50ms (95%)
[  30s] threads: 12, tps: 129.00, reads/s: 1789.00, writes/s: 519.00, response time: 108.88ms (95%)
[  31s] threads: 12, tps: 113.00, reads/s: 1603.96, writes/s: 453.99, response time: 172.02ms (95%)
[  32s] threads: 12, tps: 129.00, reads/s: 1804.02, writes/s: 510.01, response time: 112.02ms (95%)
[  33s] threads: 12, tps: 124.00, reads/s: 1729.00, writes/s: 504.00, response time: 127.48ms (95%)
[  34s] threads: 12, tps: 93.00, reads/s: 1335.96, writes/s: 383.99, response time: 195.59ms (95%)
[  35s] threads: 12, tps: 89.00, reads/s: 1192.96, writes/s: 331.99, response time: 543.15ms (95%)
[  36s] threads: 12, tps: 110.01, reads/s: 1555.11, writes/s: 454.03, response time: 152.34ms (95%)
[  37s] threads: 12, tps: 102.99, reads/s: 1440.91, writes/s: 411.97, response time: 177.51ms (95%)
[  38s] threads: 12, tps: 126.00, reads/s: 1767.07, writes/s: 496.02, response time: 127.75ms (95%)
[  39s] threads: 12, tps: 123.99, reads/s: 1764.83, writes/s: 501.95, response time: 119.79ms (95%)
[  40s] threads: 12, tps: 99.01, reads/s: 1388.17, writes/s: 406.05, response time: 331.84ms (95%)
[  41s] threads: 12, tps: 78.00, reads/s: 1092.00, writes/s: 312.00, response time: 502.63ms (95%)
[  42s] threads: 12, tps: 88.00, reads/s: 1241.99, writes/s: 351.00, response time: 408.10ms (95%)
[  43s] threads: 12, tps: 76.00, reads/s: 1031.00, writes/s: 298.00, response time: 483.16ms (95%)
[  44s] threads: 12, tps: 123.99, reads/s: 1741.93, writes/s: 494.98, response time: 118.08ms (95%)
[  45s] threads: 12, tps: 94.00, reads/s: 1287.03, writes/s: 362.01, response time: 385.42ms (95%)
[  46s] threads: 12, tps: 111.00, reads/s: 1560.04, writes/s: 451.01, response time: 153.16ms (95%)
[  47s] threads: 12, tps: 128.00, reads/s: 1800.99, writes/s: 508.00, response time: 118.79ms (95%)
[  48s] threads: 12, tps: 125.73, reads/s: 1780.13, writes/s: 503.90, response time: 119.93ms (95%)
[  49s] threads: 12, tps: 123.27, reads/s: 1721.74, writes/s: 496.08, response time: 126.08ms (95%)
[  50s] threads: 12, tps: 124.99, reads/s: 1739.92, writes/s: 501.98, response time: 119.43ms (95%)
[  51s] threads: 12, tps: 120.00, reads/s: 1676.05, writes/s: 485.01, response time: 133.10ms (95%)
[  52s] threads: 12, tps: 122.00, reads/s: 1738.03, writes/s: 489.01, response time: 132.34ms (95%)
[  53s] threads: 12, tps: 122.00, reads/s: 1659.00, writes/s: 471.00, response time: 143.61ms (95%)
[  54s] threads: 12, tps: 120.00, reads/s: 1685.00, writes/s: 487.00, response time: 138.75ms (95%)

�����߳�ѹ�� �����Ѿ������18���������

[root@zyz_dba_test03 ~]# sysbench --test=/usr/share/doc/sysbench/tests/db/oltp.lua --oltp_tables_count=9 --oltp-table-size=10 --rand-init=on --num-threads=64  --oltp-read-only=off --report-interval=1 --rand-type=gaussian --max-time=3000 --max-requests=0 --mysql-host=10.21.3.109 --mysql-port=3399 --mysql-user=zuo --mysql-password=123 run
sysbench 0.5:  multi-threaded system evaluation benchmark

Running the test with following options:
Number of threads: 64
Report intermediate results every 1 second(s)
Initializing random number generator from timer.

Random number generator seed is 0 and will be ignored


Threads started!

[   1s] threads: 64, tps: 84.58, reads/s: 1846.37, writes/s: 365.15, response time: 826.38ms (95%)
[   2s] threads: 64, tps: 122.04, reads/s: 1594.50, writes/s: 474.15, response time: 765.42ms (95%)
[   3s] threads: 64, tps: 124.00, reads/s: 1841.01, writes/s: 515.00, response time: 627.45ms (95%)
[   4s] threads: 64, tps: 135.00, reads/s: 1770.00, writes/s: 525.00, response time: 661.59ms (95%)
[   5s] threads: 64, tps: 125.00, reads/s: 1806.99, writes/s: 508.00, response time: 635.77ms (95%)
[   6s] threads: 64, tps: 131.99, reads/s: 1803.91, writes/s: 520.97, response time: 584.48ms (95%)
[   7s] threads: 64, tps: 106.00, reads/s: 1632.03, writes/s: 465.01, response time: 972.81ms (95%)
[   8s] threads: 64, tps: 26.00, reads/s: 585.97, writes/s: 149.99, response time: 1192.42ms (95%)
[   9s] threads: 64, tps: 130.00, reads/s: 1585.96, writes/s: 439.99, response time: 1562.04ms (95%)
[  10s] threads: 64, tps: 117.01, reads/s: 1715.17, writes/s: 507.05, response time: 671.36ms (95%)
[  11s] threads: 64, tps: 92.00, reads/s: 1141.00, writes/s: 314.00, response time: 1285.08ms (95%)
[  12s] threads: 64, tps: 126.00, reads/s: 1818.99, writes/s: 523.00, response time: 590.99ms (95%)
[  13s] threads: 64, tps: 125.00, reads/s: 1738.01, writes/s: 495.00, response time: 690.73ms (95%)
[  14s] threads: 64, tps: 131.00, reads/s: 1818.97, writes/s: 526.99, response time: 624.26ms (95%)

����������1 Ҳ����12�̵߳�ʱ��͸�����15��ʱ���tps�����ϲ��
�������mariadb ��mysql5.5�汾���Ӧ���ڸ���ʮ�ָߵ������ tps �ͻ������½�

�����mariadb ��û��5.6�汾���ֵ������ tps�ڸ��ز��ߵ�����±�perconaţ��
���Ǹ��ظߵ�����²���percona5.6.24�汾
��������߸��ѡ����percona ��Ⱥ

�ģ�Keepalived
1.�򵥽���
Keepalived������߿��ÿ��������Զ������棬ʹ��һ��vip��keepalived��װ���������ϵ�һ̨keepalived����ҵ��������vip����Ư�Ƶ�priority���ķ�������

2.��װ����

echo 'net.ipv4.ip_nonlocal_bind = 1'>>/etc/sysctl.conf
cd ~
wget http://www.keepalived.org/software/keepalived-1.2.9.tar.gz
tar  -xf keepalived-1.2.9.tar.gz 
mkdir /usr/local/keepalived 
cd ~/ keepalived-1.2.9
./configure  --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/
chmod +x /etc/init.d/keepalived
mkdir /etc/keepalived
cat /etc/keepalived/check_haproxy.sh  
#!/bin/bash
A=`ps -C haproxy --no-header |wc -l`
if [ $A -eq 0 ];then
/etc/init.d/haproxyd restart
echo "Start haproxy" &> /dev/null
sleep 3
if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
/etc/init.d/keepalived stop
echo "Stop keepalived" &> /dev/null
fi
fi

chmod +x /etc/keepalived/check_haproxy.sh

cat > /etc/keepalived/keepalived.conf << GG
global_defs {  
    notification_email {  
    zuoyuezong@163.com     
    }  
    notification_email_from zuoyuezong@163.com  
    smtp_server smtp.163.com   # �ʼ���������ַ  
    smtp_connect_timeout 30     # ���ӳ�ʱʱ��  
    router_id LVS_Master  
}  
vrrp_script chk_http_port {  
    script  "/etc/keepalived/check_haproxy.sh"    # haproxy���м��ű�[haproxy崵�����haproxy����]  
    interval        5                     # �ű�ִ�м��  
    weight         -5                    # ִ�нű������ȼ������5��ʾ���ȼ�+5;-5���ʾ���ȼ�-5  
}  
vrrp_instance VI_A {  
    state       BACKUP                    # ���ϴ�ֵΪMASTER,����ΪBACKUP  
    interface   eth0  
    virtual_router_id 50            # ��ֵ���ӱ���һ��  
    priority 80                    # ��ֵMASTER�ϱ�BACKUP �� 
    advert_int 1  
    authentication {                  # authentication��������ֵ,����Ҳ����һ��  
        auth_type PASS  
        auth_pass yiban
    }  
track_script {  
    chk_http_port  
    }  
    virtual_ipaddress {  
        10.21.82.41              # haproxy�ṩ������IP��ַ  
    }  
}
GG


MASTER��keepalived����
cat keepalived.conf
global_defs {  
    notification_email {  
 zuoyuezong@163.com
    }  
    notification_email_from zuoyuezong@163.com
    smtp_server smtp.163.com   # �ʼ���������ַ  
    smtp_connect_timeout 30     # ���ӳ�ʱʱ��  
    router_id LVS_Master  
}  
vrrp_script chk_http_port {  
    script  "/etc/keepalived/check_haproxy.sh"    # haproxy���м��ű�[haproxy崵�����haproxy����]  
    interval        5                     # �ű�ִ�м��  
    weight         -5                    # ִ�нű������ȼ������5��ʾ���ȼ�+5;-5���ʾ���ȼ�-5  
}  
vrrp_instance VI_A {  
    state MASTER                    # ���ϴ�ֵΪMASTER,����ΪBACKUP  
    interface eth0  
    virtual_router_id 50            # ��ֵ���ӱ���һ��  
    priority 100  
    advert_int 1  
    authentication {                  # authentication��������ֵ,����Ҳ����һ��  
        auth_type PASS  
    auth_pass yiban  
    }  
track_script {  
    chk_http_port  
    }  
    virtual_ipaddress {  
          10.21.82.41      
    }  
}  
0

评论区