监控安装 ERP

系统集成论坛

 找回密码
 注册通行证

QQ登录

只需一步,快速开始

路由器交换机防火墙系统集成商城 优质产品采购平台
查看: 2888|回复: 1
打印 上一主题 下一主题

SUSE Linux企业双机服务器搭建配置过程

  [复制链接]
跳转到指定楼层
1
发表于 2010-6-2 22:44:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
华为金牌代理
随着信息化建设的不断推进,各大企事业单位的活动越来越多的依赖于其关键的业务信息系统,这些业务信息系统对整个机构的运营和发展起着至关重要的作用,一旦发生宕机故障或应用停机,将给机构带来巨大的经济损失。Suse企业版里提供的HA软件是一款专业的高可用集群软件产品,它不仅仅是一款双机热备软件,它还为您提供Linux平台上完整的高可用性解决方案。

当集群中的某个节点由于软件或硬件原因发生故障时,集群系统可以把资源切换到其他健康的节点上,使整个系统能连续不间断的对外提供服务,从而为机构24x365的关键业务提供了可靠的保障,达到了系统99.999%的高可用性和可靠性。SuSE Enterprise Linux 10.0是内置Linux 2.6.16内核的企业级服务器,较之SuSE Enterprise Linux 9.0,它在性能、可扩展性、易管理性和安全等方面都予以加强,并有众多硬件和应用软件支持。

最近,笔者使用SuSE Enterprise Linux 10.0作为系统平台(使用其它Linux平台在安装部署时可能有小差异),在其上采用HeartBeat、Mon和Rsync等开源软件打造了一个高可用系统,挖掘了SuSE Linux的高可用性。下面我为大家详细介绍如何在Suse Linux搭建双机的配置过程。

一、 HeartBeat、Mon、Rsync简介

HeartBeat是一个高可用性解决方案,其官方网站是www.linux- ha.org。HeartBeat目前被广泛地应用,是很多商业高可用性软件的重要组成部分。大多数Linux厂商已经把它很好地集成在自己的系统中,例如SuSE Linux、RedHat和Debian Linux等。此外,HeartBeat也能很好地部署在Solaris和FreeBSD系统上。

Mon是一个后台服务运行情况的监控和告警软件,能够对大多数标准服务进行监控和告警,其中包括SMTP服务、Telnet服务、FTP服务、NNTP 服务、HTTP服务、POP3服务、Samba服务和NFS服务等,还可以自己编写告警事件和自定义服务。在本系统中,将使用Mon对两台主机的网络连接情况和服务运行情况进行监控,目的是及时告警,并且自动恢复服务。 Rsync是一个用于数据同步的软件,除了数据拷贝外,还有增量备份、同步owner、group和文件权限等重要信息的功能。在本系统中,使用 Rsync来同步主服务器和备用服务器的数据。

二、安装环境

首先,需要准备两台PC服务器,每台服务器有两块网卡,其物理网络图如图1

安装环境



图1 网络拓扑图

虽然在 YaST2控制中心里有"高可用性"图形化的配置向导,我们这里不介绍一个过程,中在讲述原理和方法,主要是基于命令行的配置方式。首先在PC服务器上安装SuSE Enterprise Linux 10.0系统,并将eth0配置为192.168.8.*网段,eth1配置为10.1.1.*网段,eth0链接对外的交换机,eth1用于两台机器的对连。

修改/etc /hosts文件,修改内容如下:

10.1.1.1 linux1  10.1.1.2 linux2  192.168.8.92 svr1  192.168.8.93 svr2  192.168.8.112 svr 注意,10.1.1.*为心跳线IP地址,192.168.8.*为对外IP,192.168.8.112为浮动IP。并且,拷贝hosts文件到 linux2上:

#scp /etc/hosts 10.1.1.2:/etc 同时,关闭不需要的服务如下:

