SUSELinux搭建企业服务器的双机配置过程
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
SUSE 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简介
二、安装环境
首先,需要准备两台PC服务器,每台服务器有两块网卡,其物理网络图如图 1
安装环境
图1 网络拓扑图
虽然在YaST2控制中心里有"高可用性"图形化的配置向导,我们这里不介绍一个过程,中在讲述原理和方法,主
要是基于命令行的配置方式。
首先在PC服务器上安装SuSE Enterprise Linux 10.0系统,并将eth0配置为192.168.8.*网段,eth1配置为10.1.1.*网段,eth0链接对外的交换机,eth1用于两台机器的对连。
修改/etc /hosts文件,修改内容如下:
1.10.1.1.1 linux1
2.10.1.1.2 linux2
3.192.168.8.92 svr1
4.192.168.8.93 svr2
5.192.168.8.112 svr
注意,10.1.1.*为心跳线IP地址,192.168.8.*为对外IP,192.168.8.112为浮动IP。
并且,拷贝hosts文件到linux2上:
1.#scp /etc/hosts 10.1.1.2:/etc
同时,关闭不需要的服务如下:
1.chkconfig -s alsasound off
2.chkconfig -s nfs off
3.chkconfig -s nfsboot off
4.chkconfig -s portmap off
5.chkconfig -s slpd off
6.chkconfig -s smbfs off
7.chkconfig -s setserial off
8.chkconfig -s splash off
9.chkconfig -s splash_early off
10.chkconfig -s splash_late off
11.chkconfig -s xdm off
12.chkconfig -s fbset off
13.chkconfig -s cups off
14.chkconfig -s nscd off
15.chkconfig -s random off
最后,修改启动级别为3。
找到/etc/inittab文件的如下几行:
1.#The default runlevel is defined here id:5:initdefault:
将其改为如下:
1.#The default runlevel is defined here id:3:initdefault:
三、安装HeartBeat
通过yast2工具添加heartbeat,如图片 2
安装HeartBeat
图2 heartbeat安装
1)安装HeartBeat软件包。
可以通过SuSE的光盘进行安装,安装命令如下:
1.#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修改如下:
1.node linux1
2.node linux2
3.keepalive 2
4.deadtime 30
5.warntime 10
6.initdead 120
7.auto_failback on
8.bcast eth1
9.ping 10.1.1.1
10.ping 10.1.1.2
11.respawn hacluster /usr/lib/heartbeat/ipfail
②认证方式文件/etc/ha.d/authkeys
修改认证方式文件/etc/ha.d/authkeys如下:
1.auth 2
2. 2 crc
③资源配置文件/etc/ha.d heresources
假设现在正在进行Apache服务的HA系统,这里设置的服务必须在/etc /ha.d/resource.d和/etc/rc.d/init.d下有响应的脚本。
修改资源配置文件/etc/ha.d/haresources如下:
1.linux1 19
2.168.8.112 apache2
④拷贝配置文件到linux2
1.#scp /etc/ha.d/ha.cf 10.1.1.2:/etc/ha.d
2.#scp /etc/ha.d/authkeys 10.1.1.2:/etc/ha.d
3.#scp /etc/ha.d/haresources 10.1.1.2:/etc/ha.d
3)启动HeartBeat服务:
1.#chkconfig -s heartbeat on
2.#chmod 600 /etc/ha.d/authkeys
3.#/etc/init.d/heartbeat start
系统显示信息如下:
1.Starting High-Availability servicesheartbeat:2010/4/01_23:05:19 info: Neither logfile nor l
ogfacility found.
2.heartbeat: 2010/4/01_23:05:19 info: Logging defaulting to /var/log/ha-log
3.heartbeat: 2010/4/01_23:05:19 info:**************************
4.heartbeat: 2010/4/01_23:05:19 info:Configuration validated.Starting heartbeat 1.2.2
5.done
通过运行"ps -ef|grep heartbeat"命令来查看进程:
1.root 4240 1 0 23:25 ? 00:00:01 heartbeat:heartbeat:master control process
2.nobody 4242 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:FIFO reader
3.nobody 4243 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:write:bcast eth1
4.nobody 4244 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:bcast eth1
5.nobody 4245 4240 0 23:05 ?00:00:00 heartbeat:heartbeat:write:ping 10.1.1.1
6.nobody 4246 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:ping 10.1.1.1
7.nobody 4247 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:write:ping 10.1.1.2
8.nobody 4248 4240 0 23:05 ? 00:00:00 heartbeat:heartbeat:read:ping 10.1.1.2
9.haclust 4254 4240 0 23:07 ? 00:00:00 /usr/lib/heartbeat/ipfail
1 安装Apache
1)安装Apache和相关软件包如下:
1.#rpm -Uvh apahe2-
2.0.49-27.8.i586.rpm apache2-prefork-2.0.49-27.8.i586.rpm libapr0-2.0.49-2
7.8.i586.rpm
2.#SuSEconfig --module apache2
2)启动Apache:
1./etc/init.d/apache2 start
并运行"ps -ef|grep apache"查看进程:
1.root 4387 1 10 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
2.wwwrun 4388 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
3.wwwrun 4389 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
4.wwwrun 4390 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
5.wwwrun 4391 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
6.wwwrun 4392 4387 0 23:33 ? 00:00:00 /usr/sbin/httpd2-prefork -f /etc/apache2/httpd.conf
3)创建并编辑一个index.html文件:
1.#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接替其工作。
1.#tail -f /var/log/ha-log
2.heartbeat: 2010/4/02_14:18:16 WARN: node 10.1.1.1:is dead
3.heartbeat: 2010/4/02_14:18:16 info: Link 10.1.1.1:10.1.1.1 dead................
4.heartbeat: 2010/4/02_14:18:27 info: mach_down takeover complete.
5.heartbeat: 2010/4/02_14:18:27 info: mach_down takeober complete for node linux1.
6.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服务正常。
1.Eth0:0 Link encap:Ethernet HWaddr 00:0C:29:35:E6:63
2.Inet addr:192.168.0.112 bcast:192.168.9.255 Mask:255.255.254.0
3.Interrupt:9 Base address:0x1000
重新启动linux1的网络服务,浮动IP将又重新绑定到linux1。
此时通过Client端访问浮动IP:192.168.8.112,HTTP 服务同样正常。
五、Mon服务监控
1) 安装Mon软件及其相关软件包。
从光盘安装Time-period、Convert-BER、perl-Mon和fping:
1.#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
1.#tar xvzf Time-HiRes-1.65.tar.gz
2.#3cd Time-HiRes-1.65/perl Makefile.PL && make &&make test && make install
1.#tar xvjf mon-0.99.
2.tar.bz2
2.#cp -r mon-0.99.2 /usr/lib/mon
3.#mkdir /etc/mon
4.#cp /usr/lib/mon/etc/auth.cf /etc/mon
2) 编辑/etc/mon/mon.cf文件:
1.cfbasedir = /etc/mon
2.alertdir = /usr/lib/mon/alert.d
3.mondir = /usr/lib/mon/mon.d
4.statedir = /usr/lib/mon/state.d
5.logdir = /usr/lib/mon/log.d
6.dtlogfile = /usr/lib/mon/log.d/dt.log
7.maxprocs = 20
8.histlength = 100
9.randstart = 60s
10.dtlogging = yes
11.authtype = getpwnam
12.hostgroup servers 10.1.1.1 10.1.1.2
13.hostgroup www 10.1.1.1
14.watch servers
15.service ping
16.interval 1m
17.monitor fping.moniter
18.period wd {Sun-Sat}
19.watch www
20.service http
21.interval 1m
22.monitor http.monitor
23.period wd {Sun-Sat}
24.alert apacherestart.alert
然后编辑/ust/lib/mon/alert.d /apacherestart.alert文件:
1.#!/bin/sh
2./etc/init.d/apache2 restart
3.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服务:
1.#/usr/lib/mon/mon -c /etc/mon/mon.cf &
查看log文件,检查服务状态:
1.#tail /var/log/messages
2.Nov 2 17:15:20 linux mon[14079]: mon server started
运行"ps -ef|grep mon"查看进程,可以看到Mon服务成功启动。
1.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服务:
1.#/etc/init.d/apache2 stop
查看log文件,检查Mon服务的处理步骤。
Mon首先发现WWW服务不能访问,然后重启Apache服务,并且发Email到指定的邮箱。
log文件内容如下:
1.Nov 2 17:15:59 linux mon[14079]: failure for www http
1099386959 10.1.1.1
2.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
3.Nov 2 17:16:03 linux mon[14079]: calling alert mail.alert for
www/http(/usr/lib/mon/alert.d/mail.alert,song@) 10.1.1.1
邮件内容则如下:
1.ALERT www/http: 10.1.1.1(Tue Nov 2 17:16:03)(标题)
2.Sunmmary output : 10.1.1.1
3.Group : www
4.Service : http
5.Time noticed : Tue Nov 2 17:16:03 2004
6.Secs until next alert :
7.Members : 10.1.1.1
8.Detailed text (if any) follows:
9.HOST 10.1.1.1: connect: Connection refused
②测试网络监控和警告
关闭linux1的网络服务:
1.#/etc/init.d/network stop
Mon会发送告警邮件到指定邮箱,邮件内容略。
六、数据同步
假设这里只更新linux1服务器上的数据,由linux1定时向linux2复制数据,这就需要进行数据同步设置。
首先,设置linux1到linux2的SSH无密码登录:
1.#ssh-keygen -t dsa
2.#scp /root/.ssh/id_dsa.pub 10.1.1.2:/root/.ssh/authorized_keys
3.#ssh 10.1.1.2 (应该不用输入密码就能登录)
然后,在linux1上运行Rsync进行数据同步:
1.#/usr/bin/rsync -avzoge ssh /srv/www/htdocs 10.1.1.2:/srv/www/htdocs
这时会显示如下内容:
1.building file list ... done
将数据同步服务加入到Crontab,设置30分钟(时间可以根据具体需要决定)定时数据同步一次。
命令如下:
1.#crontab -e
2.*/30 * * * * /usr/sbin/rsync -avzoge ssh 10.1.1.2:/srv/www/html
至此,具有数据同步、服务监控的高可用性服务系统搭建完成。