命令行管理程序中的 EOF 运算符未退出

EOF operator in Shell not exiting

提问人:Dawit 提问时间:12/20/2022 最后编辑:OneCricketeerDawit 更新时间:12/24/2022 访问量:65

问:

我正在尝试使用 Vagrantfile 在我的客户机上编辑 hadoop 文件。我正在使用 .这将编辑文件,但即使是 EOF 也被视为文本,并且它已插入到文件中。EOF 没有退出,因此以下所有内容都被视为文本的一部分。cat/hadoop/conf/core-site.xml

我应该对此代码进行哪些更改?

      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
红宝石 Hadoop 流浪者 EOF

评论

0赞 glenn jackman 12/20/2022
终止“EOF”必须是该行上的唯一字符。不允许使用前导/尾随空格。

答:

1赞 OneCricketeer 12/20/2022 #1

不要将内联 shell 用于此类工作。在与 VM 共享的卷中装载实际文件。

否则,您将同时与 ruby 解析器和 shell 解析器作斗争,并且肯定会遇到问题。

您还可以将现有的 Ansible/Puppet/Chef Hadoop 配置脚本与 Vagrant 一起使用,而不是重新发明轮子。

0赞 Dawit 12/20/2022 #2

谢谢@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" 

谢谢!

评论

0赞 OneCricketeer 12/20/2022
顺便说一句,您应该将 FQDN 主机名用于 hdfs 地址,而不是 localhost
0赞 Dawit 12/21/2022
@OneCricketeer,你能再详细说明一下吗?
1赞 OneCricketeer 12/21/2022
您正在使用 .这仅适用于一个 VM。如果您尝试创建一个完整的Hadoop集群,则应使用 ,例如,然后其他HDFS客户端将与该计算机通信,而不是全部尝试在localhost上连接到自己。<value>hdfs://localhost:8000</value>hdfs://vm1.vagrant:8000
0赞 OneCricketeer 12/21/2022
就像我说的,使用 Ansible 的现有解决方案可能比重新创建自己的解决方案更好,除非你真的只想学习 Vagrant......
0赞 fred schredder 12/20/2022 #3

几天前我遇到了同样的问题,您只需要删除“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