chkconfig -s alsasound off  chkconfig -s nfs off  chkconfig -s nfsboot off  chkconfig -s portmap off  chkconfig -s slpd off  chkconfig -s smbfs off  chkconfig -s setserial off  chkconfig -s splash off  chkconfig -s splash_early off  chkconfig -s splash_late off  chkconfig -s xdm off  chkconfig -s fbset off  chkconfig -s cups off  chkconfig -s nscd off  chkconfig -s random off 最后,修改启动级别为3。找到/etc/inittab文件的如下几行:

#The default runlevel is defined here id:5:initdefault: 将其改为如下:

#The default runlevel is defined here id:3:initdefault:

三、安装HeartBeat

通过yast2工具添加heartbeat,如图片2

安装HeartBeat



图2 heartbeat安装

1)安装HeartBeat软件包。可以通过SuSE的光盘进行安装,安装命令如下:

#rpm -Uvh heartbeat-1.2.2-0.6.i586.rpm libnet-1.1.1-42.1.i586.rpm heartbeat-pils-1.2.2-0.6.i586.rpm heartbeat-stonith-1.2.2-0.6.i586.rpm 2)修改HeartBeat的配置文件

① 主配置文件/etc/ha.d/ha.cf

将/usr/share /doc/packages/heartbeat/目录下ha.cf、authkeys、haresources 三个文件考入/etc/ha.d/目录下,再将主配置文件/etc/ha.d/ha.cf修改如下:

node linux1  node linux2  keepalive 2  deadtime 30  warntime 10  initdead 120  auto_failback on  bcast eth1  ping 10.1.1.1  ping 10.1.1.2  respawn hacluster /usr/lib/heartbeat/ipfail ② 认证方式文件/etc/ha.d/authkeys

修改认证方式文件/etc/ha.d/authkeys如下:

auth 2  2 crc ③ 资源配置文件/etc/ha.d heresources

假设现在正在进行Apache服务的HA系统,这里设置的服务必须在/etc /ha.d/resource.d和/etc/rc.d/init.d下有响应的脚本。修改资源配置文件/etc/ha.d/haresources如下:

linux1 192.168.8.112 apache2 ④ 拷贝配置文件到linux2

#scp /etc/ha.d/ha.cf 10.1.1.2:/etc/ha.d  #scp /etc/ha.d/authkeys 10.1.1.2:/etc/ha.d  #scp /etc/ha.d/haresources 10.1.1.2:/etc/ha.d 3)启动HeartBeat服务:

#chkconfig -s heartbeat on  #chmod 600 /etc/ha.d/authkeys  #/etc/init.d/heartbeat start 系统显示信息如下:

Starting High-Availability servicesheartbeat:2010/4/01_23:05:19 info: Neither logfile nor logfacility found.  heartbeat: 2010/4/01_23:05:19 info: Logging defaulting to /var/log/ha-log  heartbeat: 2010/4/01_23:05:19 info:**************************  heartbeat: 2010/4/01_23:05:19 info:Configuration validated.Starting heartbeat 1.2.2  done 通过运行"ps -ef|grep heartbeat"命令来查看进程:

root 4240 1 0 23:25 ? 00:00:01 heartbeat:heartbeat:master control process  nobody 4242 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:FIFO reader  nobody 4243 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:write:bcast eth1  nobody 4244 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:bcast eth1  nobody 4245 4240 0 23:05 ?00:00:00 heartbeat:heartbeat:write:ping 10.1.1.1  nobody 4246 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:ping 10.1.1.1  nobody 4247 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:write:ping 10.1.1.2  nobody 4248 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:ping 10.1.1.2  haclust 4254 4240 0 23:07 ? 00:00:00 /usr/lib/heartbeat/ipfail 1 安装Apache

1)安装Apache和相关软件包如下:

#rpm -Uvh apahe2-2.0.49-27.8.i586.rpm apache2-prefork-2.0.49-27.8.i586.rpm libapr0-2.0.49-27.8.i586.rpm  #SuSEconfig --module apache2 2)启动Apache:

