这段时间折腾的都是hadoop和lucene,总结了hadoop在运营过程中出现问题时的解决方案,请大家指教!

HDFS(0.20.2)运营中急救方案

1           Namenode 挂掉(secondarynamenode无影响)

如果Namenode挂掉,如果能立即起来通过,start-dfs.sh 能够重新起来则可以正常使用。否则按照以下操作。下面所有操作前提是有完整的secondarynamenode。

1)    在非secondarynamenode服务器中选择datanode作为namenode。(目前在正式文档中没有发现,建议采用第二种,但在测试中没发现问题)

a)         Kill掉所有服务。

b)        修改新namenode服务器 配置文件:core-site.xml,masters,slaves等相关文件。

c)        修改hosts文件

d)        重新配置各节点 ssh ,使新namenode到其他datanode 正常无密码ssh登陆

e)         将运行secondarynamedode机器上的hadoop.tmp.dir/dfs/namesecondary 拷贝到新namenode服务器hadoop.tmp.dir/dfs目录。

f)         将namesecondary改名为name

g)        bin/start-dfs.sh启动hdfs。

2)    在非secondarynamenode服务器中选择datanode作为namenode。通过导入以前的检查点来恢复namenode。

a)         Kill掉所有服务。

b)        修改新namenode服务器 配置文件:core-site.xml,masters,slaves等相关文件。

c)        修改hosts文件

d)        重新配置各节点 ssh ,使新namenode到其他datanode 正常无密码ssh登陆

e)         在namenode服务器core-site.xml中配置fs.checkpoint.dir(默认是在$hadoop.tmp.dir/dfs/ namesecondary).

<property>

<name>fs.checkpoint.dir</name>

<value>/home/hadoop/hadoop-data/dfs/namesecondary</value>

</property>

f)         将运行secondarynamedode机器上的hadoop.tmp.dir/dfs/namesecondary 拷贝到namenode服务器fs.checkpoint.dir目录.

g)        执行bin/hadoop namenode –importCheckpoint 导入检查点。

h)        执行bin/start-dfs.sh 启动dfs.

2           Datanode挂掉(不带secondarynamenode)

1)      原服务器完全坏掉,起不来,只能引入新的datanode。

i.      从其他datanode拷贝hadoop所有配置到新服务器

ii.      设置hosts,将所有datanodes 和namenode 设置hosts

iii.      设置ssh无密码登陆,并测试

iv.      在namenode conf 的slaves中配置新加datanode

v.      在新加datanode上通过bin/hadoop-daemon.sh start datanode  启动该新datanode。

2)         原服务器可以立即起来

i.      因为namenode slaves有该datanode,可以直接在namenode中执行bin/start-dfs.sh 启动

ii.      也可以在该服务器 通过bin/hadoop-daemon.sh start datanode启动

3           Datanode挂掉(带secondarynamenode)

1)    Namenode正常运行情况下,如果该datanode可以立即投入使用,则直接在namenode中执行bin/start-dfs.sh 启动

2)    Namenode正常运行情况下,如果该datanode无法使用,则考虑新增datanode,并配置secondarynamenode。

在新节点 配置文件hdfs-site.xml中 配置:

<property>

<name>dfs.http.address</name>

<value>netease-namenode-test:50070</value>

</property>

该配置在namenode使用默认即可。如果添加上通过外网访问netease-namenode-test:50070可能会由于网段不同导致访问不到。

SequenceFile 解决hadoop小文件问题

quenceFile Formats
2010-10-27 18:50

Overview

SequenceFile is a flat file consisting of binary key/value pairs. It is extensively used in MapReduce as input/output formats. It is also worth noting that, internally, the temporary outputs of maps are stored using SequenceFile.

The SequenceFile provides a Writer, Reader and Sorter classes for writing, reading and sorting respectively.

There are 3 different SequenceFile formats:

  1. Uncompressed key/value records.
  2. Record compressed key/value records - only 'values' are compressed here.
  3. Block compressed key/value records - both keys and values are collected in 'blocks' separately and compressed. The size of the 'block' is configurable.

The recommended way is to use the SequenceFile.createWriter methods to construct the 'preferred' writer implementation.

The SequenceFile.Reader acts as a bridge and can read any of the above SequenceFile formats.

SequenceFile Formats

