hadoop Shell中的EOF运算符未退出

vs91vp4v  于 2022-12-22  发布在  Hadoop
关注(0)|答案(3)|浏览(174)

我正在尝试使用Vagrantfile在我的客户机上编辑Hadoop文件。我使用的是cat。这将编辑文件,但即使EOF也被视为文本,它已被插入到文件/hadoop/conf/core-site.xml中。EOF未退出,因此以下内容被视为文本的一部分。
我应该对此代码做什么更改?

if node.vm.hostname == "node1"
        node.vm.provision "shell", inline: <<-SHELL
        cat >/hadoop/conf/core-site.xml <<EOF
          <?xml version="1.0" encoding="UTF-8"?>
          <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
          <configuration>
            <property>
              <name>fs.default.name</name>
              <value>hdfs://localhost:8000</value>
            </property>
          </configuration>
          EOF          
        SHELL

      end
wi3ka0sx

wi3ka0sx1#

不要使用内联shell来做这类工作。把实际的文件挂载到一个与VM共享的卷中。
否则,您将同时使用ruby解析器和shell解析器,并且肯定会遇到问题。
您还可以将现有的Ansible/Puppet/Chef Hadoop供应脚本与Vagrant一起使用,而不是重新发明轮子。

qlvxas9a

qlvxas9a2#

几天前我也遇到过同样的问题,你只需要删除“EOF”前面的制表符/空格。
所以只要改变

cat >/hadoop/conf/core-site.xml <<EOF
      <?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
      <configuration>
        <property>
          <name>fs.default.name</name>
          <value>hdfs://localhost:8000</value>
        </property>
      </configuration>
    EOF

cat >/hadoop/conf/core-site.xml <<EOF
      <?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
      <configuration>
        <property>
          <name>fs.default.name</name>
          <value>hdfs://localhost:8000</value>
        </property>
      </configuration>
  EOF
ergxz8rk

ergxz8rk3#

谢谢@OneCricketer。你的建议很有帮助。我单独创建了xml文件作为core-site.xml

<?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
      <configuration>
        <property>
          <name>fs.default.name</name>
          <value>hdfs://localhost:8000</value>
        </property>
      </configuration>

然后,我创建了一个bash文件,以便使用以下命令创建符号链接

sudo ln -sf /vagrant/hadoopscripts/core-site.xml /home/vagrant/hadoop/etc/hadoop/core-site.xml

最后,我使用以下命令从Vagrantfile中提供了名为“hadoopconfig.sh”的bash。

config.vm.provision :shell, path: "shellscripts/hadoopconfig.sh"

谢谢!

相关问题