> 데이터 베이스 > MySQL 튜토리얼 > 编译安装MySQL实现corosync+pacemaker+drbd+mysql高可用

编译安装MySQL实现corosync+pacemaker+drbd+mysql高可用

WBOY
풀어 주다: 2016-06-07 14:55:46
원래의
1384명이 탐색했습니다.

编译安装MySQL实现corosync+pacemaker+drbd+mysql高可用 实验拓扑图: 实验节点:节点一: IP : 172.16.249.248 host: node1.stu11.com node1 节点二: IP : 172.16.249.122 host: node3.stu11.com node3 650) this.width=650;" src="http://www.68idc.cn/

                   编译安装MySQL实现corosync+pacemaker+drbd+mysql高可用 


实验拓扑图:

实验节点:节点一:IP172.16.249.248    host:  node1.stu11.com  node1 

           节点二:IP172.16.249.122    host: node3.stu11.com    node3   



wKiom1S58bCwx945AADEhiTB-SY859.jpg

    


 

节点二的配置前准备:

##########下载安装drbd,以及依赖的包########
[root@node3 ~ ]# rpm -ivh drbd84-utils-8.9.1-1.el6.elrepo.x86_64.rpm kmod-drbd84-8.4.5-504.1.el6.x86_64.rpm     
[root@node3 ~ ]# yum install corosync pacemaker -y ####安装corosync和pacemaker
[root@node3 .ssh ]#fdisk /dev/sda       ####创建用作drbd的磁盘,我这里使用分区模拟了
Command (m for help): n
Command action e  extended p  
primary partition (1-4) p
Partition number (1-4): 3
First cylinder (7859-15665, default 7859):
Using default value 7859
Last cylinder,
+cylinders or +size{K,M,G} (7859-15665, default 15665): +2G ##2G同步快一点,实际大小看生产需要
Command (m for help): w
[root@node3 .ssh ]#partx -a /dev/sda
로그인 후 복사

节点一配置:

[root@node1 ~ ]# rpm -ivh drbd84-utils-8.9.1-1.el6.elrepo.x86_64.rpm kmod-drbd84-8.4.5-504.1.e
[root@node1 ~ ]# yum install corosync pacemaker -y
[root@node1 ~ ]#fdisk /dev/sda
Command (m forhelp): n
Command action e  extended  p  
primary partition (1-4) p
Partition number(1-4): 3
First cylinder(7859-15665, default 7859):
Using default value7859
Last cylinder,
+cylinders or +size{K,M,G} (7859-15665, default 15665): +2G 
Command (m forhelp): w
[root@node1 ~ ]#partx -a /dev/sda
로그인 후 복사

##############################编辑corosync配置文件##############################

[root@node1 corosync]# cp corosync.conf.example corosync.conf
[root@node1 corosync]# vim corosync.conf    ##仅显示的是在使用的部分
  2 compatibility: whitetank
  3
  4 totem {
  5     version: 2
 10     secauth: on
 12     threads: 0
 17     interface {
 19         ringnumber: 0
 25         bindnetaddr: 172.16.0.0     
 39         mcastaddr: 239.22.11.123  ##指定组播地址
 44         mcastport: 5405
 49         ttl: 1
 50     }
 51 }
 53 logging {
 57     fileline: off
 60     to_stderr: no
 63     to_logfile: yes
 64    logfile: /var/log/cluster/corosync.log
 66     to_syslog: yes
 68     debug: off
 72     timestamp: on
 73    logger_subsys {
 74        subsys: AMF
 75        debug: off
 76     }
 77 }
 78 service {         ####将pacemaker以模块方式和corosync结合工作
 79    ver: 0
 80    name: pacemaker
 81 }
로그인 후 복사

##########################################生成密钥########################################