This section describes the format for the latest 'version 6' of SequenceFiles.

Essentially there are 3 different file formats for SequenceFiles depending on whether compression and block compression are active.

However all of the above formats share a common header (which is used by the SequenceFile.Reader to return the appropriate key/value pairs). The next section summarises the header:

SequenceFile Common Header
  • version - A byte array: 3 bytes of magic header 'SEQ', followed by 1 byte of actual version no. (e.g. SEQ4 or SEQ6)

  • keyClassName - String
  • valueClassName - String
  • compression - A boolean which specifies if compression is turned on for keys/values in this file.

  • blockCompression - A boolean which specifies if block compression is turned on for keys/values in this file.

  • compressor class - The classname of the CompressionCodec which is used to compress/decompress keys and/or values in this SequenceFile (if compression is enabled).

  • metadata - SequenceFile.Metadata for this file (key/value pairs)

  • sync - A sync marker to denote end of the header.

All strings are serialized using Text.writeString api.

The formats for Uncompressed and RecordCompressed Writers are very similar:

Uncompressed & RecordCompressed Writer Format
  • Header

  • Record
    • Record length
    • Key length
    • Key
    • (Compressed?) Value
  • A sync-marker every few k bytes or so.

The sync marker permits seeking to a random point in a file and then re-synchronizing input with record boundaries. This is required to be able to efficiently split large files for MapReduce processing.

The format for the BlockCompressedWriter is as follows:

BlockCompressed Writer Format
  • Header

  • Record Block

    • A sync-marker to help in seeking to a random point in the file and then seeking to next record block.

    • CompressedKeyLengthsBlockSize

    • CompressedKeyLengthsBlock

    • CompressedKeysBlockSize

    • CompressedKeysBlock

    • CompressedValueLengthsBlockSize

    • CompressedValueLengthsBlock

    • CompressedValuesBlockSize

    • CompressedValuesBlock

    The compressed blocks of key lengths and value lengths consist of the actual lengths of individual keys/values encoded in ZeroCompressedInteger format.

简介: 
SequenceFile 是一个由二进制序列化过的key/value的字节流组成的文本存储文件,它可以在map/reduce过程中的input/output 的format时被使用。在map/reduce过程中,map处理文件的临时输出就是使用SequenceFile处理过的。
SequenceFile分别提供了读、写、排序的操作类。
SequenceFile的操作中有三种处理方式:
1) 不压缩数据直接存储。 //enum.NONE
2) 压缩value值不压缩key值存储的存储方式。//enum.RECORD
3) key/value值都压缩的方式存储。//enum.BLOCK

SequenceFile提供了若干Writer的构造静态获取。
//SequenceFile.createWriter();

SequenceFile.Reader使用了桥接模式,可以读取SequenceFile.Writer中的任何方式的压缩数据。

三种不同的压缩方式是共用一个数据头,流方式的读取会先读取头字节去判断是哪种方式的压缩,然后根据压缩方式去解压缩并反序列化字节流数据,得到可识别的数据。

流的存储头字节格式:
Header:
*字节头”SEQ”, 后跟一个字节表示版本”SEQ4”,”SEQ6”.//这里有点忘了 不记得是怎么处理的了,回头补上做详细解释
*keyClass name
*valueClass name
*compression boolean型的存储标示压缩值是否转变为keys/values值了
*blockcompression boolean型的存储标示是否全压缩的方式转变为keys/values值了
*compressor 压缩处理的类型,比如我用Gzip压缩的Hadoop提供的是GzipCodec什么的..
*元数据 这个大家可看可不看的

所有的String类型的写操作被封装为Hadoop的IO API,Text类型writeString()搞定。

未压缩的和只压缩values值的方式的字节流头部是类似的:
*Header
*RecordLength记录长度
*key Length key值长度
*key 值
*是否压缩标志 boolean
*values

package com.netease.hadooplucene.lucene.test;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.lang.String;
import java.lang.Object;
import java.net.URI;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
import org.apache.hadoop.io.compress.*;
import org.apache.hadoop.fs.*;
import com.netease.hadooplucene.lucene.util.HadoopService;
public class SequenceFileTest {
    
    
    
