Mysql_HA+IP_SAN+Clvmd+GFS2

Mysql_HA+IP_SAN+Clvmd+GFS2

====================================================================

GFS:全局文件系统,支持DLM锁管理,支持并发写,Centos6不超过16个节点适用于HA集群使用的共享存储适用于LB集群RealServer使用的共享存储

mysql高可用集群架构设计

1、节点主机系统:Centos6.5

2、高可用集群软件:RHCS

3、两台节点主机node1,node2:

Node1: IP:192.168.1.34host name:edu-mysql-master;

Node2: IP:192.168.1.157host name:edu-mysql-slave;

VIP: 192.168.1.166

Service:mysql

4、一台GFS2服务主机:

IP:192.168.1.111

LVM:/dev/mapper/datavg-mysql--lv

共享目录:/data(LVM),/data(mysql数据目录)

5、三台主机相同用户:mysql mysql(组) 3306(uid、gid)

相关准备配置

1、配置IP、安装WEB服务、关闭防火墙;

2、配置各节点名称;

3、建立各节点间的SSH互信通信;

4、各节点间的时间同步;

一、存储配置

存储端(target)

1、安装包

[root@target ~]# yum -y install scsi-target-utils

2、定义target共享

[root@target ~]# vim /etc/tgt/targets.conf

backing-store /dev/sdb

3、启动服务

[root@target ~]# service tgtd start

[root@target ~]# netstat -tnlp |grep :3260

tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 15135/tgtd

tcp 0 0 :::3260 :::* LISTEN 15135/tgtd

[root@storage ~]# tgt-admin --show

Target 1: iqn.2017-1.com.example:mysql

Backing store path: /dev/sdb

ACL information:

ALL

集群节点initiator端(node1、node2)

1、安装包

[root@node1 ~]# yum -y install iscsi-*

2、发现存储

[root@node1 ~]# iscsiadm -m discovery -t st -p 192.168.1.111

正在启动iscsid: [确定]

192.168.1.111:3260,1 iqn.2017-1.com.example:mysql

3、登入存储

[root@node1 ~]# service iscsi restart

[root@node1 ~]# chkconfig iscsi on

4、查看设备

[root@node1 ~]# fdisk -cul

Disk /dev/sdb: 8589 MB, 8589934592 bytes

64 heads, 32 sectors/track, 8192 cylinders, total 16777216 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

二、配置集群,并使用CLVMD(node1、node2)

1. 配置集群

a. 创建集群

2. 配置CLVMD

确保node1和node2 clvmd运行

[root@node1 ~]# /etc/init.d/clvmd status

clvmd (pid 1908) 正在运行...

Clustered Volume Groups: (none)

Active clustered Logical Volumes: (none)

node1创建lv

[root@node1 ~]# pvcreate /dev/sdb

[root@node1~]# vgcreate datavg /dev/sdb

[root@node1~]# lvcreate -L 2G -n mysql-lv datavg

[root@node1~]# vgs

VG #PV #LV #SN Attr VSize VFree

datavg 1 1 0 wz--nc8.00g 6.00g

[root@node1~]# lvs

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert

mysql-lv datavg -wi-a---- 2.00g

node2查看

[root@node2 ~]# vgs

VG #PV #LV #SN Attr VSize VFree

VolGroup 1 2 0 wz--n- 9.51g 0

gfs-vg 1 1 0 wz--nc 5.00g 3.00g

[root@node2 ~]# lvs

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert

lv_root VolGroup -wi-ao--- 8.54g

lv_swap VolGroup -wi-ao--- 992.00m

gfs-lv gfs-vg -wi-a---- 2.00g

3 、创建GFS2文件系统 node1或node2

a、在node1,node2上安装gfs2的相关软件包

[root@node1 ~]# rpm -qa |grep gfs

gfs2-utils-3.0.12.1-78.el6.x86_64//提供mkfs.gfs2命令用于创建gfs2文件系统

[root@node1 ~]# modinfo -F filename gfs2

/lib/modules/2.6.32-358.el6.x86_64/kernel/fs/gfs2/gfs2.ko

b、在任意一个节点上格式化

[root@node1 ~]# cman_tool status

Version: 6.2.0

Config Version: 19

Cluster Name:gfs-cluster

Cluster Id: 1835