[root@node1 yum.repos.d ]# corosync-keygen
Writing corosync key
to /etc/corosync/authkey.
[root@node1 drbd.d]# ls
global_common.conf  global_common.conf.bak  mydisk.res
[root@node1 corosync]# ll
total 24
-r-------- 1 root
root  128 Jan 17 09:38 authkey    ###保证权限是600或400
-rw-r--r-- 1 root
root 2701 Jan 17 09:38 corosync.conf
[root@node1 corosync]# scp corosync.conf authkey node3:/etc/corosync/
corosync.conf                   100% 2701     2.6KB/s   00:00   
authkey                         100%  128     0.1KB/s  00:00 
[root@node3 corosync ]# ll    //查看各节点密钥文件权限都是600,默认是不需要修改的。
total 24
-r-------- 1 root
root  128 Jan 17 09:38 authkey
로그인 후 복사

############################配置各节点DRBD配置文件配置##############################################

[root@node1 drbd.d]# vim global_common.conf
  5 global {
  6    usage-count no;
  7     #minor-count dialog-refresh disable-ip-verification
  8 }
 10 common {
 11    handlers {
 17         pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh;/usr/lib/drbd/notify-emergency-reboot.sh; echo     b > /proc/sysrq-trigger ; reboot-f";
 18         pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh;/usr/lib/drbd/notify-emergency-reboot.sh; echo     b > /proc/sysrq-trigger ; reboot-f";
 19         local-io-error "/usr/lib/drbd/notify-io-error.sh;/usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc    /sysrq-trigger ; halt -f";
 25     }
 26
 27    startup {
 28        # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb
 29     }
 30
 31    options {
 32        # cpu-mask on-no-data-accessible
 33     }
 35     disk {
 36          on-io-error detach; ###磁盘故障直接拆除
 41     }
 42
 43    net {
 44         protocol C; ###最稳妥的协议
 45         cram-hmac-alg "sha1";
 46         shared-secret "test";
 54     }
 56 syncer {
 57    rate 100M;
 58
 59 }
 60 }    //一定要注意最后一个引号,是全局段的。
로그인 후 복사


##################################配值DRBD资源文件##################################################

 [root@node1 drbd.d ]#vim mydisk.res 
  1 resource mydisk {
  2    on node1.stu11.com {
  3        device /dev/drbd0;
  4        disk /dev/sda3;
  5        address 172.16.249.248:7789;
  6        meta-disk internal;
  7        }
  8        on node3.stu11.com {
  9        device /dev/drbd0;
 10        disk /dev/sda3;
 11        address 172.16.249.122:7789;
 12        meta-disk internal;
 13        }
 14 }
로그인 후 복사

#################################同步两个节点的配置文件###########################################

[root@node1 drbd.d]# scp global_common.conf mydisk.res node3:/etc/drbd.d/
global_common.conf                    100% 2101     2.1KB/s   00:00   
mydisk.res                            100%  257     0.3KB/s   00:00
로그인 후 복사

##################################各节点资源初始化#################################################

[root@node1 corosync]# drbdadm create-md mydisk
initializing
activity log
NOT initializing
bitmap
Writing meta data...
New drbd meta data
block successfully created.
로그인 후 복사
[root@node3 drbd.d]# drbdadm create-md mydisk
initializing
activity log
NOT initializing
bitmap
Writing meta data...
New drbd meta data
block successfully created.
[root@node3 corosync]# service drbd start
Starting DRBD
resources:
로그인 후 복사

##########################################启动各节点DRBD###########################################

[root@node1 corosync]# service drbd start
Starting DRBD
resources:
로그인 후 복사

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/1214304240-1.jpg" title="2.png" alt="wKiom1S5-P-yT5ifAADHFsB3Q2U098.jpg" />

[root@node1 corosync ]# drbd-overview //查看节点状态

0:mydisk/0 Connected Secondary/Secondary Inconsistent/Inconsistent

##########################提升一个节点为主节点:并且查看数据在同步######################################

[root@node1 corosync]# drbdadm primary --force mydisk
[root@node1 corosync]# drbd-overview
 0:mydisk/0 
SyncSource Primary/Secondary UpToDate/Inconsistent
[>...................]
sync'ed:  7.1% (1959028/2103412)K
로그인 후 복사

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/1214302564-2.jpg" title="3.png" alt="wKioL1S5-zLRwAzuAAGTM_9o4Nw385.jpg" />

##################################对DRBD格式化####################################################