    public static void writeSequceFile(String uri)throws IOException{
        FileSystem fs = HadoopService.getInstance().getHDFSClient();
        Path path = new Path(uri);
        IntWritable key = new IntWritable();
        Text value = new Text();
        SequenceFile.Writer writer = null;
        try {
            writer = SequenceFile.createWriter(fs, fs.getConf(), path, key.getClass(), value.getClass());
            for (int i = 0; i < 100; i++) {
                String tt = String.valueOf(100 - i);
                key.set(i);
                value.set(tt);
                System.out.printf("[%s]/t%s/t%s/n", writer.getLength(), key, value);
                writer.append(key, value);
            }
        } finally {
            IOUtils.closeStream(writer);
        }
    }
    
    
//    public static File getFile(String uri){
//        FileSystem fs = HadoopService.getInstance().getHDFSClient();
//        Path path = new Path(uri);
//        SequenceFile.Reader reader=new SequenceFile.Reader(fs, path, fs.getConf());
//        reader.
//        reader.
//    }
    public static void main(String[] args) throws IOException {
        String uri = args[0];
//        Configuration conf = new Configuration();
//        FileSystem fs = FileSystem.get(URI.create(uri), conf);
        
    }
}
 
 
 
 
 
 
 

前天项目组里遇到由于sequenceFile 的压缩参数设置为record 而造成存储空间的紧张,后来设置为block 压缩方式的压缩方式,存储空间占用率为record 方式的1/5 。问题虽解决了,但是还不是很清楚这两种方式是如何工作以及他们的区别是啥。昨天和今天利用空闲时间,细细的看了一遍sequenceFile 这个类和一些相关类的源码。

sequenceFile 文件存储有三种方式:可以通过在程序调用 enum CompressionType { NONE RECORD BLOCK } 指定,或通过配置文件io.seqfile.compression.type 指定,这三种存储方式如下图:

对于Record 压缩这种存储方式,RecordLen 表示的是key 和value 的占用的byte 之和,Record 压缩方式中 key 是不压缩 ,value 是压缩后的值,在record 和非压缩这两种方式,都会隔几条记录插入一个特殊的标号来作为一个同步点Sync ,作用是当指定读取的位置不是记录首部的时候,会读取一个同步点的记录,不至于读取数据的reader “迷失”。 每两千个byte 就插入一个同步点,这个同步点占16 byte ,包括同步点标示符:4byte ,一个同步点的开销是20byte 。

对于block 这种压缩方式, key 和value 都是压缩的 ,通过设置io.seqfile.compress.blocksize 这个参数决定每一个记录块压缩的数据量,默认大小是1000000 byte ,这个值具体指的是key 和value 缓存所占的空间,每要往文件写一条key/value 时,都是将key 和value 的长度以及key 和value 的值缓存在keyLenBuffer keyBuffer valLenBuffer valBuffer 这四个DataOutputStream 中,当keyBuffer.getLength() + valBuffer.getLength() 大于或等于io.seqfile.compress.blocksize 时,将这些数据当做一个block 写入sequence 文件,如上图所示 每个block 之间都会插入一个同步点。

使secondarynamenode能够post请求到namenode。

然后在namenode masters中增加 新的secondarynamenode 并配置hosts

使用bin/start-dfs.sh 启动。

