hongmeigui22027 发表于 2019-1-6 15:12:50

heartbeat v2 实现HA (二)

heartbeat v2 版本简介
v1版本通过haresource配置文件手动定义资源,然后手动复制到各个节点,非常不方便管理和使用,于是就催生了heartbeat v2 版本。
  V2 版本不再基于haresoures配置文件,而是基于crm实现。XML,只需在任意一个节点定义资源之后就可以通知给所以节点。


[*]  /var/lib/heartbeat/crm :用户用XML格式定义资源文件的路径
[*]  但是XML格式的文件一般用户都不会写,不用着急,heartbeast内置了一个程序会帮我们把haresoures格式文件翻译为XML格式文件:另外也可以用GUI图像话界面配置。
/usr/lib64/hearebeat/haresources2cib.py(python编写)


基于GUI图像化配置步骤(接v1版本配置)
http://blog.运维网.com/e/u/themes/default/images/spacer.gifhttp://s3.运维网.com/wyfs02/M01/24/90/wKiom1NSiZejADm0AAEghBkx58Y649.jpg
1、停掉heartbeat服务,删除haresoures文件。
2、编辑配置文件ha.,(可以用scp,也可以用工具ha_paropagate:之复制authkeys和ha.)
# vim ha.
node    node1.nyist.com
node    node2.nyist.com
#
crm on---------------启动crm
# /usr/lib64/heartbeat/ha_propagate
Propagating HA configuration files to node node2.nyist.com.
ha.                                                                                                               100%   10KB10.4KB/s   00:00
authkeys
3、要想安装基于图像话管理工具,需要两个节点安装heartbeat-gui
# rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm
4、启动heartbeat服务,可以看到mgmtd监听在5560端口:只要这个进程一启动,就可以使用crm命令管理资源了
root@node1 heartbeat2]# ss -tunlp | grep 5560
tcp    LISTEN   0      10                     *:5560                  *:*      users:(("mgmtd",11576,10))
mamtd:接收用户的连接命令,并提供API接口的进程
此时就有了一大堆crm命令可以使用了
# crm
crmadmin       crm_failcountcrm_resource   crm_uuid
crm_attributecrm_master   crm_sh         crm_verify
crm_diff       crm_mon      crm_standby
5、管理资源需要一个用户,安装heartbeat的时候已经生成了一个hacluster用户,这里给其加密码,我们需要用这个用户登录管理。
hacluster:x:496:493:heartbeat user:/var/lib/heartbeat/cores/hacluster:/sbin/nologin
# passwd hacluster
实例一
登录管理,定义资源和约束
# hb_gui &
http://s3.运维网.com/wyfs02/M01/24/8F/wKioL1NSiaLhLjxhAAKupEzyL_k605.jpg
http://s3.运维网.com/wyfs02/M00/24/90/wKiom1NSic2wJ3kDAAJyrWMNSxk438.jpg
http://s3.运维网.com/wyfs02/M02/24/8F/wKioL1NSiaTDstBUAABDoyAgrHg654.jpg

默认工作在负载均衡模式,两个资源分别运行在不同节点。
定义排列约束(或资源组),让两个资源运行在一个节点上:
http://blog.运维网.com/e/u/themes/default/images/spacer.gifhttp://s3.运维网.com/wyfs02/M02/24/90/wKiom1NSigGB7wVgAAKfd-Of4m8081.jpg
http://s3.运维网.com/wyfs02/M02/24/90/wKiom1NSigGi63u7AABC9ykOjYE885.jpg

定义位置约束:服务更倾向运行在哪个节点上
http://blog.运维网.com/e/u/themes/default/images/spacer.gifhttp://s3.运维网.com/wyfs02/M02/24/8F/wKioL1NSihGzTdwdAAMHbci61kM636.jpg
定义顺序约束:哪个资源优先启动
http://blog.运维网.com/e/u/themes/default/images/spacer.gifhttp://s3.运维网.com/wyfs02/M00/24/8F/wKioL1NSih-AWHMIAAKo6bz2Pao258.jpg

实例二、通过定义组来统一管理资源
定义组资源后就不用定义排列约束了
http://s3.运维网.com/wyfs02/M02/24/90/wKiom1NSiqPjfmIrAACd2Ujcpgw026.jpg
http://s3.运维网.com/wyfs02/M01/24/8F/wKioL1NSinqRv2gzAAKHmx3Cepg966.jpg
http://s3.运维网.com/wyfs02/M00/24/90/wKiom1NSiqWAipKIAAKByJKu_Is286.jpg
http://s3.运维网.com/wyfs02/M02/24/8F/wKioL1NSin3ydPkwAAJ17E3obmA272.jpg
http://s3.运维网.com/wyfs02/M01/24/90/wKiom1NSiqaDkWa4AABolKxFpe4077.jpg