[root@node1 corosync ]# mke2fs -t ext4 /dev/drbd0 //对主节点格式化

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/1214302602-3.jpg" title="4.png" alt="wKiom1S5-sOy7yq9AADDFnFRipc185.jpg" />

#####################################挂载创建测试文件############################################

[root@node1 corosync ]# mount /dev/drbd0 /mnt/  
[root@node1 corosync]# cd /mnt/
[root@node1 mnt ]#ls
lost+found
[root@node1 mnt ]#touch test.txt
[root@node1 mnt ]#ls
lost+found  test.txt
로그인 후 복사

##################### ##降为从节点把另一个节点升为主节点挂载查看测试文件########################

[root@node1 ~ ]# umount /mnt/     
[root@node1 ~ ]#drbd
drbdadm        drbdmeta       drbd-overview  drbdsetup     
[root@node1 ~ ]#drbdadm secondary mydisk
[root@node1 ~ ]#drbd-overview
 0:mydisk/0 
Connected Secondary/Secondary UpToDate/UpToDate
로그인 후 복사

#####################节点二升级主节点,查看测试文件#################################

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/1214305H8-4.jpg" title="5.png" alt="wKiom1S5-_ihLcNtAAEVRvGonog788.jpg" />

至此:两个节点的DRBD已经建成同步完成。开始布置两个节点的mysql

######################准备各节点的mysql############################################# 准备编译环境及安装:

[root@node3 /]# yum groupinstall "Development Tools" -y
[root@node3 /]# yum install "Server Platform Developmnet"
[root@node3 ~ ]# yum install cmake -y     //mariadb是使用cmake的编译安装的
[root@node3 ~ ]# tar xf mariadb-10.0.13.tar.gz -C /usr/local/
[root@node3 local ]#groupadd -g 306 mysql
[root@node3 local ]#useradd -u 306 -g 306 mysql
[root@node3 local ]#id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
[root@node3 local ]#mkdir /mydata
[root@node3 ~ ]#umount /mnt/     
[root@node3 local ]#chown -R mysql:mysql /mydata
[root@node3 ~ ]#mount /dev/drbd0 /mydata     
[root@node3 mariadb-10.0.13 ]#cmake .
            -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \##指定安装路径
            -DMYSQL_DATADIR=/mydata \                ##指定库位置          
            -DWITH_INNOBASE_STORAGE_ENGINE=1 \       ##指定存储引擎          
            -DWITH_ARCHIVE_STORAGE_ENGINE=1\                      
            -DWITH_BLACKHOLE_STORAGE_ENGINE=1\          
            -DWITH_READLINE=1\                                
            -DWITH_SSL=system\                      ##定制SSL功能          
            -DWITH_ZLIB=system\                     ##定制ZLIB功能          
            -DWITH_LIBWRAP=0\           
            -DMYSQL_UNIX_ADDR=/tmp/mysql.sock\      ##sock位置          
            -DDEFAULT_CHARSET=utf8 \                 ##默认字符集         
            -DDEFAULT_COLLATION=utf8_general_ci  
#make 
#make之后
Linking CXX
executable my_safe_process
[100%] Built target
my_safe_process
[root@node3 mysql ]#ls /mydata/
aria_log.00000001  aria_log_control  ibdata1 
ib_logfile0  ib_logfile1  mysql performance_schema  test
[root@node3support-files ]# cp my-large.cnf /etc/mysql/my.cnf
[root@node3support-files ]# cd /etc/mysql
[root@node3 mysql ]#ls
my.cnf
[root@node3 mysql ]#vim my.cnf  #####在mysqld添加如下
innodb_file_per_table = on
datadir = /mydata
[root@node3 mysql ]#
service mysqld start
Starting
MySQL...                                         
[  OK  ]
[root@node3 mysql ]# mysql   //登陆已经正常了
Welcome to the MySQL
monitor.  Commands end with ; or \g.
Your MySQL
connection id is 4
Server version: 5.5.5-10.0.13-MariaDB-log Source
distribution
Copyright (c) 2000,
2013, Oracle and/or its affiliates. All rights reserved.
로그인 후 복사

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/12143055N-5.jpg" title="6.png" alt="wKioL1S6AKiBdZmaAACOJ8rbeRU363.jpg" />

