heartbeat实现高可用集群(1)

环境
   node1 192.168.1.35
   node2 192.168.1.36
   fip 192.168.1.80
   daemon httpd
  nfs 192.168.1.15 
配置HA集群的前提
  1.节点时间必须同步,使用ntp协议实现
  2.节点间需要通过主机互相通信,必须解析主机名至IP地址
    a.建议名称解析功能能使用hosts文件实现
     b.通信中使用的名字与节点名字必须保持一致
  3.考虑仲裁设备是否会用到
  4.建立各节点之间的root用户能够基于密钥认证
    # ssh-keygen -t rsa -P ''
    # ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.36
[[ heartbeat v2 + haresources(v1)]]
node1&node2(centos 6)
# yum install net-snmp-libs libnet PyXML
# rpm -ivh heartbeat-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
配置文件:/etc/ha.d目录下
             ha.cf:主配置文件,定义各节点上的heartbeat HA集群的基本属性
             authkeys:集群内各节点彼此传递消息时使用加密算法 及密钥
             haresources:为heartbeat v1提供资源管理器配置接口;v1版本专用的配置接口
         样例:/usr/share/doc/hearbeat-2.1.4/目录下
node1
# cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,haresources,authkeys} /etc/ha.d/
# ll
# chmod 600 authkeys
# vim authkeys(指明启用那种算法,使用的密钥是什么)
     auth 2
     2 sha1 gbpNZ/hvE89KxPqjyHclmn(openssl rand -base64 16)
# vim ha.cf
     logfile  /var/log/heartbeat.log (日志)
     mcast eth0 225.13.180.1 694 1 0
     auto_failback on 
     node     node1(指明节点名,必须与uname -n保持一致)
     node     node2
     ping 192.168.0.1(仲裁设备)
     compression    bz2 (指明节点间传递信息的压缩算法)
     comprehensive_threshold 2 (压缩时的起点,单位KB)
# vim haresource (定义集群资源)(对资源的管理要使用资源代理)
     node1   192.168.1.80/24/eth0/192.168.255.255 httpd
# scp -p authkeys ha.cf haresources node2:/etc/ha.d/
node1&node2
# yum install httpd -y
# echo "<h1>node1.com</h1> > /var/www/html/index.html (node1)
# echo "<h1>node2.com</h1> > /var/www/html/index.html (node2)
# service httpd stop
# curl 192.168.1.35
  <h1>node1.com</h1>
# service httpd stop
# chkconfig httpd off (开机不自启)
# service heartbeat start
# ss -tunl
   :694
浏览器访问192.168.1.80
nfs
# mkdir -pv /web/htdocs
# echo "<h1>Page on NFS server</h1>" > /web/htdoc/index.html
# vim /etc/exports(共享文件)
  /web/htdocs 192.168.0.1/24(rw,no_root_squash)
# service nfs service
# chkconfig nfs on
node1
# cd
# service heartbeat stop; ssh node2 'service heartbeat stop'
# cd /etc/ha.d/
node1&2
# mount -t nfs 192.168.1.15:/web/htdocs /var/www/html
# mount 
  192.168.1.15:/web/htdocs on /var/www/html type nfs (rw,vers=4,addr=192.168.1.15,clientaddr=192.168.1.35)
# service httpd restart
浏览器访问192.168.1.35及192.168.1.36
# service httpd stop
# umount /var/www/html/
node1
# ls
# pwd
  /etc/ha.d
# ls resource.d/
  Filesystem     (文件系统的资源代理)
# vim haresources
  node1 192.168.1.80/24/eth0/192.168.255.255 Filesystem::192.168.1.15:/web/htdocs::/var/www/html::nfs httpd
  (Filesystem::192.168.1.15:/web/htdocs::/var/www/html::nfs Filesystem::要挂载的设备::挂载点::文件系统类型)
# scp -p haresources node2:/etc/ha.d
# service heartbeat start; ssh node2 'service heartbeat start'
# ss -tnl
# ifconfig
# mount 
# tail /var/log/heartbeat.log 
# /usr/lib64/heartbeat/hb_standby  让节点变成备用模式
node2
# tail /var/log/heartbeat.log
# ss -tnl
# ifconfig
# mount 
# /usr/lib64/heartbeat/hb_standby
node1
# /usr/lib64/heartbeat/hb_takeover





原创文章,作者:nene,如若转载,请注明出处:http://www.178linux.com/88196

(0)
nenenene
上一篇 2017-11-02 18:08
下一篇 2017-11-03 16:22

相关推荐

  • 进程管理(二)之计划任务

    进程管理(二)之计划任务   一、计划任务: 1、未来的某时间点执行一次任务: (1)at:跟一个时间点,到点了自动运行指定的任务 (2)batch:系统自行选择空闲时间去执行此处指定的任务 2、周期性运行某任务:cron 二、at命令: 1、at命令:at [option] TIME 注:当输入完成后,使用Ctrl+d结束,不能使用Ctrl+c …

    Linux干货 2016-09-10
  • mysqld_multi 多实例部署

    序言:多实例?Why?   随着硬件层面的发展,linux系统多核已经是普通趋势,而mysql是单进程多线程,所以先天上对多进程的利用不是很高,虽然5.6版本已经在这方面改进很多,但是也没有达到100%,所以为了充分的利用系统资源,mysql有自己的补充,那就是可以部署多实例,一个实例一个端口。     1,准备好mysql环境…

    2017-11-16
  • ~~ 1;列出当前系统上所有已经登录的用户的用户名,注意:同一用户登录多次,则只显示 一次即可。 # who | cut -d" " -f 1 | sort -u 2;取出最后登录到当前系统的用户的相关信息 # id $(who | tail -1 |cut -d" " -f 1) # last | head -1 3…

    Linux干货 2017-01-03
  • grep虐我千百遍,我待grep如初恋

    N21第四周博客作业 1、  复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@Centos6 ~]# cp -r /etc/skel /home/tuser1 [root@Centos6 ~]#…

    Linux干货 2016-07-16
  • 集群-ipvsadm和NAT实验(3)

    纠正:报文进入内核空间后,当到达input链时发现是一个集群服务时,则直接发送到postrouting链,不经过forward链。 调度算法: 1、静态方法: rr:轮询,即依照次序从所有RS中进行挑选 wrr:加权轮询,按照权重在RS中进行轮询 sh:source hashing,源地址哈希,即对来自相同客户端的请求发送至同一RS,这样会破坏负载均衡效果。…

    Linux干货 2015-12-15
  • PHP5.4最新特性

    原文Oracle:LAMP 体系有了新的竞争,但此版本中的特性使 PHP 再次挑战极限。 稍微做了修改。: 概述总结:1. 内存和性能改进:大型 PHP 应用程序中可节省 20-50% 的内存。通过各种优化使性能提高 10-30%2. 支持特性Trait3. 精简数组语法,可以定义短数组4. 函数数组解除引用,支持Array dereferenci…

    Linux干货 2015-11-18