chmod 600/etc/ha.d/authkeys4.3 在備用服務器上安裝Heartbeat把配置文件拷貝到備用服務器上[root@server1 ~]# scp -r/etc/ha.droot@server3:/etc/ha.d4.4 啟動Heartbeat1 在主服務器和備用服務器上把heartbeat配置為開機自動啟動chkconfig --level 35 heartbeat on2 手工啟停方法/etc/init.d/heartbeat start或者service heartbeat start/etc/init.d/heartbeat stop或者service heartbeat stop5、 Hadoop主要配置文件的配置提示:在啟動heartbeat前,應該先formatnamenode在drbd分區(qū)中產(chǎn)生元數(shù)據(jù)。mastersservervipslavesserver2core-site.xml<property><name>hadoop.tmp.dir</name><value>/home/share/hadoopdata/</value><description>A base for other temporary directories.</description></property><property><name>fs.default.name</name><value>hdfs://servervip:9000</value><description>The name of the default file system. A URI whoseschemeand authority determine the FileSystem implementation. Theuri'sscheme determines the config property (fs.SCHEME.impl) namingtheFileSystem implementation class. Theuri's authority is used todetermine the host, port, etc. for a filesystem.</description></property<property><name>fs.checkpoint.dir</name><value>${hadoop.tmp.dir}/dfs/namesecondary</value><description>Determines where on the local filesystem the DFSsecondarynamenode should store the temporary images to merge.Ifthis is a comma-delimited list of directories then the image isreplicated in all of the directories for redundancy.</description></property<property><name>fs.checkpoint.edits.dir</name><value>${fs.checkpoint.dir}</value><description>Determines where on the local filesystem the DFSsecondarynamenode should store the temporary edits to merge.Ifthis is a comma-delimited list of directoires then teh edits isreplicated in all of the directoires for redundancy.Default value is same as fs.checkpoint.dir</description></property>hdfs-site.xml<property><name>dfs.name.dir</name><value>${hadoop.tmp.dir}/dfs/name</value><description>Determines where on the local filesystem the DFSnamenode should store the name table(fsimage). If this is acomma-delimitedlist of directories then the name table isreplicated in all of the directories, forredundancy.</description></property><property><name>dfs.name.edits.dir</name><value>${dfs.name.dir}</value><description>Determines where on the local filesystem the DFSnamenode should store the transaction (edits) file. If this isacomma-delimited list of directories then the transaction fileisreplicated in all of the directories, for redundancy.Default value is same as dfs.name.dir</description></property>mapred-site.xml<property><name>mapred.job.tracker</name><value>servervip:9001</value><description>The host and port that the MapReduce job tracker runsat. If "local", then jobs are run in-processas a single mapandreduce task.</description></property>6、 通過haresource配置自動切換如果不使用heartbeat的情況下,DRBD只能手工切換主從關(guān)系,現(xiàn)在修改heartbeat的配置文件,使DRBD可以通過heartbeat自動切換。6.1 創(chuàng)建資源腳本1、新建腳本hadoop-hdfs,用于啟停hdfs文件系統(tǒng),同理也可以建腳本hadoop-all,hadoop-jobtracker等資源文件,以hdfs為例內(nèi)容如下:[root@server1 conf]# cat/etc/ha.d/resource.d/hadoop-hdfscd /etc/ha.d/resource.dvi hadoop-hdfs#!/bin/shcase "$1" instart)# Start commands go herecd /home/hadoop-0.20.2/binmsg=`su - root -c "sh/home/hadoop-0.20.2/bin/start-dfs.sh"`logger $msg;;stop)# Stop commands go herecd /home/hadoop-0.20.2/binmsg=`su - root -c "sh/home/hadoop-0.20.2/bin/stop-dfs.sh"`logger $msg;;status)# Status commands go here;;2、修改權(quán)限[root@server1 conf]# chmod755 /etc/ha.d/resource.d/hadoop-hdfs3、 把腳本拷貝到備份機并同樣修改權(quán)限[root@server1 conf]# scp/etc/ha.d/resource.d/hadoop-hdfs server3: /etc/ha.d/resource.d/6.2 配置haresources[root@server1 conf]# cat /etc/ha.d/haresourcesserver1 IPaddr::10.10.140.200 drbddisk::r0 Filesystem::/dev/drbd0::/home/share::ext2hadoop-hdfs注釋:Server1 主服務器名10.10.140.200 對外服務IP別名drbddisk::r0 資源drbddisk,參數(shù)為r0Filesystem::/dev/drbd0::/home/share::ext2資源Filesystem,mount設(shè)備/dev/drbd0到/home/share目錄,類型為ext2Hadoop-hdfs文件系統(tǒng)資源7、 DRBD、heartbeat、hadoop聯(lián)調(diào)7.1創(chuàng)建文件和目錄1、在server1(主節(jié)點)上drbd和heartbeat運行著。由于heartbeat啟動后,虛擬地址10.10.140.200被分配到主節(jié)點上。用命令查看:
7.2 主備機切換1、在server1上停止heartbeat[root@server1 /]# service heartbeat stopStopping High-Availabilityservices:[ OK ]2、可以查看虛擬IP已經(jīng)切換到server3上了
3、驗證server3上查看hadoop文件系統(tǒng)
7.3 主備機再次切換1、在server1上啟動heartbeat[root@server1 /]# service heartbeatstartStarting High-Availability services:2012/07/25_15:03:31 INFO: Resource is stopped[ OK ]2、查看虛擬IP已經(jīng)切換到server1上。