styxmx 发表于 2019-1-7 09:56:20

heartbeat mysql nfs 高可用mysql集群

  一环境准备
  二拓扑结构
  三安装heartbeat
  四配置NFS服务
  五安装mysql
  六crm 配置资源
  一环境准备
  操作系统
  centos 6.4 x86_64 最小化安装
  如使用yum 安装的方式 centos5.5 安装的是V2.X ,centos 6.4 安装的是V3.X
  YUM 安装 Vim man ntp “development tools” “server platform development” “desktop platform development”
  mysql-5.5.37(采用通用二进制包安装方式)
  配置 epel YUM 源
  关闭 防火墙 selinux
  二 拓扑结构
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914968lEtE.png
  三 安装heartbeart
  1 节点之间主机名可以互相解析
  web1 ,web2
# vim /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.132web1.daphne.comweb1
192.168.200.133web2.daphne.comweb2
  2 节点之间时间同步

# ntpdate ntp.api.bz
  3 节点之间配置SSH互信

# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
# ssh-copy-id -i .ssh/id_rsa.pub root@web2.daphne.com
# ssh web2
#

# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
# ssh-copy-id -i .ssh/id_rsa.pub root@web1.daphne.com
# ssh web1
#
  3 heartbeat 组件说明

[*]heartbeat 核心组件
[*]heartbeat-gui 图形管理接口
[*]heartbeat-ldirectord 为lvs高可用提供规则自动生成及后端realserver健康状态检查组件
[*]heartbeat-pils 装载库插件接口
[*]heartbeat-stonith
  4 安装heartbeat
  heartbeat-2.1.4-12.el6.x86_64.rpm
heartbeat-gui-2.1.4-12.el6.x86_64.rpm
heartbeat-pils-2.1.4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm

yum install PyXML libnet pygtk2-libglade net-snmp-libs
yum installlibnet
rmp -ivh heartbeat-*
  配置heartbeat
  1配置文件说明

# cd /etc/ha.d/
# ls
authkeysharc         rc.d         resource.d
ha.cf   haresourcesREADME.configshellfuncs
  说明 安装好的heartbeat 默认没有配置文件,但提供了配置文件样本

# cd /usr/share/doc/heartbeat-2.1.4/
# ls
apphbd.cf         faqntips.html      haresources         Requirements.html
authkeys          faqntips.txt         hb_report.html      Requirements.txt
AUTHORS         GettingStarted.htmlhb_report.txt       rsync.html
ChangeLog         GettingStarted.txt   heartbeat_api.htmlrsync.txt
COPYING         ha.cf                heartbeat_api.txt   startstop
COPYING.LGPL      HardwareGuide.html   logd.cf
DirectoryMap.txtHardwareGuide.txt    README
我们需要authkeys ha.cf两个配置文件
# cp authkeys ha.cf/etc/ha.d/
  2 配置authkeys

# openssl rand -hex 8 >> authkeys
# vim authkeys
auth 2
#1 crc
#2 sha1 HI!
#3 md5 Hello!
2 sha1 7c0f241959ee845d
# chmod 600 authkeys
  3 配置ha.cf文件

# vim ha.cf
  修改心跳信息的传播方式 可以采用 组播 广播 单播

bcasteth0
  配置集群中的节点数

node web1.daphne.com
node web2.daphne.com
crm on
  4 复制以上两个文件到web2上

# scp authkeys ha.cfweb2:/etc/ha.d/
  5 启动web1与web2
  先启动备份节点

# service heartbeatstart
# service heartbeatstart

  6 查看集群状态

# crm_mon
Node: web2.daphne.com (1eb4208c-1790-491c-bbc9-4b4b8669a6da): online
Node: web1.daphne.com (f145a88d-245f-4b92-b31c-89670502927e): online两个节点都在线,资源暂时没有配置
  7 测试一下hb_gui图形界面
  (如遇到图形界面乱码   yum installsystem-config-kickstart)
  # hb_gui
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914968dseq.png
  四 配置NFS 服务
  1创建数据库目录   (生成环境可使用LVM)

# mkdir -pv /mydata/data/
  2 创建mysql用户
  在 web1,web2,nfs三个节点都要创建ID保持相同

# useradd -r -u 127 mysql
  3 修改数据库目录用户

# chown -R mysql:mysql /mydata/
  4 安装NFS服务

# yum install nfs*
# service rpcbind start
# service nfs start
  5 修改NFS配置文件

# vim /etc/exports
/mydata/data 192.168.200.0/24(rw,no_root_squash)
  6 重新输出一下NFS

# exportfs -avr
exporting 192.168.200.0/24:/mydata/data
  7 查看输出的NFS共享存储

