经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 大数据/云/AI » Hadoop » 查看文章
1.Hadoop集群安装部署
来源:cnblogs  作者:零度微笑  时间:2018/10/17 8:56:22  对本文有异议

Hadoop集群安装部署

1.介绍

(1)架构模型

(2)使用工具

  1. VMWARE
  2. cenos7
  3. Xshell
  4. Xftp
  5. jdk-8u91-linux-x64.rpm
  6. hadoop-2.7.3.tar.gz

2.安装步骤

(1)部署master

  1. 创建一台虚拟机

  2. 修改ip

    这里请参考:VMWARE虚拟机中CentOs7网络连接

  3. Xftp传输jdk、hadhoop安装包

    把两个安装包拉取到/usr/local路径下

  4. 安装jdk

    rpm -ivh jdk-8u91-linux-x64.rpm

  5. 安装hadhoop

    tar zxvf hadoop-2.7.3.tar.gz

  6. 配置环境变量

    • 配置/hadoop/etc/hadoop/hadoop-env.sh的JAVA_HOME

      1. # Licensed to the Apache Software Foundation (ASF) under one
      2. # or more contributor license agreements. See the NOTICE file
      3. # distributed with this work for additional information
      4. # regarding copyright ownership. The ASF licenses this file
      5. # to you under the Apache License, Version 2.0 (the
      6. # "License"); you may not use this file except in compliance
      7. # with the License. You may obtain a copy of the License at
      8. #
      9. # http://www.apache.org/licenses/LICENSE-2.0
      10. #
      11. # Unless required by applicable law or agreed to in writing, software
      12. # distributed under the License is distributed on an "AS IS" BASIS,
      13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14. # See the License for the specific language governing permissions and
      15. # limitations under the License.
      16. # Set Hadoop-specific environment variables here.
      17. # The only required environment variable is JAVA_HOME. All others are
      18. # optional. When running a distributed configuration it is best to
      19. # set JAVA_HOME in this file, so that it is correctly defined on
      20. # remote nodes.
      21. # The java implementation to use.
      22. export JAVA_HOME=/usr/java/default
      23. # The jsvc implementation to use. Jsvc is required to run secure datanodes
      24. # that bind to privileged ports to provide authentication of data transfer
      25. # protocol. Jsvc is not required if SASL is configured for authentication of
      26. # data transfer protocol using non-privileged ports.
      27. #export JSVC_HOME=${JSVC_HOME}
      28. export HADOOP_CONF_DIR=${HADOOP_CONF_DIR:-"/etc/hadoop"}
      29. # Extra Java CLASSPATH elements. Automatically insert capacity-scheduler.
      30. for f in $HADOOP_HOME/contrib/capacity-scheduler/*.jar; do
      31. if [ "$HADOOP_CLASSPATH" ]; then
      32. export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:$f
      33. else
      34. export HADOOP_CLASSPATH=$f
      35. fi
      36. done
      37. # The maximum amount of heap to use, in MB. Default is 1000.
      38. #export HADOOP_HEAPSIZE=
      39. #export HADOOP_NAMENODE_INIT_HEAPSIZE=""
      40. # Extra Java runtime options. Empty by default.
      41. export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true"
      42. # Command specific options appended to HADOOP_OPTS when specified
      43. export HADOOP_NAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_NAMENODE_OPTS"
      44. export HADOOP_DATANODE_OPTS="-Dhadoop.security.logger=ERROR,RFAS $HADOOP_DATANODE_OPTS"
      45. export HADOOP_SECONDARYNAMENODE_OPTS="-Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_SECONDARYNAMENODE_OPTS"
      46. export HADOOP_NFS3_OPTS="$HADOOP_NFS3_OPTS"
      47. export HADOOP_PORTMAP_OPTS="-Xmx512m $HADOOP_PORTMAP_OPTS"
      48. # The following applies to multiple commands (fs, dfs, fsck, distcp etc)
      49. export HADOOP_CLIENT_OPTS="-Xmx512m $HADOOP_CLIENT_OPTS"
      50. #HADOOP_JAVA_PLATFORM_OPTS="-XX:-UsePerfData $HADOOP_JAVA_PLATFORM_OPTS"
      51. # On secure datanodes, user to run the datanode as after dropping privileges.
      52. # This **MUST** be uncommented to enable secure HDFS if using privileged ports
      53. # to provide authentication of data transfer protocol. This **MUST NOT** be
      54. # defined if SASL is configured for authentication of data transfer protocol
      55. # using non-privileged ports.
      56. export HADOOP_SECURE_DN_USER=${HADOOP_SECURE_DN_USER}
      57. # Where log files are stored. $HADOOP_HOME/logs by default.
      58. #export HADOOP_LOG_DIR=${HADOOP_LOG_DIR}/$USER
      59. # Where log files are stored in the secure data environment.
      60. export HADOOP_SECURE_DN_LOG_DIR=${HADOOP_LOG_DIR}/${HADOOP_HDFS_USER}
      61. ###
      62. # HDFS Mover specific parameters
      63. ###
      64. # Specify the JVM options to be used when starting the HDFS Mover.
      65. # These options will be appended to the options specified as HADOOP_OPTS
      66. # and therefore may override any similar flags set in HADOOP_OPTS
      67. #
      68. # export HADOOP_MOVER_OPTS=""
      69. ###
      70. # Advanced Users Only!
      71. ###
      72. # The directory where pid files are stored. /tmp by default.
      73. # NOTE: this should be set to a directory that can only be written to by
      74. # the user that will run the hadoop daemons. Otherwise there is the
      75. # potential for a symlink attack.
      76. export HADOOP_PID_DIR=${HADOOP_PID_DIR}
      77. export HADOOP_SECURE_DN_PID_DIR=${HADOOP_PID_DIR}
      78. # A string representing this instance of hadoop. $USER by default.
      79. export HADOOP_IDENT_STRING=$USER
    • 配置hadoop的全局变量

      1. 修改/etc/profile

        vi /etc/profile

        1. # /etc/profile
        2. # System wide environment and startup programs, for login setup
        3. # Functions and aliases go in /etc/bashrc
        4. # It's NOT a good idea to change this file unless you know what you
        5. # are doing. It's much better to create a custom.sh shell script in
        6. # /etc/profile.d/ to make custom changes to your environment, as this
        7. # will prevent the need for merging in future updates.
        8. pathmunge () {
        9. case ":${PATH}:" in
        10. *:"$1":*)
        11. ;;
        12. *)
        13. if [ "$2" = "after" ] ; then
        14. PATH=$PATH:$1
        15. else
        16. PATH=$1:$PATH
        17. fi
        18. esac
        19. }
        20. if [ -x /usr/bin/id ]; then
        21. if [ -z "$EUID" ]; then
        22. # ksh workaround
        23. EUID=`/usr/bin/id -u`
        24. UID=`/usr/bin/id -ru`
        25. fi
        26. USER="`/usr/bin/id -un`"
        27. LOGNAME=$USER
        28. MAIL="/var/spool/mail/$USER"
        29. fi
        30. # Path manipulation
        31. if [ "$EUID" = "0" ]; then
        32. pathmunge /usr/sbin
        33. pathmunge /usr/local/sbin
        34. else
        35. pathmunge /usr/local/sbin after
        36. pathmunge /usr/sbin after
        37. fi
        38. HOSTNAME=`/usr/bin/hostname 2>/dev/null`
        39. HISTSIZE=1000
        40. if [ "$HISTCONTROL" = "ignorespace" ] ; then
        41. export HISTCONTROL=ignoreboth
        42. else
        43. export HISTCONTROL=ignoredups
        44. fi
        45. export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
        46. # By default, we want umask to get set. This sets it for login shell
        47. # Current threshold for system reserved uid/gids is 200
        48. # You could check uidgid reservation validity in
        49. # /usr/share/doc/setup-*/uidgid file
        50. if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
        51. umask 002
        52. else
        53. umask 022
        54. fi
        55. for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do
        56. if [ -r "$i" ]; then
        57. if [ "${-#*i}" != "$-" ]; then
        58. . "$i"
        59. else
        60. . "$i" >/dev/null
        61. fi
        62. fi
        63. done
        64. unset i
        65. unset -f pathmunge
        66. export PATH=$PATH:/usr/local/hadoop/bin:/usr/local/hadoop/sbin
      2. 生效/etc/profile

        source /etc/profile