/etc/init.d/apache2 start 并运行"ps -ef|grep apache"查看进程:

root 4387 1 10 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf  wwwrun 4388 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf  wwwrun 4389 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf  wwwrun 4390 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf  wwwrun 4391 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf  wwwrun 4392 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf 3)创建并编辑一个index.html文件:

#vi /srv/www/htdocs/index.html 在其中输入"linux ha"的字样,并保存退出。通过Client端访问浮动IP:192.168.8.112,在linux1上成功安装Apache服务后,在linux2 上执行以上操作,并且同样测试其结果如图3。

安装HeartBeat



图3 linux上的测试结果

四、测试HA系统

首先,关闭linux1的网络服务(也可以使用shutdown):

#/etc/init.d/network stop

然后,查看linux2的log文件。正确结果是HA系统发现linux1已经 dead,由linux2接替其工作。

#tail -f /var/log/ha-log  heartbeat: 2010/4/02_14:18:16 WARN: node 10.1.1.1:is dead  heartbeat: 2010/4/02_14:18:16 info: Link 10.1.1.1:10.1.1.1 dead................  heartbeat: 2010/4/02_14:18:27 info: mach_down takeover complete.  heartbeat: 2010/4/02_14:18:27 info: mach_down takeober complete for node linux1.  heartbeat: 2010/4/02_14:18:27 ERROR: Both machines own our resources! 同时,在linux2上面检查浮动IP,此时浮动IP应该绑定在linux2上。用"ifconfig"查看如图3示。

这时,通过Client端访问浮动IP:192.168.8.112,HTTP服务正常。

Eth0:0 Link encap:Ethernet HWaddr 00:0C:29:35:E6:63  Inet addr:192.168.0.112 bcast:192.168.9.255 Mask:255.255.254.0  Interrupt:9 Base address:0x1000 重新启动linux1的网络服务,浮动IP将又重新绑定到 linux1。此时通过Client端访问浮动IP:192.168.8.112,HTTP服务同样正常。

五、Mon服务监控

使用Mon可以实现监控网络、监控服务、E-mail告警和自动重启服务等。

1) 安装Mon软件及其相关软件包。

从光盘安装Time-period、Convert-BER、perl-Mon和fping:

#rpm -Uvh perl-Time-period-1.20-301.1.i586.rpm perl-Convert-BER-1.3101-190.1.i586.rpm perl-Mon-0.11-294.1.i586.rpm fping-2.2b1-819.1.i586.rpm 从www.cpan.org下载并安装Time-HiRes:

#tar xvzf Time-HiRes-1.65.tar.gz  #3cd Time-HiRes-1.65/perl Makefile.PL && make &&make test && make install 从www.kernel.org/software/mon/下载并安装软件包mon-0.99.2.tar.bz2:

#tar xvjf mon-0.99.2.tar.bz2  #cp -r mon-0.99.2 /usr/lib/mon  #mkdir /etc/mon  #cp /usr/lib/mon/etc/auth.cf /etc/mon 2) 编辑/etc/mon/mon.cf文件:

cfbasedir = /etc/mon  alertdir = /usr/lib/mon/alert.d  mondir = /usr/lib/mon/mon.d  statedir = /usr/lib/mon/state.d  logdir = /usr/lib/mon/log.d  dtlogfile = /usr/lib/mon/log.d/dt.log  maxprocs = 20 histlength = 100 randstart = 60s dtlogging = yes authtype = getpwnam hostgroup servers 10.1.1.1 10.1.1.2  hostgroup www 10.1.1.1  watch servers  service ping  interval 1m  monitor fping.moniter  period wd {Sun-Sat}  alert mail.alert 97140@263.com (请指定邮件地址)  watch www  service http  interval 1m  monitor http.monitor  period wd {Sun-Sat}  alert apacherestart.alert  alert mail.alert 97140@263.com (请指定邮件地址) 然后编辑/ust/lib/mon/alert.d /apacherestart.alert文件:

