Heartbeat v1 版讲解及实现NFS文件共享(3)

data -s mm/dd/yy hh/mm/ss

ssh node2. "date -s '20140914 23:12:30'";date -s '20140914 23:12:30'

前提是做好下面两步才可以使用上面的命令

修改hostname

vim /etc/hosts

192.168.1.11 node1. node1

192.168.1.12 node2. node2

2、两边都修改,我们可以ping 一下node1 测试一下是不是本机ip地址

3、基于密钥认证两台机能相互不输入密码登录

ssh-keygen -t rsa

ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2.  可能会出错

我们可以用另外一条命令来复制

ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2的ip地址就不会出错啦

两边都生成,发给对方,这里的话我们可以测试一下是否基于密钥认证成功

ssh node1.linuxidc.com 'date';date

4、软件安装

yum 安装四个包有依赖问题,所以只能先解决依赖

yum install perl-TimeDate PyXML libnet net-snmp-libs

这里的话安装libnet包没有,不知道咋办,以至于后面的包都无法安装

所于一定要搭建到yum源 libnet 在extra中

yum install 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

cd ~

scp -r heartbeat2/ node2:/root

node2

一样安装软件

yum install perl-TimeDate PyXML libnet net-snmp-libs

yum install 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

5、主要配置讲解

配置组播地址  224.0.1.0--238.255.255.255

grep  694  /etc/services

ha.cf  主配置文件

authkeys  认证密钥,其权限必须为组和它无权访问

haresources 用于资源的文件

cd /etc/ha.d

ls

cp /usr/share/doc/heartbeat-2.1.4/{ha.cf,haresources,authkeys} ./

chmod 600 authkeys

cd /etc/ha.cf

6、具体配置

vim ha.cf

启用

logfile /var/log/ha-log 日志

ompression_threshold 2  压缩

mcast eth0  225.100.90.101 694 1 0  广播地址

node  node1.

node  node2.  配置节点

ping 172.16.0.1  一般为网关  ping网关

vim  authkeys      认证密钥

auth  2

2 sha1    xxxxx      随机码  openssl rand  -hex  8

vim  haresources

在  virtual

定义资源

主资源  vip(流动ip)/子网/网卡别名/广播地址 第二个资源  同进同退

node1.linuxidc.com 172.16.100.23/16/eth0/172.16.255.255 httpd

确保有httpd 资源

定义资源ip脚本

ls /etc/ha.d/resource.d

IPaddr 和 IPaddr2

资源httpd的脚本

就是/etc/rc.d/init.d/httpd

scp -p ha.cf haresources authkeys node2:/etc/ha.d

节点二配置把节点一的脚本发过去给他就可以啦

vim /var/www/html/index.html 提供网页

测试一下  curl

关闭服务  service httpd stop

开机不要启动

chkconfig  httpd off

节点2 一样配置定义httpd资源

实验结果测试

主节点

service  heartbeat start

ss -unl  694

ssh  node2.linuxidc.com 'service heartbeat start'

tail  -f  /var/log/ha-log

节点2上看 ss -unl  694

ifconfig  看流动ip 配置上去没有

service  heartbeat stop

网页测试是否成功

6、扩展配置

共享mysql存储设备提供给网页,做web的高可用

172.16.1.143

vim /etc/exports

/www/html  172.16.0.0/16(no_root_squash,rw)

节点上挂载测试网页是否正常

mount -t nfs 172.16.1.143:/www/html /var/www/html

curl 本机web服务

关闭全部节点上的 service heartbeat stop

重新定义资源

vim etc/ha.d/haresources

node1.linuxidc.com 172.16.100.23/16/eth0/172.16.255.255 Filesystem::172.16.100.9:/var/www/html::/var/www/html::nfs  httpd

scp haresources node2:/etc/ha.d/

service haretbeat start

ssh node2.linuxidc.com 'service heartbeat start'

mount

ifconfig

mount

7、测试

离线一个节点

测试网页

重启此节点,再离线另一个节点测试

ss -unl

另外一个命令的使用

cd /usr/lib64/heartbeat

hb_standby

hb_takeover

heartbeat v2  配置

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b8e1a9b84bb0316edd3f1375b98b95af.html