使用vagrantfile自动定义hadoop变量

kcwpcxri  于 2021-05-29  发布在  Hadoop
关注(0)|答案(0)|浏览(246)

我正在尝试使用vb和vagrant设置hadoop集群。我能够加载主虚拟机和从虚拟机,下载hadoop和untar它里面。我的问题是,当我试图添加export命令来设置hadoop变量时,它似乎不起作用。。。这是我的流浪档案:


# -*- mode: ruby -*-

# vi: set ft=ruby :

Vagrant.configure(2) do |config|
config.vm.define "nodeA" do |nodeA|
    nodeA.vm.box = "ubuntu/trusty64"
    nodeA.vm.network "forwarded_port", guest: 8088, host: 8088
    nodeA.vm.provision "shell", inline: <<-SHELL

        # !!! YOU NEED TO REPLACE HERE CORRECT IP ADDRESS !!!
        sudo echo "62.04.97.01 slave" >> /etc/hosts

        # Update VM to the latest binaries from distribution
        # package.
        sudo apt-get update && sudo apt-get upgrade -y
        sudo apt-get install -y vim telnet wget curl htop nmon

        # Installing and configuring java.
        cp /vagrant/install_java.sh .
        ./install_java.sh

        # Passwordless ssh communication between two virtual nodes.
        su vagrant -c "ssh-keygen -t rsa -P '' -f /home/vagrant/.ssh/id_rsa"
        mkdir -p /vagrant/files/ssh/
        cp /home/vagrant/.ssh/id_rsa.pub /vagrant/files/ssh/master.pub
        cp /vagrant/after_startup.sh /home/vagrant/.

        # TODO: In order to complete Hadoop configuration you have to
        # provide here set of Linux shell commands which completes
        # instalation and configuration of Hadoop cluster.

        cd /home/vagrant/
        wget http://apache.mivzakim.net/hadoop/common/hadoop-2.7.2/hadoop-2.7.2.tar.gz

        tar xzf hadoop-2.7.2.tar.gz 

        cp /vagrant/mysource.sh .
        source ./mysource.sh
        #hadoop version
        #$ hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduceexamples-2.2.0.jar 

        #HADOOP VARIABLES START
        export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_77
        export HADOOP_HOME=/home/vagrant/hadoop-2.7.2
        export HADOOP_INSTALL=$HADOOP_HOME
        export PATH=$PATH:$HADOOP_INSTALL/bin
        export PATH=$PATH:$HADOOP_INSTALL/sbin
        export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
        export HADOOP_COMMON_HOME=$HADOOP_INSTALL
        export HADOOP_HDFS_HOME=$HADOOP_INSTALL
        export YARN_HOME=$HADOOP_INSTALL
        export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
        export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
        #HADOOP VARIABLES END
        #alias hadoop="/home/vagrant/hadoop-2.7.2/bin/hadoop"
        echo 'source /vagrant/mysource.sh' >> ~/.bashrc
        echo 'source /vagrant/mysource.sh' >> ~/.profile
        source /vagrant/mysource.sh

        # !!! Fill your commands here !!!
    SHELL
end

config.vm.define "nodeB" do |nodeB|
    nodeB.vm.box = "ubuntu/trusty64"
    nodeB.vm.network "forwarded_port", guest: 8088, host: 9088
    nodeB.vm.provision "shell", inline: <<-SHELL
        # !!! YOU NEED TO REPLACE HERE CORRECT IP ADDRESS !!!
        sudo echo "62.04.97.02 master" >> /etc/hosts

        # Update VM to the latest binaries from distribution
        # package.
        sudo apt-get update && sudo apt-get upgrade -y
        sudo apt-get install -y vim telnet wget curl htop nmon

        # Installing and configuring java.
        cp /vagrant/install_java.sh .
        ./install_java.sh

        # Passwordless ssh communication between two virtual nodes.
        su vagrant -c "ssh-keygen -t rsa -P '' -f /home/vagrant/.ssh/id_rsa"
        mkdir -p /vagrant/files/ssh/
        cp /home/vagrant/.ssh/id_rsa.pub /vagrant/files/ssh/slave.pub
        cp /vagrant/after_startup.sh /home/vagrant/.

        cd /home/vagrant/
        wget http://apache.mivzakim.net/hadoop/common/hadoop-2.7.2/hadoop-2.7.2.tar.gz

        tar xzf hadoop-2.7.2.tar.gz 
        #hadoop version
        #$ hadoop jar $HADOOP_HOME/share/hadoop/mapreduce/hadoop-mapreduceexamples-2.2.0.jar 

        cp /vagrant/mysource.sh .
        source ./mysource.sh

        #HADOOP VARIABLES START
        export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_77
        export HADOOP_HOME=/home/vagrant/hadoop-2.7.2
        export HADOOP_INSTALL=$HADOOP_HOME
        export PATH=$PATH:$HADOOP_INSTALL/bin
        export PATH=$PATH:$HADOOP_INSTALL/sbin
        export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
        export HADOOP_COMMON_HOME=$HADOOP_INSTALL
        export HADOOP_HDFS_HOME=$HADOOP_INSTALL
        export YARN_HOME=$HADOOP_INSTALL
        export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
        export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
        #HADOOP VARIABLES END
        #alias hadoop="/home/vagrant/hadoop-2.7.2/bin/hadoop"
        echo 'source /vagrant/mysource.sh' >> ~/.bashrc
        source /vagrant/mysource.sh

        # TODO: In order to complete Hadoop configuration you have to
        # provide here set of Linux shell commands which completes
        # installation and configuration of Hadoop cluster.

        # !!! Fill your commands here !!!
    SHELL
end
end

当我跑向流浪者时,它除了输出命令外什么都做。
我还尝试在脚本中查看导出命令,将其复制到内部并使用source命令运行,尝试使用sudo和sudo-s,但也没有任何效果。。。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题