linux集群高可用--crm
来源:互联网 发布:quickconnect 域名 编辑:程序博客网 时间:2024/04/28 15:33
(一)
高可用集群介绍(入门)
http://blog.csdn.net/tjiyu/article/details/52643096
高可用集群的概念
(非常重要,需要重点理解)
①:什么是高可用集群 高可用集群(High Availability Cluster,简称HA Cluster),是指以减少服务中断时间为目的的服务器集群技术。它通过保护用户的业务程序对外不间断提供的服务,把因为软件、硬件、人为造成的故障对业务的影响降低到最小程度。总而言之就是保证公司业务7x24小时不宕机②:高可用集群的衡量标准 通常用平均无故障时间(MTTF:mean time to failure)来度量系统的可靠性,用平均故障维修时间(MTTR:Mean Time Between Failures)来度量系统的可维护性。于是可用性被定义为:HA=MTTF/(MTTF+MTTR)*100%。 基本可用性 2个9 99% 年度宕机时间:87.6小时 较高可用性 3个9 99.9% 年度宕机时间:8.8小时 具有故障自动恢复 4个9 99.99% 年度宕机时间:53分钟 极高可用性 5个9 99.999% 年度宕机时间:5分钟③:高可用集群实现原理 高可用集群主要实现自动侦测(Auto-Detect)故障、自动切换/故障转移(FailOver)和自动恢复(FailBack)。 1:自动侦测、故障检查:通过集群各节点间通过心跳信息判断节点是否出现故障 2:当有节点(一个或多个)和另外节点互相接收不到对方心跳信息时,如何决定哪一部分节点是正常运行的,而哪一部分是出现故障需要隔离的呢? 这时候通过法定票数(quorum)决定,即当有节点故障时,节点间投票决定哪个节点是有问题的,票数大于半数为合法,每个节点可以设置其票数,当一个节点能和另一个节点保持心跳信息,该节点就获取得了另一个节点的票数,该节点获得的所有票数就是法定票数,如果其法定票数大于集群中票数的总和的一半,那么该节点就是正常节点,反之为故障节点④:什么是RA(Resource Agent)? 资源代理层,简单的说就是能够集群资源进行管理的脚本,如启动start,停止stop、重启restart和查询状态信息status等操作的脚本。由各个节点的LRM本地资源管理器负责运行 有四类资源代理:(安装crmsh后,可以使用ra classes查看) 1、Legacy heartbeat(heatbeat v1版本的资源管理); 2、LSB(Linux Standard Base),主要是/etc/init.d/*目录下的脚本 3、OCF(Open Cluster Famework),比LSB更专业,更加通用,除了上面的四种操作,还包含monitor、validate-all等集群操作,OCF 的规范在http://www.opencf.org/cgi-bin/viewcvs.cgi/specs/ra/resource-agent-api.txt?rev=HEAD。 4、STONITH:实现节点隔离
HA解决方案分类
1:vrrp协议:keepalived2:OpenAIS提供一种集群模式解决方案:heartbeat,corosync,CMAN(RHCS:红帽集群管理套件)
集群的工作模式详解
message layer,消息层的作用是传递集群内部节点之间的信息,如果有节点宕机,此节点宕机的信息将会立即被crm集群资源管理器捕获,crm决定宕机节点上运行的服务将有哪个节点代为运行,然而必须通知crm,通过crm在调用RA(RA是一系列启动或关闭服务的脚本),实现资源在集群节点的迁移过程
红帽5、红帽6、红帽7 高可用解决方案的组合程序
红帽6:corosync 版本1 + pacemaker + pcs或crmsh corosync 版本1 + cman + pacemaker红帽7:corosync + pacemaker(pacemaker作为crm运行) + pcs/crmsh corosync是用于高可用环境中的提供Massage layer,它位于高可用集群架构中的底层(Message Layer),扮演着为各节点之间提供心跳信息传递的管理者 pacemaker是一个开源的高可用资源管理器(cluster resource manager),位于HA集群架构中资源管理、资源代理(RA)这个层次,它不能提供底层心跳信息传递的功能,它要想与对方节点通信需要借助底层的心跳传递服务corosync来实现,将信息通告给对方。通常它与corosync的结合方式有两种:①:pacemaker作为corosync的插件运行,②:pacemaker作为独立的守护进程运行
(二)
配置高可用集群(环境)
集群中节点必须满足一下基本条件
1:集群中的节点必须实现时间同步
2:能够通过/etc/hosts进行主机名解析
3:基于ssh免密码通信
集群环境准备
1:环境介绍:首先搭建两个节点的集群,node1(192.168.43.10)和 node2(192.168.43.11)2:三个节点:192.168.43.9(node0时间同步服务器),192.168.43.10(node1),192.168.43.11(node2)
集群配置步骤
node0,node1,node2上配置/etc/hosts文件,实现主机名解析
(首先要设置好主机名hostnamectl)
192.168.43.9 node0192.168.43.10 node1192.168.43.11 node2
配置ssh免密码登入
(在node0上操作)(为了避免ssh登入是需要输入yes,可以笨办法可以先在各个节点上使用ssh先登入其他的节点)
ssh-keygen -t rsa -P "" cd .ssh mv id_rsa.pub authorized_keys rm -f known_hosts cd ../ scp -rp .ssh/ node1:/root/ scp -rp .ssh/ node2:/root/
node0,node1,node2上配置时间同步服务器
1:在node0上安装配置chrony服务,同步国内互联网时间服务器的时间yum install -y chrony2:编辑配置文件/etc/chrony.conf修改默认的centos时间同步服务器地址为国内时间同步服务器地址,且允许192.168.43.0/24网段的主机同步时间server s1a.time.edu.cn iburstserver s1b.time.edu.cn iburstserver s1c.time.edu.cn iburstserver s1d.time.edu.cn iburstallow 192.168.43.0/243:启动chronysystemctl enable chronyd.servicesystemctl start chronyd.service4:在node1和node2上分别安装chrony,且修改配置文件/etc/chrony.conf,将时间同步指向node0节点yum install -y chronyserver node0 iburst(配置文件里面修改)systemctl enable chronyd.servicesystemctl start chronyd.service5:node1,node2验证时间同步[root@node1 ~]# chronyc sources 210 Number of sources = 1MS Name/IP address Stratum Poll Reach LastRx Last sample ===============================================================================^* node0 3 6 17 6 -5684ns[-1595ns] +/- 401ms
(三)
高可用集群(服务配置)
pacemaker提供的管理程序有:(rpm -ql pacemaker)
/usr/libexec/pacemaker/cib(集群信息中心 cluster infomation base)
/usr/libexec/pacemaker/crmd(集群管理器)
/usr/libexec/pacemaker/lrmd(本地管理器)
在node1和node2节点安装corosync、pacemaker
安装pacemaker( corosync将会被作为依赖安装)yum install -y pacemaker
在node1上操作
cd /etc/corosync/cp corosync.conf.example corosync.conf
关于/etc/corosync/corosync.conf配置文件的介绍
1:totem { }:设置节点间的通信方式,通信协议,加密,通信的多播地址,且至少需要定义一个interface{}接口用来传递集群心跳信息2:loggin { }:设置格式,存储路径,记录的级别3:quorum { }: 设置投票信息4:nodelist { }:设置节点个数
由于在message layer层传递心跳信息需要加密,因此先必须生成加密文件
corosync-keygen
编辑配置文件/etc/corosync/corosync.conf,修改配置文件
(man corosync.conf 查看配置选项)
totem { version: 2 # 指定版本号 cluster_name: uplookingcluster # 指定集群名称 crypto_cipher: aes256 # 指定对称加密算法 crypto_hash: sha1 # 指定单向加密算法 interface { ringnumber: 0 # 指定心跳信息传递的环路id bindnetaddr: 192.168.43.0 # 指定环路中的网络地址 mcastaddr: 239.255.1.1 # 指定心跳信息通过多播的方式传递的IP通道 mcastport: 5405 # 指定多播的端口 ttl: 1 # 指定多播报文信息的生命周期 } } logging { fileline: off to_stderr: no to_logfile: yes # 指定开启日志文件 logfile: /var/log/cluster/corosync.log # 指定日志文件保存的位置 to_syslog: no # 指定不使用系统日志保存日志信息 debug: off timestamp: on logger_subsys { # 指定启用仲裁机制 subsys: QUORUM debug: off } } quorum { # 指定仲裁机制是corosync投票系统 provider: corosync_votequorum } nodelist { # 指定节点列表 node { ring0_addr: 192.168.43.10 nodeid: 1 } node { ring0_addr: 192.168.43.11 nodeid: 2 } }
将corosync.conf配置文件和生成的authkey文件复制到node2节点,注意authkey文件的权限必须是400才能启动corosync
scp authkey corosync.conf node2:/etc/corosync/
在node1和node2上分别启动corosync
systemctl enable corosync.servicesystemctl start corosync.service
在node1和node2上分别启动pacemaker
systemctl enable pacemaker.servicesystemctl start pacemaker.service
在node1节点上查看,当前集群中谁是DC(DC:Designated Coordinator 指定的协调员 负责管理集群的事务信息)
crm_mon
在node1和node2上配置crmsh的yum仓库,此仓库的RPM包有openSUSE提供,将这个network:ha-clustering:Stable.repo文件直接下载到本地并且命名为crmsh.repo
wget -O /etc/yum.repos.d/crmsh.repo http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/network:ha-clustering:Stable.repo
在node1和node2上通过yum安装crmsh
yum repolistyum install -y crmsh
在此可以使用crm命令进入交互式接口,实现对集群的管理操作
(四)
高可用集群(crmsh详解)
http://www.it165.net/admin/html/201404/2869.html
crmsh是pacemaker的命令行接口工具,执行help命令,可以查看shell接口所有的一级命令和二级命令,使用cd 可以切换到二级子命令的目录中去,可以执行二级子命令
在集群中的资源有四类:primitive主资源、group组资源、clone克隆资源、ms/master主从资源
在集群中的约束有三种:
①:location位置约束:资源间的依赖/互斥性,定义资源是否运行在同一节点上。score,正值表示要运行在同一节点上,负值则不可。
②:colocation排列约束:每个节点都有一个score值,正值则倾向于本节点,负值倾向于其他节点,所有节点score比较,倾向于最大值的节点。
③:order顺序约束:定义资源执行动作的次序,例如vip应先配置,httpd服务后配置。特殊的score值,-inf 负无穷,inf 正无穷。
查看命令帮助
(非常重要的命令用中文注释了)
crm(live)# helpHelp overview for crmshAvailable topics: Overview Help overview for crmsh Topics Available topics Description Program description CommandLine Command line options Introduction Introduction Interface User interface Completion Tab completion Shorthand Shorthand syntax Features Features Shadows Shadow CIB usage Checks Configuration semantic checks Templates Configuration templates Testing Resource testing Security Access Control Lists (ACL) Resourcesets Syntax: Resource sets AttributeListReferences Syntax: Attribute list references AttributeReferences Syntax: Attribute references RuleExpressions Syntax: Rule expressions Reference Command referenceAvailable commands: cd 切换命令层级,例如 cd cluster:切换到cluster二级命令 help 查看帮助 ls 列出命令层级和命令 quit 退出 report 报告 status 查看集群状态,可以有参数 help status 可以查看 up 回到上一个命令层级 verify 验证集群状态 assist/ Configuration assistant 配置集群代理 template Create template for primitives weak-bond Create a weak bond between resources cib/ CIB shadow management cibstatus CIB status management and editing commit Copy a shadow CIB to the cluster delete Delete a shadow CIB diff Diff between the shadow CIB and the live CIB import Import a CIB or PE input file to a shadow list List all shadow CIBs new Create a new shadow CIB reset Copy live cib to a shadow CIB use Change working CIB cibstatus/ CIB status management and editing load Load the CIB status section node Change node status op Edit outcome of a resource operation origin Display origin of the CIB status section quorum Set the quorum run Run policy engine save Save the CIB status section show Show CIB status section simulate Simulate cluster transition ticket Manage tickets cluster/ Cluster setup and management (重要) add 给集群添加节点 copy 拷贝文件到另外一个集群的节点 diff Diff file across cluster geo_init Configure cluster as geo cluster geo_init_arbitrator Initialize node as geo cluster arbitrator geo_join Join cluster to existing geo cluster health 集群的健康状态检查 init 初始化集群 join 加入到已经存在的集群 remove 从集群中移除一个节点 run 在所有集群节点执行一条命令 start 启动集群服务 status 集群状态检查 stop 停止集群服务 wait_for_startup Wait for cluster to start configure/ CIB configuration cib 集群配置(很重要,最重要的命令用中文注释了) acl_target Define target access rights alert Event-driven alerts cib CIB shadow management cibstatus CIB status management and editing clone 定义克隆资源 colocation 设置排列约束 commit Commit the changes to the CIB default-timeouts Set timeouts for operations to minimums from the meta-data delete Delete CIB objects edit 编辑集群配置文件,cib文件 erase Erase the CIB fencing_topology Node fencing order filter Filter CIB objects get_property Get property value graph Generate a directed graph group 定义组资源 load Import the CIB from a file location 设置位置约束 modgroup Modify group monitor Add monitor operation to a primitive ms 定义主从资源 node Define a cluster node op_defaults Set resource operations defaults order 设置顺序约束 primitive 定义主资源 property 设置集群的属性 ptest Show cluster actions if changes were committed refresh Refresh from CIB rename Rename a CIB object role Define role access rights rsc_defaults Set resource defaults rsc_template Define a resource template rsc_ticket Resources ticket dependency rsctest Test resources as currently configured save Save the CIB to a file schema Set or display current CIB RNG schema set Set an attribute value show Display CIB objects tag Define resource tags template Edit and import a configuration from a template upgrade Upgrade the CIB user Define user access rights validate-all Help for command validate-all validate_all Call agent validate-all for resource verify Verify the CIB with crm_verify xml Raw xml corosync/ Corosync management Corosync的管理 add-node Add a corosync node del-node Remove a corosync node diff Diffs the corosync configuration edit Edit the corosync configuration get Get a corosync configuration value log Show the corosync log file pull Pulls the corosync configuration push Push the corosync configuration reload Reload the corosync configuration set Set a corosync configuration value show Display the corosync configuration status Display the corosync status history/ Cluster history 设置集群的历史信息 detail Set the level of detail shown diff Cluster states/transitions difference events Show events in log exclude Exclude log messages graph Generate a directed graph from the PE file info Cluster information summary latest Show latest news from the cluster limit Limit timeframe to be examined log Log content node Node events peinputs List or get PE input files refresh Refresh live report resource Resource events session Manage history sessions setnodes Set the list of cluster nodes show Show status or configuration of the PE input file source Set source to be examined transition Show transition transitions List transitions wdiff Cluster states/transitions difference maintenance/ Maintenance mode commands 维护模式的命令 action Invoke a resource action off Disable maintenance mode on Enable maintenance mode node/ Node management 节点管理(很重要) attribute 管理、查看节点属性 clearstate Clear node state delete 删除节点 fence Fence 一个节点 maintenance Put node into maintenance mode online 让节点上线, 例如:node online node2 ready Put node into ready mode server Show node hostname or server address show 查看集群中的节点 standby 让一个节点standy,例如:node standby node1 status 查看集群中节点的状态 status-attr 管理集群中节点的属性 utilization Manage utilization attributes options/ User preferences add-quotes Add quotes around parameters containing spaces check-frequency When to perform semantic check check-mode How to treat semantic errors colorscheme Set colors for output editor Set preferred editor program manage-children How to handle children resource attributes output Set output type pager Set preferred pager program reset Reset user preferences to factory defaults save Save the user preferences to the rc file set Set the value of a given option show Show current user preference skill-level Set skill level sort-elements Sort CIB elements user Set the cluster user wait Synchronous operation ra/ 资源代理管理操作(很重要) classes 列出资源类别和提供者,例如:ra classes info 查看脚本的使用方法,例如:ra info IPaddr2 list 列出一个类别中有多少可用的资源代理,例如:ra list lsb 或 ra list ocf providers 查看特定资源代理有哪个提供者提供,例如:ra providers IPaddr2 validate Validate parameters for RA resource/ Resource management 资源管理(重要) ban Ban a resource from a node cleanup Cleanup resource status clear Clear any relocation constraint constraints Show constraints affecting a resource demote Demote a master-slave resource failcount Manage failcounts locate Show the location of resources maintenance Enable/disable per-resource maintenance mode manage Put a resource into managed mode meta Manage a meta attribute move 将某个资源迁移到哪个节点上去 operations Show active resource operations param Manage a parameter of a resource promote Promote a master-slave resource refresh Refresh CIB from the LRM status reprobe Probe for resources not started by the CRM restart Restart resources scores Display resource scores secret Manage sensitive parameters start Start resources status Show status of resources stop Stop resources trace Start RA tracing unmanage Put a resource into unmanaged mode untrace Stop RA tracing utilization Manage a utilization attribute script/ Cluster script management json JSON API for cluster scripts list List available scripts run Run the script show Describe the script verify Verify the script site/ GEO clustering site support ticket Manage site tickets template/ Edit and import a configuration from a template apply Process and apply the current configuration to the current CIB delete Delete a configuration edit Edit a configuration list List configurations/templates load Load a configuration new Create a new configuration from templates show Show the processed configuration
(五)
搭建高可用集群演示
(入门级别)
温馨提示①:使用crmsh配置集群有两种方式,最好使用第一种方式配置集群
第一种方式:进入crm的shell接口,使用命令进行配置,例如:cluster status
第二种方式:不进入crm的shell接口,直接在linux的shell接口输入:crm cluster status
温馨提示②:使用crmsh配置corosync + pacemaker 高可用集群的时候,在集群中任意的节点都可以,因为集群的任意节点都可以都到集群内部的配置信息
温馨提醒③:集群中的任何服务型资源,例如httpd,MySQL等都需要在节点上先安装,且开机自启,如果没有开机自启,crmsh将无法管理资源
实例演示:配置一个高可用的httpd服务
分析所需的资源: 1:vip 2:httpd 3:NFS(因为不同的httpd节点需要有相同的静态页面)分析启动次序:分析资源代理 vip:IPaddr(ifconfig命令实现)、IPaddr2(ip命令实现) httpd:systemd, ocf格式的apache NFS:Filesystem
什么是stonith设备
Stonith 即shoot the other node in the head使Heartbeat软件包的一部分,该组件允许系统自动地复位一个失败的服务器使用连接到一个健康的服务器的遥远电源设备。Stonith设备是一种能够自动关闭电源来响应软件命令的设备
由于无法模拟生成环境中的stonith设备,因此需要先禁用stonith设备,且配置完毕之后必须要提交
(温馨提示:使用vsphpere也可以虚拟出stonish设备)
[root@node1 ~]# crmcrm(live)# configure property stonith-enabled=falsecrm(live)# commit
1:配置vip资源
在configure二级命令接口处配置vip资源# 定义vip主资源,vip为资源的名称,ocf为资源类型,IPaddr为ocf资源类型下的IPaddr资源,ip、nic、cidr_netmask为IPaddr资源的参数。如果需要查看某个资源的定义,可以使用命令 ra info IPaddr 查看primitive vip ocf:IPaddr params ip=192.168.43.100 nic=enp0s3 cidr_netmask=24# 查看配置信息show # 提交配置,让配置生效,commit
- 再配置了IP资源后,此资源由于没有配置倾向性,因此一般会在当前所配置的节点上生效,在node1节点上配置的资源会在node1节点上生效
# 可以使用ip命令查看虚拟IP , 也可以使用crm status查看集群中的资源所在位置[root@node1 ~]# ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:df:0a:f1 brd ff:ff:ff:ff:ff:ff inet 192.168.43.10/24 brd 192.168.43.255 scope global enp0s3 valid_lft forever preferred_lft forever # 刚刚配置的vip在这里 inet 192.168.43.100/24 brd 192.168.43.255 scope global secondary enp0s3 valid_lft forever preferred_lft forever# 如果让node1节点成为备用节点,那么vip将会漂移到其他节点上[root@node1 ~]# crm node standy# 再次在node1节点查看vip,发现已经没有了[root@node1 ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:df:0a:f1 brd ff:ff:ff:ff:ff:ff inet 192.168.43.10/24 brd 192.168.43.255 scope global enp0s3 valid_lft forever preferred_lft forever[root@node1 ~]# # 在node2节点查看vip,发现vip已经漂移到node2节点上了[root@node2 ~]# ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:20:46:0a brd ff:ff:ff:ff:ff:ff inet 192.168.43.11/24 brd 192.168.43.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 192.168.43.100/24 brd 192.168.43.255 scope global secondary enp0s3 valid_lft forever preferred_lft forever# 重新让node1上线,在node1节点上,发现vip并没有重新漂移至node1节点,因为,vip资源没有设置倾向性[root@node1 ~]# crm node online# 将 vip资源迁移到node1上 ,再使用ip addr 发现vip 资源已经在node1上了[root@node1 ~]# crm resource move vip node1INFO: Move constraint created for vip to node1
2:配置httpd资源
1:在configure二级命令接口处配置httpd资源,在配置之前需要在各个节点安装上httpd,且开机自启,且为了测试,给node1节点和node2节点使用两个不同的测试首页yum install -y httpdsystemctl enable httpd.service2:在node1 和 node2 分别查看,是否有systemd类型的httpd资源,如果有说明可以使用httpd资源代理[root@node1 ~]# crm ra list systemd | grep httpdhttpd hypervkvpd hypervvssd ip6tables iptables3:可以查看一下httpd资源代理的使用帮助crm ra info systemd:httpd4:定义主资源httpd[root@node2 ~]# crm configure primitive httpd systemd:httpd[root@node2 ~]# crm configure commit5:查看资源配置情况crm verify6:查看下资源分布情况,发现vip运行在node1上, 而httpd运行在node2上,因此需要手动迁移资源的分布[root@node2 ~]# crm statuscrm(live)resource# move httpd node17:再次查看一下,资源的分布情况,此时vip、httpd资源都运行在node1之上了,使用浏览器可以访问到httpd提供的服务[root@node2 ~]# crm verify8:为了避免手动迁移资源,因此可以将必须运行在一起的primitive资源绑定到一个group资源里面crm(live)# configure group webservice vip httpdINFO: modified location:cli-prefer-vip from vip to webserviceINFO: modified location:cli-prefer-httpd from httpd to webservice9:查看集群配置的cib文件crm(live)# configure show 10:让node1成为备用节点,此时资源已经全部迁移到node2节点crm(live)# node standy 11:再让node1节点上线,迁移group资源到node1节点crm(live)resource# move webservice node112:可以直接编辑cib文件,配置集群资源信息crm configure edit
3:配置NFS资源
(重新启动一个虚拟机192.168.43.12,节点主机名为NFS)- 在NFS节点上配置
1:在NFS节点安装nfs-utilsyum install -y nfs-utils2:创建共享目录mkdir /data/3:编辑配置文件/etc/exports(这里使用了选择no_root_squash不压缩root权限,但是NFS一定不要添加这个选项,如果客户端要实现读写访问,必须给/data目录设置文件系统级别的访问权限)/data 192.168.0.0/16(rw, no_root_squash)4:启动nfssystemctl start nfs.serviceexportfs -r
- 在node1节点上配置
0:在node1上查看NFS节点的挂载情况showmount -e 192.168.43.131:查看资源代理Filesystem的使用帮助crm ra info ocf:Filesystem2:直接在node1的crm接口中配置NFS资源crm(live)configure# primitive nfs ocf:Filesystem parameters device="192.168.43.13:/data" directory="/var/www/html" fstype=nfs3:检查且提交crm(live)configure# verifycrm(live)configure# commit4:查看集群中的资源分布crm(live)# status5:将nfs资源添加到webservice组中,但是首先需要将webservice组删除,再创建,且资源启动顺序为:vip nfs httpd crm(live)configure# delete webservicecrm(live)configure# group webservice vip nfs httpd 6:检查语法,并且提交crm(live)configure# verifycrm(live)configure# commit7:再次查看集群状态crm(live)# status8:让node1处于备用状态crm(live)# node standy9:再次查看集群状态crm(live)# status10:其实也可以定义资源约束,例如设置vip对node2节点的倾向性为100,资源默认的倾向性为0,vip_node2为名称crm(live)configure# delete webservicecrm(live)configure# location vip_node2 vip 100: node211:同样可以配置组资源对节点的倾向性crm(live)configure# group webservice vip nfs httpdcrm(live)configure# location webservice_node1 webservice 100: node112:也可以使用colocation定义资源对资源的倾向性,vip_with_httpd是名称,inf:表示无穷大,vip资源在httpd资源的后面,说明:vip运行在哪个节点httpd就运行在哪个节点crm(live)configure# colocation vip_with_httpd inf: httpd vip13:也可以定义顺序约束,httpd_after_vip为约束名,mandatory:表示强制,表示vip必须在httpd资源前启动crm(live)configure# order httpd_after_vip mandatory: vip httpd14:虽然可以定义约束,但是最好将资源绑定在一个组里面,再定义组的约束
4:配置资源集群监控
# 如果此时的高可用集群的环境是 vip nfs httpd 都运行在node1,如果在node1停止httpd[root@node1 ~]# systemctl stop httpd# 再使用netstat -lntup查看的时候,httpd是不会自动启动的,因此在定义资源的同时需要定义监控,先停止httpd资源crm(live)# resource stop httpd# 编辑cib文件,删除所有的关于httpd资源的信息,因为httpd资源需要重新定义crm(live)# cofigure edit# 重新定义httpd资源,超时时长建议为100scrm(live)configure# primitive httpd systemd:httpd op start timeout=100s op stop timeout=100s op monitor interval=15s timeout=100s# 校验crm(live)configure# verify# 在编辑cib文件crm(live)configure# edit# 将新创建的资源添加至webservice资源组中,修改cib文件即可# 提交crm(live)configure# commit# 查看资源在节点的发布情况,发现httpd资源运行在node1节点上[root@node2 ~]# crm status# 在node1上停止httpd资源,看看是否httpd资源会自动重启,查看发现确实自动重启systemctl stop httpd
总结高可用集群解决方案
对于中小型业务模型而言,一般会有web服务、MySQL服务、邮件服务等等,一般这些服务都直接跑在物理服务器上,因此corosync + pacemaker 将会是很好的选择
实战作业:搭建lamp或lnmp高可用集群
要求:架构如上图所示,存储使用NFS共享存储,且NFS实现部分或keepalived高可用
(六)
共享存储解决方案
简单介绍Raid:磁盘阵列
(记得在淘宝、京东让大家看看什么是磁盘阵列,以及如何使用)
Raid一般有三种:一是外接式磁盘阵列柜(大型服务器,可以在淘宝、京东上购买)、二是内接式磁盘阵列卡(单台服务器),三是利用软件来仿真(一般不使用)
常见的raid解决方案:
- RAID0:
使其特别适用于对性能要求较高,而对数据安全不太在乎的领域,但是不提供数据冗余,因此一旦用户数据损坏,损坏的数据将无法得到恢复
- RAID1:
RAID 1的每一个磁盘都具有一个对应的镜像盘,系统可以从一组镜像盘中的任何一个磁盘读取数据,安全性高,但是空间只有磁盘容量总和的一半
- RAID10:
raid10是综合raid0特性和raid1特性的解决方案,但是也具有raid0和raid1的共同缺陷
- RAID5:
RAID 5 或 RAID 6 是一种存储性能、数据安全和存储成本兼顾的存储解决方案,没有完全使用RAID 1镜像理念,而是使用了"奇偶校验信息"来作为数据恢复的方式。RAID 5不对存储的数据进行备份,而是把数据和相对应的奇偶校验信息存储到组成RAID5的各个磁盘上,当RAID5的一个磁盘数据发生损坏后,利用剩下的数据和相应的奇偶校验信息去恢复被损坏的数据即可,图中的Ap、Bp、Cp、Dp就是"奇偶校验信息"
特别提醒:RAID5允许坏一块磁盘,RAID6允许坏两块块磁盘
磁盘整列RAID小总结
现在市场上买的新的机架式服务器一般都是2U最为常见,且每一台服务器内部都自带磁盘阵列卡,且默认是RAID5。因此单台服务器无需购买外挂式的raid
存储解决方案分类
1:集中式存储解决方案
①DAS:直接附加存储(适合单台服务器) 1:DAS指的是什么:指将存储设备通过SCSI接口或光纤通道直接连接到一台计算机上 2:DAS的适用哪些环境: a:服务器在地理分布上很分散,通过SAN或NAS在它们之间进行互连非常困难时。 b:存储系统必须被直接连接到应用服务器上时; c:只有单台服务器,存储设备无需与其他服务器共享。 3:代表作:IDE接口磁盘, SATA接口磁盘 , SCSI接口磁盘 , SAS接口磁盘,USB接口磁盘②NAS:网络附加储存(文件系统级别) 1:NAS指的是什么:一种专门的文件系统级别的储存解决方案,NAS存储系统通常由一个以上的硬盘提供,通常会把它们组成RAID(磁盘阵列)来提供服务 2:NAS只适合应用在较小的网络或者局域网内,当多台客户端访问NAS文件系统时,NAS的性能大大的下降,最终不能满足用户的需求。NAS后期的扩容成本高,一般的NAS没有高可用配置,但是能够自动实现锁机制 3:代表作品:NFS、Samba③SAN:存储区域网络(block 块级别) 1:SAN指的是什么:SAN存储通过光纤交换机将磁盘空间分配给不同的服务器,服务器通过以太网对外提供服务 2:SAN存储使用光纤网络进行传输,并且独立于应用网络,可以提供非常高的带宽,数据的传输基于块协议,无需对数据进行处理,直接进行传送,因此性能最好,另外光纤线路可以提供远距离的高带宽链路,可以实现数据中心的异地灾备应用,但是部署成本较高。因此SAN存储多应用于企业级的存储部署中,各个节点之间必须使用集群文件系统(GFS2)实现共享锁机制 3:代表作品:FC SAN、IP SAN
分布式存储分类
1:GlusterFS2:Ceph(内核级关系存储)3:MogileFS(海量图片共享存储)4:HDFS(Hadoop)5:TFS(淘宝开源)6:CFS(腾讯)
(七)
DRBD 详解
跨主机的块设备镜像系统,工作在内核中完成
drbd工作原理:客户端发起一个写操作的系统调用给文件系统,写请求再到达内核缓冲区,最到达DRBD模块,此时drbd会复制写入磁盘的数据,且进行两步操作,第一步操作是调用磁盘驱动,将数据写入本地的磁盘设备,第二部是通过网卡设备将数据发送给备用节点,备用节点的网卡接受到数据之后,将数据再发送给drbd模块,DRBD模块再调用磁盘驱动将数据写入磁盘。这就实现了数据写入的高可用
高可用集群都需要时间同步、主机名相互通信、ssh免密码登入(node1、node2两个节点已经ok)
安装DRBD(在node1,node2上都需要安装)
1:配置yum仓库vi /etc/yum.repos.d/drbd.repo[network_drbd]name=drbdbaseurl=http://elrepo.org/linux/elrepo/el7/x86_64/gpgcheck=0enabled=12:安装drbd内核模块、DRBD管理工具yum install -y drbd84-utils kmod-drbd843:给node1、node2添加一个虚拟磁盘,且分区5G[root@node2 ~]# fdisk -l 设备 Boot Start End Blocks Id System/dev/sdb1 2048 41945087 20971520 83 Linux4:编辑/etc/drbd.d/global_common.conf文件,修改如下配置即可global { # 指定不被DRBD官方纳入调研对象 usage-count no; # 指定udev策略 udev-always-use-vnr; # treat implicit the same as explicit volumes}common { handlers { } startup { } options { } disk { # 指定磁盘io出现错误的时候,拆除磁盘 on-io-error detach; } net { # 指定数据在drbd节点通信时,使用的加密算法 cram-hmac-alg "sha1"; # 指定密钥 shared-secret "UzcHlMYSw5o"; } # 指定drbd节点通信时,所使用的带宽 syncer { rate 1000M; }}5:编辑/etc/drbd.d/mariadb.res,创建drbd的工作方式,已经使用的资源resource mysql { # 指定drbd存储设备名称 device /dev/drbd0; # 指定实际的drbd使用的磁盘分区 disk /dev/sdb1; # 指定元数据存放值磁盘上 meta-disk internal; # 指定主节点 on node1 { address 192.168.43.10:7789; } # 指定从节点 on node2 { address 192.168.43.11:7789; }}6:将node1的配置文件拷贝一份到node2 scp -pr /etc/drbd.d/global_common.conf /etc/drbd.d/mariadb.res node2:/etc/drbd.d/7:在node1和node2上分别执行资源初始化(如果数据资源初始化不成功,可以尝试重启系统)drbdadm create-md mysql8:在node1和node2上启动DRBDsystemctl start drbd.service 9:查看节点同步情况drbd-overview10:让node1成为主节点 ,开始同步drbdadm primary --force mysql11:再次查看node1和node2节点数据同步情况drbd-overview12:等待同步完成之后,可以在node1节点直接在/dev/drbd0上创建文件系统,且挂载mkfs -t ext4 /dev/drbd0mount /dev/drbd0 /mnt13:向/mnt目录拷贝文件,卸载挂载点,让后将node1切换为从节点cp /etc/fstab /mntumount /dev/drbd0drbdadm secondary mysql14:在node2上执行命令,让node2为主, 挂载/mnt,查看是否在/mnt目录下存在/etc/fstabdrbdadm primary mysqlmount /dev/drbd0 /mnt
高可用Mariadb + DRBD
需求分析:配置一个Mariadb的高可用集群,且Mariadb的数据目录由DRBD存储提供1:分别在node1、node2中停止DRBD服务systemctl stop drbd.service2:如果想将drbd作为集群中的资源,那么drbd将不能开机自启,分别在node1、node2中让drbd禁止开机自启,systemctl disable drbd.service3:查看资源代理,这里的linbit为drbd代理的提供者crm(live)ra# list ocf linbitdrbd 4:查看ocf中drbd代理的使用帮助crm(live)ra# info ocf:drbd5:定义drbd在集群中的组资源primitive storage ocf:drbd params drbd_resource=mysql op monitor role=Master interval=15s timeout=20s op monitor role=Slave interval=10s timeout=20s6:将drbd资源设置为主从模式ms drbd_storage storage meta clone-max=2 clone-node-max=1 master-max=1 master-node-max=1
阅读全文
0 0
- linux集群高可用--crm
- heartbeat v2 crm 配置高可用集群
- Linux 高可用集群
- Linux集群,高可用keepalived
- LVS学习笔记 8 crm实现Mysql高可用集群
- linux高可用集群heartbeat实现http的高可用
- Linux-HA, heartbeat, 高可用集群,双机
- Linux-HA, heartbeat, 高可用集群,双机
- linux学习之高可用集群总结
- linux-hadoop高可用集群和Zookeeper
- linux高可用集群HA之pacemaker
- heartbeat v2 crm 及 NFS共享存储的mysql高可用集群
- Linux搭建高并发高可用Redis集群
- Linux高可用集群(一):Corosync/Openais + Pacemaker 实现高可用集群
- 高可用集群 HA
- Mysql高可用集群
- Rabbitmq集群高可用
- 高可用集群简介
- 315晚会召开在即,这些公司紧张得睡不着觉
- 时隔两年,微视终于“死”了但腾讯做短视频的心未死
- 品牌跨界新玩法 vivo 联合大 V 齐刷微博尾巴
- 我的学习记录17
- shell 处理json格式数据
- linux集群高可用--crm
- 计算机网络第4章 网络层(上)
- 315前夕,打假小程序“12315”上线
- WebService之jax-ws入门
- 【linux 学习】linux上的PhotoShop-Gimp(linux mint)
- 5. 1 IO流(字符流(6个),字节流(4个),(缓冲区装饰类(装饰设计模式)),(转换流))
- Javascript计算器(二)-简单的布局与美化
- Mybatis源码研究之SqlSource
- LaTex: 数学公式