(2)部署slave

  1. 克隆三个主机slave1、slave2、slave3
  2. 修改ip

(3)统一配置

利用Xshell提供的工具多窗口命令行,会使我们的操作更简单。

  1. 测试网络

    ping 192.168.40.100

    ping 192.168.40.101

    ping 192.168.40.102

    ping 192.168.40.103

  2. 关闭防火墙

    systemctl stop filewalld ------关闭防火墙

    systemctl disable filewalld ------失效防火墙,下次重启也属于关闭状态

  3. 修改host

    vi /etc/hosts

    192.168.40.100 master

    192.168.40.101 slave1

    192.168.40.102 slave2

    192.168.40.103 slave3

  4. 配置core-site.xml

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
    3. <!--
    4. Licensed under the Apache License, Version 2.0 (the "License");
    5. you may not use this file except in compliance with the License.
    6. You may obtain a copy of the License at
    7. http://www.apache.org/licenses/LICENSE-2.0
    8. Unless required by applicable law or agreed to in writing, software
    9. distributed under the License is distributed on an "AS IS" BASIS,
    10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11. See the License for the specific language governing permissions and
    12. limitations under the License. See accompanying LICENSE file.
    13. -->
    14. <!-- Put site-specific property overrides in this file. -->
    15. <configuration>
    16. <property>
    17. <name>fs.defaultFS</name>
    18. <value>hdfs://master:9090</value>
    19. </property>
    20. </configuration>

