HIVE详解大数据

只需要在主节点配置即可

  1. 进入usr
    cd /usr

  2. 解压hive
    tar -xzvf apache-hive-2.1.1-bin.tar.gz

  3. 删除apache-hive-2.1.1-bin.tar.gz
    rm -rf apache-hive-2.1.1-bin.tar.gz

  4. 修改文件名
    mv apache-hive-2.1.1-bin/ hive

  5. 编辑/etc/profile文件,增加hive相关的环境变量配置
    vi /etc/profile

  6. 添加如下代码
    export HIVE_HOME=/usr/hive
    export HIVE_CONF_DIR=${HIVE_HOME}/conf

  7. 生效
    source /etc/profile

  8. hive-site.xml相关的配置
    A:cd hive/
    B:cp conf/hive-default.xml.template conf/hive-site.xml

  9. 使用hadoop新建hdfs目录
    A:su wuyang
    B:/usr/hadoop/bin/hadoop fs -mkdir -p /user/hive/warehouse
    C:/usr/hadoop/bin/hadoop fs -chmod 777 /user/hive/warehouse
    D:/usr/hadoop/bin/hadoop fs -mkdir -p /tmp/hive/
    E:/usr/hadoop/bin/hadoop fs -chmod 777 /tmp/hive

  10. 检查hdfs目录是否创建成功

  11. A: /usr/hadoop/bin/hadoop fs -ls /user/hive
    B:/usr/hadoop/bin/hadoop fs -ls /tmp
  12. 切换到root
  13. 修改hive-site.xml中的临时目录
    A:将vi conf/hive-site.xml文件中的${system:java.io.tmpdir}替换为hive的临时目录,例如我替换为/usr/hive/tmp,该目录如果不存在则要自己手工创建,并且赋予读写权限。
    B:将${system:user.name}都替换为root

  14. 修改vi conf/hive-site.xml数据库相关的配置
    A:<name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://192.168.193.201:3306/hive?createDatabaseIfNotExist=true</value>
    B:<name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.jdbc.Driver</value>
    C:<name>javax.jdo.option.ConnectionUserName</name>
    <value>root</value>
    D:<name>javax.jdo.option.ConnectionPassword</name>
    <value>root</value>
    E:<name>hive.metastore.schema.verification</name>
    <value>false</value>

  15. 将MySQL驱动包上载到lib目录

  16. 创建tmp
    mkdir tmp

  17. hive-env.sh文件并进行修改
    A: cp conf/hive-env.sh.template conf/hive-env.sh
    B:vi conf/hive-env.sh
    C:export HADOOP_HOME=/usr/hadoop
    export HIVE_CONF_DIR=/usr/hive/conf
    export HIVE_AUX_JARS_PATH=/usr/hive/lib

  18. 授权
    chown -R wuyang:wuyang /usr/hive/

  19. 进入bin
    cd /usr/hive/bin/

  20. 切换用户su wuyang
  21. 对数据库进行初始化
    ./schematool -initSchema -dbType mysql
    出现SLF4J: Class path contains multiple SLF4J bindings.
    SLF4J: Found binding in [jar:file:/usr/hive/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/usr/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
    SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
    Metastore connection URL: jdbc:mysql://127.0.0.1:3306/hive?createDatabaseIfNotExist=true
    Metastore Connection Driver : com.mysql.jdbc.Driver
    Metastore connection User: root
    Starting metastore schema initialization to 2.1.0
    Initialization script hive-schema-2.1.0.mysql.sql
    Initialization script completed
    schemaTool completed

  22. 启动hive
    ./hive
    出现SLF4J: Class path contains multiple SLF4J bindings.
    SLF4J: Found binding in [jar:file:/usr/hive/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: Found binding in [jar:file:/usr/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
    SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
    Logging initialized using configuration in jar:file:/usr/hive/lib/hive-common-2.1.1.jar!/hive-log4j2.properties Async: true
    Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.hive>

  23. 测试
    show functions;
    出现
    >=
    ^
    abs
    acos
    add_months
    aes_decrypt
    aes_encrypt
    and
    array
    array_contains
    ascii
    asin
    assert_true
    atan
    avg
    base64
    between
    bin
    bround
    case
    cbrt
    ceil
    ceiling
    chr
    coalesce
    collect_list
    collect_set
    compute_stats
    concat
    concat_ws
    context_ngrams
    conv
    corr
    cos
    count
    covar_pop
    covar_samp
    crc32
    create_union
    cume_dist
    current_database
    current_date
    current_timestamp
    current_user
    date_add
    date_format
    date_sub
    datediff
    day
    dayofmonth
    decode
    degrees
    dense_rank
    div
    e
    elt
    encode
    ewah_bitmap
    ewah_bitmap_and
    ewah_bitmap_empty
    ewah_bitmap_or
    exp
    explode
    factorial
    field
    find_in_set
    first_value
    floor
    format_number
    from_unixtime
    from_utc_timestamp
    get_json_object
    get_splits
    greatest
    hash
    hex
    histogram_numeric
    hour
    if
    in
    in_file
    index
    initcap
    inline
    instr
    isnotnull
    isnull
    java_method
    json_tuple
    lag
    last_day
    last_value
    lcase
    lead
    least
    length
    levenshtein
    like
    ln
    locate
    log
    log10
    log2
    lower
    lpad
    ltrim
    map
    map_keys
    map_values
    mask
    mask_first_n
    mask_hash
    mask_last_n
    mask_show_first_n
    mask_show_last_n
    matchpath
    max
    md5
    min
    minute
    month
    months_between
    named_struct
    negative
    next_day
    ngrams
    noop
    noopstreaming
    noopwithmap
    noopwithmapstreaming
    not
    ntile
    nvl
    or
    parse_url
    parse_url_tuple
    percent_rank
    percentile
    percentile_approx
    pi
    pmod
    posexplode
    positive
    pow
    power
    printf
    quarter
    radians
    rand
    rank
    reflect
    reflect2
    regexp
    regexp_extract
    regexp_replace
    repeat
    replace
    reverse
    rlike
    round
    row_number
    rpad
    rtrim
    second
    sentences
    sha
    sha1
    sha2
    shiftleft
    shiftright
    shiftrightunsigned
    sign
    sin
    size
    sort_array
    soundex
    space
    split
    sqrt
    stack
    std
    stddev
    stddev_pop
    stddev_samp
    str_to_map
    struct
    substr
    substring
    substring_index
    sum
    tan
    to_date
    to_unix_timestamp
    to_utc_timestamp
    translate
    trim
    trunc
    ucase
    unbase64
    unhex
    unix_timestamp
    upper
    var_pop
    var_samp
    variance
    version
    weekofyear
    when
    windowingtablefunction
    xpath
    xpath_boolean
    xpath_double
    xpath_float
    xpath_int
    xpath_long
    xpath_number
    xpath_short
    xpath_string
    year
    |
    ~
    Time taken: 3.756 seconds, Fetched: 237 row(s)
  24. 执行查看sum函数的详细信息的命令
    desc function sum;
    出现OK
    sum(x) – Returns the sum of a set of numbers
    Time taken: 4.509 seconds, Fetched: 1 row(s)
  25. 执行新建数据库的hive命令
    create database db_hive_wuyang;

  26. 创建的数据库中创建数据表,执行hive命令
    use db_hive_wuyang;

  27. 创建表
    create table student(id int,name string) row format delimited fields terminated by ‘/t’;

  28. 将文件数据写入表中
    A:touch /usr/hive/student.txt
    B:vi student.txt
    C:001 zhangsan
    002 lisi
    003 wangwu
    004 zhaoliu
    005 chengqi
    D:load data local inpath ‘/usr/hive/student.txt’ into table db_hive_wuyang.student;

  29. 查看是否写入成功
    select * from student;

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/9075.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论