HDFS(0.20.2)运营中急救方案的更多相关文章

  1. 使用DbVisualizer 10.0.20 查询ES中的索引时需要注意的事项

    查询前5条数据 光标停在某一个查询结果框中,左下角会显示该字段的类型 查询类型是text的字段使用单引号,使用双引号查询会报错

  2. HDFS集群PB级数据迁移方案-DistCp生产环境实操篇

    HDFS集群PB级数据迁移方案-DistCp生产环境实操篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 用了接近2个星期的时间,终于把公司的需要的大数据组建部署完毕了,当然,在部 ...

  3. hadoop 0.20.2伪分布式安装详解

    adoop 0.20.2伪分布式安装详解 hadoop有三种运行模式: 伪分布式不需要安装虚拟机,在同一台机器上同时启动5个进程,模拟分布式. 完全分布式至少有3个节点,其中一个做master,运行名 ...

  4. 【张宴】PHP在金山游戏运营中的应用

    PPT下载地址1(国外服务器):http://blog.s135.com/attachment/201105/2011phptc_zy.zip PPT下载地址2(国内服务器):http://ishar ...

  5. Hadoop 0.20.2+Ubuntu13.04配置和WordCount測试

    事实上这篇博客写的有些晚了.之前做过一些总结后来学校的事给忘了,这几天想又一次拿来玩玩发现有的东西记不住了.翻博客发现居然没有.好吧,所以赶紧写一份留着自己用吧.这东西网上有非常多,只是也不是全然适用 ...

  6. .NET平台开源项目速览(20)Newlife.Core中简单灵活的配置文件

    记得5年前开始拼命翻读X组件的源码,特别是XCode,但对Newlife.Core 的东西了解很少,最多只是会用用,而且用到的只是九牛一毛.里面好用的东西太多了. 最近一年时间,零零散散又学了很多,也 ...

  7. Mapnik 3.0.20编译安装

    1. 确定epel安装 yum install -y epel-release 2. 按照<CentOS7.2部署node-mapnik>一文中的步骤,手动安装 gcc-6.2.0 和 b ...

  8. centos6.5环境通达OA数据库mysql5.0.67升级至mysql5.5.48方案

    centos6.5环境通达OA数据库mysql5.0.67升级至mysql5.5.42方案 整体方案: 环境准备,在备用服务器安装mysql5.5数据库 1.停用生产环境的应用访问 直接修改web的访 ...

  9. centos6.5下编译安装mariadb-10.0.20

    源码编译安装mariadb-10.0.20.tar.gz 一.安装cmake编译工具 跨平台编译器 # yum install -y gcc* # yum install -y cmake 解决依赖关 ...

随机推荐

  1. ZT fcntl设置FD_CLOEXEC标志作用

    fcntl设置FD_CLOEXEC标志作用 分类: C/C++ linux 2011-11-02 22:11 3217人阅读 评论(0) 收藏 举报 bufferexegccnullfile 通过fc ...

  2. 使用信号进行同步 sem_post

    使用信号进行同步 信号是 E. W. Dijkstra 在二十世纪六十年代末设计的一种编程架构.Dijkstra 的模型与铁路操作有关:假设某段铁路是单线的,因此一次只允许一列火车通过. 信号将用于同 ...

  3. iOS自动化-iOS录屏xrecord及解决iPhone设备不显示的问题

    github地址:https://github.com/WPO-Foundation/xrecord 安装方法: git clone https://github.com/WPO-Foundation ...

  4. Linux中如何配置sudo用户

    Linux中的sudo文件在/etc/sudoers,但不建议直接修改此文件: 可以在/etc/sudoers.d文件夹中新建文件,文件名随意,在文件中添加内容如下: 用户名 ALL=(ALL) AL ...

  5. python虚拟环境virtualenv高级篇

    我曾经写过一篇virtualenv的博客:http://www.cnblogs.com/anpengapple/p/5907416.html 总体来讲还是适用的,不过稍微傻了一点.这一篇的内容有两个: ...

  6. win10中显示资源管理器扩展

    一年前从有两台机器win7升级到win10,一台上装了我常用的资源管理器扩展setExBar,但另一台没有.升级后原来有插件的依然默认显示插件,我在另一台机器上安装了setExBar时默认不显示.如果 ...

  7. Odoo中的约束

    转载请注明原文地址:https://www.cnblogs.com/cnodoo/p/9280735.html 一:装饰器约束(字段约束) 装饰器参数指定了约束的字段,当涉及的字段中任一发生改变时触发 ...

  8. I、Q信号是如何产生的,I、Q信号复用的作用

    接收机在中频部分实现模数变换和采样,采样后的信号和数字域的同频相乘,就可以得到基带的I.Q分量.在无线接口传输时,每一种使用特定的载波频率.码(扩频码和扰码)以及载波相对相位(I或Q)的信道都可以理解 ...

  9. 利用maven开发springMVC项目(三)——数据库配置

    前两节介绍了开发环境的搭建以及框架的配置 现在主要介绍在eclipse中如何将SpringMVC.hibernate.mysql数据库结合起来. 数据库配置 下面,就要通过一个简单的例子,来介绍Spr ...

  10. first-child伪类选择器

    原文链接地址:https://www.cnblogs.com/wangmeijian/p/4562304.html :first-child 选择器用于选取属于其父元素的首个子元素的指定选择器.——w ...