# showmount -e 192.168.200.130
Export list for 192.168.200.130:
/mydata/data 192.168.200.0/24
  8 测试挂载

# mkdir -pv /mydata/data/
# mount -t nfs 192.168.200.130:/mydata/data/ /mydata/data/
# mkdir -pv /mydata/data/
# mount -t nfs 192.168.200.130:/mydata/data /mydata/data
  (centos 6.4采用NFS 4v即使各个节点有相同用户,也显示nobody用户,为避免此问题 可以修改 /etc/idmapd.conf 文件
  #Domain = local.domain.edu
  Domain = daphne.com
  服务器端客户端都要修改
  service rpcidmapd restart)
  五 安装msyql
  web1
  1安装mysql

# tar -zxvf mysql-5.5.37-linux2.6-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# ln -sv mysql-5.5.37-linux2.6-x86_64 mysql
  2 初始化数据库

# yum install libaio
# scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql
  3 提供配置文件

# cp support-files/my-large.cnf /etc/my.cnf
# vim /etc/my.cnf
datadir = /mydata/data
4 提供mysql启动脚本
# cp support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
  5 启动mysql

# service mysqld start
  6 查看数据目录

# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.200.130:/mydata/data/ on /mydata/data type nfs (rw,vers=4,addr=192.168.200.130,clientaddr=192.168.200.132)
# cd /mydata/data/
# ls
ibdata1         mysql-bin.000002mysql-bin.000007   web1.daphne.com.pid
ib_logfile0       mysql-bin.000003mysql-bin.index      web2.daphne.com.err
ib_logfile1       mysql-bin.000004performance_schema
mysql             mysql-bin.000005test
mysql-bin.000001mysql-bin.000006web1.daphne.com.err
  7 测试登陆

# mysql
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.37-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement
mysql>
  8 停止mysql服务卸载/mydata/data

# service mysqld stop
# umount /mydata/data/
  web2
  1 安装mysql

# tar -zxvf mysql-5.5.37-linux2.6-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# ln -sv mysql-5.5.37-linux2.6-x86_64 mysql
  2 将web1的配置文件 启动脚本拷贝至 web2

# scp /etc/my.cnf web2:/etc/
# scp /etc/init.d/mysqldweb2:/etc/init.d/
  3 启动mysql

# service mysqld start
Starting MySQL.. SUCCESS!
  4 测试登陆

# mysql
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.37-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
  5 停止mysql卸载/mydata/data

# service mysqld stop
Shutting down MySQL. SUCCESS!
# umount /mydata/data/
  六 crm资源配置
  1 新建组资源
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914970abXE.jpg
  2 设置组ID名
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914971Q6A7.jpg
  3 添加VIP资源
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914973BMuT.jpg
  4 添加 共享存储资源
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914975hWoU.jpg
  5 添加mysql 服务资源
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914977Mjds.jpg
  6 资源添加完成
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914979zHq2.jpg
  7启动全部资源
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914981ranK.jpg
  8 查看IP
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914984Sx4V.jpg
  10 查看资源状态
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914987eE98.jpg
  11web1 连接测试mysql
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914990krrp.jpg
  12 mysql授权
  mysql> grant all on *.* to 'root'@'192.168.200.%' identified by 'redhat';
  mysql> flush privileges;
  13 测试集群
  # mysql -uroot -predhat -h 192.168.200.10
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.37-log MySQL Community Server (GPL)
  Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  14 模拟故障
  1 将web2节点 切换到 standby,资源全部切换到web1上
http://168322.blog.运维网.com/attachment/201406/28/158322_1403914992DOHf.jpg
  2 查看web1接口

# ifconfig
eth0      Link encap:EthernetHWaddr 00:0C:29:7D:C1:D7
inet addr:192.168.200.132Bcast:192.168.200.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe7d:c1d7/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:13573 errors:0 dropped:0 overruns:0 frame:0
TX packets:7765 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:17996747 (17.1 MiB)TX bytes:831831 (812.3 KiB)
eth0:0    Link encap:EthernetHWaddr 00:0C:29:7D:C1:D7
inet addr:192.168.200.10Bcast:192.168.200.255Mask:255.255.255.0
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
eth1      Link encap:EthernetHWaddr 00:0C:29:7D:C1:E1
inet addr:192.168.10.132Bcast:192.168.10.255Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe7d:c1e1/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b)TX bytes:830 (830.0 b)
lo      Link encap:Local Loopback
inet addr:127.0.0.1Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNINGMTU:16436Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b)TX bytes:0 (0.0 b)
3 远程测试mysql
# mysql -uroot -predhat -h 192.168.200.10
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.37-log MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
  高可用mysql集群,演示完毕











页: [1]
查看完整版本: heartbeat mysql nfs 高可用mysql集群