导航

不许杀人,也不许放火

« 简单主备结构的反向WEB缓存(1)简单主备结构的反向WEB缓存(3) »

简单主备结构的反向WEB缓存(2)

找了两台低端服务器做实验,centos4.6,双网卡,一个接外网,一个用来心跳监测。
两台机器,机器名分别为cache1和cache2,也就是uname -n看到的,在hosts里加上另外一台机器,以便通过ping cache1和ping cache2能通
安装heartbeat
为了省事,直接用yum安装,很方便
yum install heartbeat

装完heartbeat-2.1.3以后,在/etc/ha.d目录下编辑一个ha.cf,内容是
use_logd yes
auto_failback on
bcast   eth1
node cache1 cache2
crm on

心跳监测通过eth1进行。

编辑一个logd.cf,内容是
logfacility     daemon

编辑一个authkeys,内容是
auth 1
1 sha1 mykeystring

把authkeys属性改成600。

配置文件的其他项目这里都用默认值了。
也可以从/usr/share/doc/heartbeat-2.1.3下复制这两个配置文件的样板来根据需要修改。

为了实现地址浮动,需要在/var/lib/heartbeat/crm目录下做一个cib.xml,用来描述资源管理。
我是在原来缺省的文件上修改的
增加部分为:
    <resources>
      <primitive id="ip_resource" class="ocf" type="IPaddr" provider="heartbeat">
        <instance_attributes>
          <attributes>
            <nvpair name="ip" value="192.168.111.10"/>
             <nvpair name="nic" value="eth0"/>
             <nvpair name="cidr_netmask" value="26"/>
          </attributes>
        </instance_attributes>
      </primitive>
    </resources>
    <constraints>
      <rsc_location id="run_ip_resource" rsc="ip_resource">
        <rule id="pref_run_ip_resource" score="100">
          <expression attribute="#uname" operation="eq" value="cache1"/>
        </rule>
      </rsc_location>
    </constraints>

   
上面的主要意思应该也就是加一个IP地址资源,这个IP地址是192.168.11.10,也就是两个CACHE上的浮动地址,这个浮动地址是在eth0上的。主用是在cache1上。
这个配置是在cache1上的。
cache2上的配置和cache1上差不多,ha.cf,logd.cf,authkeys内容都是一样的。

配置完成后,在rc.local里写上/etc/init.d/heartbeat start,然后两台机器都重启一下。
这时候可以用crm_mon看一下,我的输出是这样的,cache1上:
Last updated: Sat Apr 12 20:12:07 2008
Current DC: cache2 (b3b95984-acb7-4ca6-ab40-c9a6c18e192a)
2 Nodes configured.
1 Resources configured.
============

Node: cache2 (b3b95984-acb7-4ca6-ab40-c9a6c18e192a): online
Node: cache1 (15347a3b-44a4-4eb3-5ab1-e6cf15fab0b4): online

ip_resource     (heartbeat::ocf:IPaddr):        Started cache1


cache2上的输出:
Last updated: Sat Apr 12 20:08:13 2008
Current DC: cache2 (b3b95984-acb7-4ca6-ab40-c9a6c18e192a)
2 Nodes configured.
1 Resources configured.
============

Node: cache2 (b3b95984-acb7-4ca6-ab40-c9a6c18e192a): online
Node: cache1 (15347a3b-44a4-4eb3-5ab1-e6cf15fab0b4): online

ip_resource     (heartbeat::ocf:IPaddr):        Started cache1
这时候主用在cache1上,在cache1上用ifconfig能看到浮动地址。

如果这时候我重启cache1,来模拟宕机,在cache2上crm_mon输出
Last updated: Sat Apr 12 20:14:35 2008
Current DC: cache2 (b3b95984-acb7-4ca6-ab40-c9a6c18e192a)
2 Nodes configured.
1 Resources configured.
============

Node: cache2 (b3b95984-acb7-4ca6-ab40-c9a6c18e192a): online
Node: cache1 (15347a3b-44a4-4eb3-5ab1-e6cf15fab0b4): OFFLINE

ip_resource     (heartbeat::ocf:IPaddr):        Started cache2

这时候在cache2上ifconfig能看到浮动IP已经到了cache2上。
当cache1启动起来回复正常以后,浮动IP又回到了cache1上。

我的E文也很烂,看heartbeat文档半懂不懂的,特别是cib.xml部分,看了两个小时一点头绪都没有,糊里糊涂乱写乱一通,竟然成了,自己都觉得神奇。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Search

控制面板

首页

最近发表

Powered By Z-Blog