Cluster Member: Yes

Cluster Generation: 24

Membership state: Cluster-Member

Nodes: 2

Expected votes: 1

Total votes: 2

Node votes: 1

Quorum: 1

Active subsystems: 9

Flags: 2node

Ports Bound: 0 11 177

Node name: edu-mysql-master

Node ID: 1

Multicast addresses: 239.192.7.50

Node addresses: 192.168.1.34

[root@node1 ~]# mkfs.gfs2 -tgfs-cluster:table1 -p lock_dlm -j 3 -J 128M /dev/datavg/mysql-lv

This will destroy any data on /dev/datavg/mysql-lv.

It appears to contain: symbolic link to `../dm-2'

Are you sure you want to proceed? [y/n] y

Device: /dev/datavg/mysql-lv

Blocksize: 4096

Device Size 2.00 GB (524288 blocks)

Filesystem Size: 2.00 GB (524288 blocks)

Journals: 3

Resource Groups: 8

Locking Protocol: "lock_dlm"

Lock Table: "gfs-cluster:table1"

UUID: 98326a5a-f72c-5a1d-6ccd-bec094caba26

-t clustername:locktablename

-p lock_dlm

-j 指定日志空间个数,此个数一定要大于等于使用gfs2文件系统存储的主机数

-J 指定一个日志空间的大小

c、挂载并测试写入

[root@node1 ~]# vim /etc/fstab

/dev/datavg/mysql-lv /var/www/html gfs2 defaults,_netdev0 0

[root@node1 ~]# mount -a

[root@node1 ~]# df -P

/dev/mapper/datavg-mysql--lv gfs2 2.0G 410M 1.7G 20% /data

GFS扩展知识:

1. 使用非DLM锁挂载GFS2

[root@node2 ~]# mount -a

/sbin/mount.gfs2: node not a member of the default fence domain

/sbin/mount.gfs2: error mounting lockproto lock_dlm

[root@node2 ~]# mount-o lockproto=lock_nolock/dev/datavg/mysql-lv /data

2. 当集群节点扩充时,增加日志的个数

=====================================================================

MySQL初始化数据库:

1. 安装

[root@node1 ~]# tar -zxfmysql.package.tar-C /usr/local

[root@node1 ~]# cd /usr/local/

[root@node1 local]# cd mysql

[root@node1 mysql]# chown -R mysql:mysql ./*

[root@node1 mysql]# ll

[root@node1 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/

node2同上

(以后脚本安装mysql,更新mysql安装脚本相应路径即可)

2. node1初始化

[root@node1 ~]#mkdir /data

[root@node1 ~]#vim /etc/fstab    (node2无须操作)

/dev/datavg/mysql-lv      /data           gfs2    defaults,_netdev 0 0

[root@node1 ~]#mount –a

[root@node1 ~]# mount /dev/datavg/mysql-lv /data

[root@node1 ~]# service mysqld start;chkconfig mysqld off

[root@node1 ~]# service mysqld stop

[root@node1 ~]# umount /data

2.node1初始化

node2同上

(注:启动mysql服务前先停止node1上的mysql服务,并卸载GFS2共享目录;

然后先挂载存储,再在node2上启动mysql服务,进行测试,测试完后记得停止mysql服务,并卸载GFS2共享目录)

[root@node1 ~]#scp -p /etc/my.cnf  node2:/etc

[root@node1 ~]# scp -p /etc/init.d/mysqldnode2:/etc/init.d/

此文档需要与https://192.168.1.111:8084/ 端配置同时进行,集群管理断配置见http://www.jianshu.com/p/988e74a26469;

=====================================================================

[root@node2~]#Apache:

[root@node2~]# ip: 192.168.1.100

[root@node2~]# script: /etc/init.d/httpd

[root@node2~]# filesystem: ------ NFS mount (NAS)

[root@node2~]#MySQL:

[root@node2~]# ip: 192.168.1.200

[root@node2~]# script: /etc/init.d/mysqld

[root@node2~]# filesystem: /dev/datavg/mysql-lv /var/lib/mysql (GFS2)

针对存储资源设置

NFS: NFS Mount

EXT4: Filesystem

GFS2: GFS2

你可能感兴趣的:(Mysql_HA+IP_SAN+Clvmd+GFS2)