corosync+pacemaker实现高可用的MariaDB

一、准备工作

承接上文:corosync+pacemaker使用crmsh构建高可用集群

二、MariaDB server配置(基于nfs)

nfs server准备

1、在nfs server准备LVM存储空间
[[email protected] ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x61284c6a.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won‘t be recoverable.
 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
 
WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
         switch off the mode (command ‘c‘) and change display units to
         sectors (command ‘u‘).
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1-1305, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +10G
Value out of range.
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +5G 
 
Command (m for help): t
Selected partition 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
 
[[email protected] ~]# partx -a /dev/sdb
 
[[email protected] ~]# pvcreate /dev/sdb3
  Physical volume "/dev/sdb3" successfully created
[[email protected] ~]# vgcreate myvg /dev/sdb3
  Volume group "myvg" successfully created
[[email protected] ~]# lvcreate -L 5G -n mydata myvg
  Logical volume "mydata" created.
[[email protected] ~]# mke2fs -t ext4 /dev/myvg/mydata
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736
 
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
 
 
2、开机自动挂载,并nfs导出
[[email protected] ~]# mkdir  /mydata
[[email protected] ~]# vim /etc/fstab 
/dev/myvg/mydata        /mydata                 ext4    defaults        0 0
[[email protected] ~]# mount -a
[[email protected] ~]# mount | grep /mydata
/dev/mapper/myvg-mydata on /mydata type ext4 (rw)
 
[[email protected] ~]# vim /etc/exports 
/mydata         192.168.0.0/24(rw,no_root_squash)
#共享给192.168.0.0/24网段,可读可写,允许root用户登录便于初始化,配置结束可取消root用户登录
 
 
3、导出nfs共享目录
#创建mysql用户,指明uid,gid。各节点的mysql用户uid,gid一致。
[[email protected] ~]# groupadd -r -g 306 mysql
[[email protected] ~]# useradd -r -g 306 -u 306 mysql
 
#创建共享目录,并修改属主属组。
[[email protected] ~]# mkdir /mydata/data
[[email protected] ~]# chown -R mysql.mysql /mydata/data
 
#导出nfs共享目录
[[email protected] ~]# exportfs -arv
exporting 192.168.0.0/24:/mydata

[[email protected] ~]# service nfs start

三、各节点准备mysql

node1

创建mysql用户,uid和gid与nfs server的mysql用户保持一致
[[email protected] ~]# groupadd -r -g 306 mysql
[[email protected] ~]# useradd -r -g 306 -u 306 mysql

安装mariadb
[[email protected] ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local/
[[email protected] ~]# cd /usr/local
[[email protected] local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql
`mysql‘ -> `mariadb-5.5.46-linux-x86_64‘
[[email protected] local]# cd mysql/
[[email protected] mysql]# chown -R root.mysql ./*

挂载nfs文件系统
[[email protected] mysql]# mount -t nfs 192.168.0.20:/mydata /mydata
[[email protected] mysql]# mount | grep /mydata
192.168.0.20:/mydata on /mydata type nfs (rw,vers=4,addr=192.168.0.20,clientaddr=192.168.0.15)

初始化mysql至nfs,此步骤只需一个节点操作即可,本文node1执行,那么node2就不需要执行
初始化操作后,可以将nfs server的共享选项中的no_root_squash移除了
[[email protected] mysql]# ./scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql

nfs server端查看
[[email protected] ~]# cd /mydata/data
[[email protected] data]# ll
total 32
-rw-rw---- 1 mysql mysql 16384 Nov 21 20:32 aria_log.00000001
-rw-rw---- 1 mysql mysql    52 Nov 21 20:32 aria_log_control
drwx------ 2 mysql root   4096 Nov 21 20:32 mysql
drwx------ 2 mysql mysql  4096 Nov 21 20:32 performance_schema
drwx------ 2 mysql root   4096 Nov 21 20:32 test

node1节点配置mysql
[[email protected] mysql]# mkdir /etc/mysql
[[email protected] mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf
[[email protected] mysql]# vim /etc/mysql/my.cnf
datadir = /mydata/data
innodb_file_per_table = on
skip_name_resolve = on

为mysql提供服务脚本,并禁止其开机启动
[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld off

启动mysql,创建mydb数据库
[[email protected] mysql]# service mysqld start
Starting MySQL..... SUCCESS!
[[email protected] mysql]# vim /root/.bashrc 
PATH=/usr/local/mysql/bin:$PATH
export PATH
[[email protected] mysql]# source /root/.bashrc
[[email protected] mysql]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.46-MariaDB-log MariaDB Server

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

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

MariaDB [(none)]> create database mydb;
Query OK, 1 row affected (0.16 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]> exit
Bye
[[email protected] mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS! 

卸载共享目录
[[email protected] mysql]# umount /mydata

node2

[[email protected] ~]# groupadd -r -g 306 mysql
[[email protected] ~]# useradd -r -g 306 -u 306 mysql
[[email protected] ~]# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local
[[email protected] ~]# cd /usr/local/
[[email protected] local]# ln -sv mariadb-5.5.46-linux-x86_64 mysql
`mysql‘ -> `mariadb-5.5.46-linux-x86_64‘
[[email protected] local]# cd mysql/
[[email protected] mysql]# chown  root.mysql ./*

将node1的配置文件复制给node2
[[email protected] mysql]# mkdir /etc/mysql/
[[email protected] mysql]# scp /etc/mysql/my.cnf node2:/etc/mysql/

为node2节点准备服务脚本,并禁止开机启动
[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld off

挂在共享文件系统,启动mysql
[[email protected] mysql]# mkdir /mydata
[[email protected] mysql]# mount -t nfs 192.168.0.20:/mydata /mydata
[[email protected] mysql]# service mysqld start
Starting MySQL.. SUCCESS! 
[[email protected] mysql]# vim /root/.bashrc 
PATH=/usr/local/mysql/bin:$PATH
export PATH
[[email protected] mysql]# source /root/.bashrc
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.02 sec)

授权远程访问
MariaDB [(none)]> grant all on *.* to ‘root‘@‘192.168.%.%‘ identified by ‘jymlinux‘;
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> exit
Bye

停止mysql,并卸载共享目录
[[email protected] mysql]# service mysqld stop
Shutting down MySQL.. SUCCESS! 
[[email protected] mysql]# umount /mydata

四、使用crmsh配置mariadb高可用

[[email protected] ~]# crm
crm(live)# cd configure
crm(live)configure# primitive myip ocf:heartbeat:IPaddr params ip=192.168.0.17 nic=eth0 cidr_netmask=24 op monitor interval=10s timeout=20s
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# primitive mystore ocf:heartbeat:Filesystem params device=192.168.0.20:/mydata/data directory=/mydata fstype=nfs 
crm(live)configure# verify
WARNING: mystore: default timeout 20s for start is smaller than the advised 60
WARNING: mystore: default timeout 20s for stop is smaller than the advised 60
crm(live)configure# commit
WARNING: mystore: default timeout 20s for start is smaller than the advised 60
WARNING: mystore: default timeout 20s for stop is smaller than the advised 60
crm(live)configure# primitive myserver ocf:heartbeat:mysql params binary="/usr/local/mysql/bin/mysqld_safe" config="/etc/mysql/my.cnf" datadir="/mydata/data"  op start timeout=120s op stop timeout=120s op monitor interval=20s timeout=30s
crm(live)configure# verify
crm(live)configure# commit

定义组资源
crm(live)configure# group myservice myip mystore myserver
时间: 2024-08-04 03:37:29

corosync+pacemaker实现高可用的MariaDB的相关文章

通过 corosync/pacemaker实现高可用的MariaDB

目的: 通过corosync v1 和pacemaker 提供高可用mariadb,在调度切换RS时,仍能数据库访问及操作不中断. 其中corosyncv1提供底层心跳及事务信息传递功能,pacemaker提供CRM.LRM 试验环境流程: 第一台虚拟机提供nfs文件共享存储:中间两台虚拟机配置相同mariadb服务,数据库存储位置为第四台虚拟机提供的nfs文件系统.对pacemaker的配置操作可以有多种形式,如CLI接口的crmsh和pcs,GUI的 hawk(webgui)和LCMC.其中

corosync/pacemaker, 实现高可用的MariaDB

实验环境: 两台mariaDB服务器 172.16.10.20 172.16.10.21 fip:172.16.10.28 MariaDB文件存储共享:172.16.10.22 实验准备: 1.两个节点的主机名称和对应的IP地址解析服务可以正常工作,且每个节点的主机名称需要跟"uname -n"命令的结果保持一致   vim /etc/hosts      172.16.10.20 21.xuphoto.com 20xu      172.16.10.21 22.xuphoto.com

corosync+pacemaker实现高可用(HA)集群

corosync+pacemaker实现高可用(HA)集群(一) ????重要概念 在准备部署HA集群前,需要对其涉及的大量的概念有一个初步的了解,这样在实际部署配置时,才不至于不知所云 资源.服务与主机(又称节点)的关系: 资源包括vip,httpd,filesystem等: 可整合多个资源形成一个服务: 服务必运行在某个主机上,主机上也可不运行服务(此为空闲主机): 服务里的所有资源应该同时运行在同一个节点上,实现方式有2种: 资源组: 排列约束 资源类型 primitive(或native

corosync+pacemaker实现高可用集群。

实验环境: 安装: yum install corosync pacemaker -y 复制配置文件 cp corosync.conf.example corosync.conf vim corosync.conf 编辑配置文件: compatibility: whitetank  是否兼容0.8版本的corosynctotem {定义集群之间心跳信息传递层   version: 2 ----版本号        secauth: on ---是否启用安全认证        threads: 0

corosync+pacemaker的高可用集群

基于corosync+pacemaker的高可用集群 Pacemaker即Cluster Resource Manager (简称CRM),用来管理整个HA的控制中心,客户端通过pacemaker来配置管理监控整个集群.它不能提供底层心跳信息传递的功能,它要想与对方节点通信需要借助底层(新拆分的heartbeat或corosync)的心跳传递服务,将信息通告给对方. pacemaker管理资源的工具由命令行界面的crmsh.pcs和图形化界面pygui.hawk等进行管理. 因此,一般来说都是选

corosync+pacemaker实现高可用集群

Corosync corosync最初只是用来演示OpenAIS集群框架接口规范的一个应用,可以实现HA心跳信息传输的功能,是众多实现HA集群软件中之一,可以说corosync是OpenAIS的一部分,然而后面的发展超越了官方最初的设想,越来越多的厂商尝试使用corosync作为集群解决方案,如Redhat的RHCS集群套件就是基于corosync实现. corosync只提供了message layer(即实现HeartBeat + CCM),而没有直接提供CRM,一般使用Pacemaker进

Corosync + Pacemaker 搭建高可用MariaDB服务

实验描述 1.本实验的目的是为了通过手动配置corosync配置文件,实现MariaDB服务的高可用,集群心跳传递使用组播方式.2.三个节点的主机名分别为:node5.redhat.com.node6.redhat.com.node7.redhat.com.地址为172.16.100.5.172.16.100.6.172.16.100.7.3.利用nfs做后端存储,NFS地址为172.16.0.254.3.VIP地址为172.16.100.1004.三个节点系统全部为CentOS7.2,NFS节

drbd+mariadb+corosync+pacemaker构建高可用,实现负载均衡

DRBD DRBD是由内核模块和相关脚本而构成,用以构建高可用性的集群 drbd 工作原理:DRBD是一种块设备,可以被用于高可用(HA)之中.它类似于一个网络RAID-1功能. 当你将数据写入本地 文件系统时,数据还将会被发送到网络中另一台主机上.以相同的形式记录在一个 文件系统中. 本地(主节点)与远程主机(备节点)的数据可以保证实时同步.当本地系统出现故障时,远 程主机上还会保留有一份相同的数据,可以继续使用.在高可用(HA)中使用DRBD功能,可以代替使用一 个共享盘阵.因为数据同时存在

corosync+pacemaker+http高可用操作手记

前言: 因为公司大量用到了corosync+packmaker,本人之前只是了解,并没深入比较keepalive及heatbeatcorosync+packmaker的区别,原理方面不探讨,可以查看官网,或者查看网上资料. 这里仅仅分享一下自己做的一个小实验,算是基础入门.新公司东西比较多,因此最近博客更新会很慢,但是以后有时间分享的东西,则都是网上少见的,加上自己的经验之谈,热爱开源,热爱分享. 实验目的: 利corosync+packmaker,做到http高可用访问.当然可以结合drdb,