(4)启动master

切换到master主机:

  1. 格式化namenode

    hdfs namenode -format

  2. 启动namenode

    hadoop-daemon.sh start namenode

  3. 查看namenode是否启动成功

    jps

    如果有NameNode进程则启动成功。

(5)启动slave

切换到slave1,slave2,slave3主机:

  1. 启动datanode

    hadoop-daemon.sh start datanode

  2. 查看datanode是否启动成功

    jps

    如果有DataNode进程则启动成功。

(6)查看NameNode里的DataNode

hadoop dfsadmin -report

结果:

  1. [root@bogon hadoop]# hadoop dfsadmin -report
  2. DEPRECATED: Use of this script to execute hdfs command is deprecated.
  3. Instead use the hdfs command for it.
  4. Configured Capacity: 19925041152 (18.56 GB)
  5. Present Capacity: 13599780864 (12.67 GB)
  6. DFS Remaining: 13599756288 (12.67 GB)
  7. DFS Used: 24576 (24 KB)
  8. DFS Used%: 0.00%
  9. Under replicated blocks: 0
  10. Blocks with corrupt replicas: 0
  11. Missing blocks: 0
  12. Missing blocks (with replication factor 1): 0
  13. -------------------------------------------------
  14. Live datanodes (3):
  15. Name: 192.168.40.103:50010 (slave3)
  16. Hostname: localhost
  17. Decommission Status : Normal
  18. Configured Capacity: 6641680384 (6.19 GB)
  19. DFS Used: 8192 (8 KB)
  20. Non DFS Used: 2108416000 (1.96 GB)
  21. DFS Remaining: 4533256192 (4.22 GB)
  22. DFS Used%: 0.00%
  23. DFS Remaining%: 68.25%
  24. Configured Cache Capacity: 0 (0 B)
  25. Cache Used: 0 (0 B)
  26. Cache Remaining: 0 (0 B)
  27. Cache Used%: 100.00%
  28. Cache Remaining%: 0.00%
  29. Xceivers: 1
  30. Last contact: Tue Oct 16 18:34:12 CST 2018
  31. Name: 192.168.40.101:50010 (slave1)
  32. Hostname: localhost
  33. Decommission Status : Normal
  34. Configured Capacity: 6641680384 (6.19 GB)
  35. DFS Used: 8192 (8 KB)
  36. Non DFS Used: 2108420096 (1.96 GB)
  37. DFS Remaining: 4533252096 (4.22 GB)
  38. DFS Used%: 0.00%
  39. DFS Remaining%: 68.25%
  40. Configured Cache Capacity: 0 (0 B)
  41. Cache Used: 0 (0 B)
  42. Cache Remaining: 0 (0 B)
  43. Cache Used%: 100.00%
  44. Cache Remaining%: 0.00%
  45. Xceivers: 1
  46. Last contact: Tue Oct 16 18:34:12 CST 2018
  47. Name: 192.168.40.102:50010 (slave2)
  48. Hostname: localhost
  49. Decommission Status : Normal
  50. Configured Capacity: 6641680384 (6.19 GB)
  51. DFS Used: 8192 (8 KB)
  52. Non DFS Used: 2108424192 (1.96 GB)
  53. DFS Remaining: 4533248000 (4.22 GB)
  54. DFS Used%: 0.00%
  55. DFS Remaining%: 68.25%
  56. Configured Cache Capacity: 0 (0 B)
  57. Cache Used: 0 (0 B)
  58. Cache Remaining: 0 (0 B)
  59. Cache Used%: 100.00%
  60. Cache Remaining%: 0.00%
  61. Xceivers: 1
  62. Last contact: Tue Oct 16 18:34:12 CST 2018
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号