#!/bin/sh  /etc/init.d/apache2 restart  chmod +x /usr/lib/mon/alert.d/apacherestart.alert 同样地,在linux2完成以上步骤。但注意,在配置/etc/mon/mon.cf时,"hostgroup www 10.1.1.1"应设置为"hostgroup www 10.1.1.2"。

在两台服务器上分别安装和配置完成后,启动Mon服务:

#/usr/lib/mon/mon -c /etc/mon/mon.cf & 查看log文件,检查服务状态:

#tail /var/log/messages  Nov 2 17:15:20 linux mon[14079]: mon server started 运行"ps -ef|grep mon"查看进程,可以看到Mon服务成功启动。

root 14079 1 0 17:15 ? 00:00:00 /usr/bin/perl/usr/lib/mon/mon -c/etc/mon/mon.cf 3)对Mon服务进行测试。

① 测试Apache服务的邮件告警和服务重启功能

先关闭linux1的Apache服务:

#/etc/init.d/apache2 stop 查看log文件,检查Mon服务的处理步骤。Mon首先发现WWW服务不能访问,然后重启Apache服务,并且发Email到指定的邮箱。

log文件内容如下:

Nov 2 17:15:59 linux mon[14079]: failure for www http 1099386959 10.1.1.1  Nov 2 17:15:59 linux mon[14079]: calling alert apacherestart.alert for www/http(/usr/lib/mon/alert.d/apacherestart.alert,) 10.1.1.1  Nov 2 17:16:03 linux mon[14079]: calling alert mail.alert for www/http(/usr/lib/mon/alert.d/mail.alert,song@heming.org) 10.1.1.1 邮件内容则如下:

ALERT www/http: 10.1.1.1(Tue Nov 2 17:16:03)(标题)   
Sunmmary output : 10.1.1.1   
Group : www   
Service : http   
Time noticed : Tue Nov 2 17:16:03 2004   
Secs until next alert :   
Members : 10.1.1.1   
Detailed text (if any) follows:   
HOST 10.1.1.1: connect: Connection refused  
② 测试网络监控和警告

关闭linux1的网络服务:

#/etc/init.d/network stop Mon会发送告警邮件到指定邮箱,邮件内容略。

六、数据同步

假设这里只更新linux1服务器上的数据,由linux1定时向linux2复制数据,这就需要进行数据同步设置。

首先,设置linux1到linux2的SSH无密码登录:

#ssh-keygen -t dsa  #scp /root/.ssh/id_dsa.pub 10.1.1.2:/root/.ssh/authorized_keys  #ssh 10.1.1.2 (应该不用输入密码就能登录) 然后,在linux1上运行Rsync进行数据同步:

#/usr/bin/rsync -avzoge ssh /srv/www/htdocs 10.1.1.2:/srv/www/htdocs 这时会显示如下内容:

building file list ... done 将数据同步服务加入到Crontab,设置30分钟(时间可以根据具体需要决定)定时数据同步一次。命令如下:

#crontab -e  */30 * * * * /usr/sbin/rsync -avzoge ssh 10.1.1.2:/srv/www/html 至此,具有数据同步、服务监控的高可用性服务系统搭建完成。


来源:IT168

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册通行证

x
我分享,我成长!系统集成 XTJC.COM
2
发表于 2010-8-2 11:01:24 | 只看该作者
华为金牌代理
支持!!!!
您需要登录后才可以回帖 登录 | 注册通行证

本版积分规则

联系我们| 手机版|系统集成论坛 ( 京ICP备11008917号 )

GMT+8, 2024-9-30 20:30 , Processed in 0.096638 second(s), 27 queries .

系统集成论坛

BBS.XTJC.COM

快速回复 返回顶部 返回列表