STONITH
为了防止退出集群的节点对数据造成破坏,需要定义STONITH设备:当某节点发生故障时,集群成员将其踢除。


http://blog.运维网.com/e/u/themes/default/images/spacer.gif
http://blog.运维网.com/e/u/themes/default/images/spacer.gifhttp://s3.运维网.com/wyfs02/M02/24/90/wKiom1NSitTyukAnAAMF5zbX-qo217.jpg
http://s3.运维网.com/wyfs02/M01/24/8F/wKioL1NSiqzAmSXLAAKrdB_V4888.jpg




第二种集群
将Mysql定义到集群中:

http://s3.运维网.com/wyfs02/M02/24/8F/wKioL1NSisrQgj-KAAFQd9TO5Ds921.jpg
    定义两个组,一个web,一个mysql,heartbeat默认会提供负载均衡功能,会将两个组资源分摊到两个节点上。
创建共享存数,存放MySQL数据,
    mysql使用另外一个VIP 172.16.20.10


配置步骤:

1、创建NFS文件系统供Mysql挂载
# mkdir /nfs
# vim /etc/exports
/nfs172.16.0.0/16(rw,no_root_squash)
# groupadd -r -g 306 mysql
# useradd -r -u 306 -g 306 mysql
# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
# setfacl -m u:mysql:rwx /nfs
2、各节点提供和nfs中定义的Mysql的id号码一致的mysql用户,并测试其能正常读写
# groupadd -r -g 306 mysql
# useradd -r -g 306 -u 306 mysql
# id mysql
uid=306(mysql) gid=306(mysql) groups=306(mysql)
3、各节点二进制安装mysql数据库,注意,只需要一个节点初始化数据库即可。安装前先挂载nfs.
# mkdir /mydata
# mount -t nfs 172.16.20.62:/nfs /mydata/
# su mysql
bash-4.1$ cd /mydata/
bash-4.1$ mkdir data binlogs relaylogs
# tar -xf mariadb-10.0.10-linux-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# ln -sv mariadb-10.0.10-linux-x86_64/ mysql
# cd mysql
# chown root.mysql .* -R
# cp support-files/my-large.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
# vim /etc/my.cnf
datadir=/mydata/data
bin-log=/mydata/binlogs/mysql-bin
导出头文件,PATH环境变量,库文件,帮助文件
# vim /etc/man.config
# vim /etc/profile.d/mysql.sh
# ln /usr/local/mysql/include /usr/include/
# ln -sv /usr/local/mysql/include /usr/include/mysql
`/usr/include/mysql' -> `/usr/local/mysql/include'
# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
# ldconfig
4、关闭mysql服务,注意不要让其开机自启。卸载nfs文件系统。(此时为了提高安全性可以把挂载选项no_root_squash去掉了)
5、然后就可以定义一个mysql的资源组来创建集群服务了
http://s3.运维网.com/wyfs02/M02/24/90/wKiom1NSi0Gi_O29AAN4hFei7Do446.jpg
http://s3.运维网.com/wyfs02/M01/24/8F/wKioL1NSixjwJwPGAAKXmSBpc70764.jpg
http://s3.运维网.com/wyfs02/M02/24/8F/wKioL1NSixmDAeFRAAJhmrG2TdU899.jpg
  6、heartbeat默认具有负载均衡的功能,所以当你定义两个资源的时候,会平均分配到两个节点上。停掉一个节点,资源会转移到另一个节点上。
http://s3.运维网.com/wyfs02/M01/24/90/wKiom1NSi0TCKS7yAAKRG3Il_nw035.jpg
http://s3.运维网.com/wyfs02/M00/24/8F/wKioL1NSixzzhLZoAAKTb2f42R8639.jpg

5、授权一个远程客户端登录mysql验证HA效果。
# mysql
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.0.10-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant all on *.* TO 'xuqimin'@'172.16.%.%' IDENTIFIED BY 'xuqimin';
Query OK, 0 rows affected (0.00 sec)
# mysql -uxuqimin -h172.16.20.10 -pxuqimin
Welcome to the MariaDB monitor.Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.0.10-MariaDB-log MariaDB Server
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databeses;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'databeses' at line 1
MariaDB [(none)]> show databases;
+--------------------+
| Database         |
+--------------------+
| information_schema |
| mysql            |
| performance_schema |
| test               |
| xuxu               |
+--------------------+




页: [1]
查看完整版本: heartbeat v2 实现HA (二)