hadoop Shell中的EOF运算符未退出

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

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

  1. if node.vm.hostname == "node1"
  2. node.vm.provision "shell", inline: <<-SHELL
  3. cat >/hadoop/conf/core-site.xml <<EOF
  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  6. <configuration>
  7. <property>
  8. <name>fs.default.name</name>
  9. <value>hdfs://localhost:8000</value>
  10. </property>
  11. </configuration>
  12. EOF
  13. SHELL
  14. end
wi3ka0sx

wi3ka0sx1#

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

qlvxas9a

qlvxas9a2#

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

  1. cat >/hadoop/conf/core-site.xml <<EOF
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  4. <configuration>
  5. <property>
  6. <name>fs.default.name</name>
  7. <value>hdfs://localhost:8000</value>
  8. </property>
  9. </configuration>
  10. EOF

  1. cat >/hadoop/conf/core-site.xml <<EOF
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  4. <configuration>
  5. <property>
  6. <name>fs.default.name</name>
  7. <value>hdfs://localhost:8000</value>
  8. </property>
  9. </configuration>
  10. EOF
展开查看全部
ergxz8rk

ergxz8rk3#

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

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

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

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

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

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

谢谢!

展开查看全部

相关问题