注意:同样的步骤部署第二个节点mysql但是,不要初始化。因为共享磁盘已经初始化过了。

########################下面,就可以使用crmsh配置资源了。###########################

下面,就可以使用crmsh配置资源了。

首先:保证我们两个节点的服务不会开机自动启动

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/12143033X-6.jpg" title="7.png" alt="wKioL1S6AhCjIfplAADGdV1gZTs642.jpg" />

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/1214303016-7.jpg" title="8.png" alt="wKiom1S6AV3BIyK6AAEBu0s2HYQ789.jpg" />

##################启动两个节点的corosync##########################################################

[root@node3 ~ ]#service corosync start
Starting Corosync
Cluster Engine (corosync):              [  OK  ]
로그인 후 복사
[root@node3 ~ ]# service mysqld stop    ##停掉我们使用的所有资源
Stopping
mysqld:                                          [  OK  ]
[root@node3 ~ ]#umount /mydata/
[root@node3 ~ ]#drbd-overview
 0:mydisk/0 Connected Primary/Secondary UpToDate/UpToDate
[root@node3 ~ ]#drbdadm secondary mydisk
[root@node3 ~ ]#drbd-overview
 0:mydisk/0 Connected Secondary/Secondary UpToDate/UpToDate
[root@node3 ~ ]#service drbd stop
Stopping all DRBD
resources: .
로그인 후 복사

650) this.width=650;" src="http://www.68idc.cn/help/uploads/allimg/151111/1214301141-8.jpg" title="9.png" alt="wKioL1S6Av7xuRf-AAE6aE3fG9I709.jpg" />

安装crmsh ##安装并且定义

[root@node3 ~ ]# yum install crmsh-2.1-1.6.x86_64.rpm
[root@node3 ~ ]# crm
crm(live)# configure
#####################第一步:定义前提属性#############################
crm(live)configure# property stonith-enabled=false            //禁用stonish
crm(live)configure# property no-quorum-policy=ignore    //定义无票策略
#####################第二步:定义DRBD主资源###########################
crm(live)configure#
primitive mydrbd ocf:linbit:drbd params drbd_resource="mydisk" op
monitor role=Master timeout=20 interval=10 op monitor role=Slave timeout=20
interval=10 op start timeout=240 op stop timeout=100
####################第三步:定义DRBD主从资源##########################
crm(live)configure#ms ms_mydrbd mydrbd meta master-max="1" master-node-max="1"
clone-max="2" clone-node-max="1" notify="true"
####################第四步:定义文件系统资源##########################
crm(live)configure#primitive myfs ocf:heartbeat:Filesystem params device=/dev/drbd0
directory=/mydata fstype="ext4" op monitor timeout=40 interval=20 op start timeout=60 op stop timeout=60
####################第五步:定义协同约束##############################
crm(live)configure#colocation mydrbd-master_with_myfs inf: ms_mydrbd:Master myfs
crm(live)configure#
####################第六步:定义顺序约束##############################
crm(live)configure#order ms_mydrbd-master_before_myfs inf: ms_mydrbd:promote myfs:start
#################第七步:定义流动IP###################################
crm(live)configure#primitive myvip ocf:heartbeat:IPaddr params ip=172.16.11.11 op monitor
timeout=20 interval=10 op start timeout=20 op stop timeout=20
###################第八步:定义mysql服务资源############################
crm(live)configure#primitive myservice lsb:mysqld op monitor timeout=20 interval=20
crm(live)configure#
###################第九步:定义他们为一个组资源########################
crm(live)configure#group mygroup myvip myfs ms_mydrbd:Master myservice
####################第十步:定义他们的协同约束#########################
crm(live)configure#order myfs_before_myservice inf: myfs:start myservice:start
crm(live)configure# commit     ##提交
interval in monitor_Master must be unique
crm(live)configure#show     ##查看我们定义的所有资源
로그인 후 복사

wKiom1S6A5azjLKOAAVVzvgpk14762.jpg

切换测试结果:

wKiom1S6A_Cj3MhEAACrW42JB6g335.jpg

wKiom1S6BBvRHUnUAACjCpLd-ME589.jpg


至此高可用全部完成!





원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