下面是/etc/hosts文件的示例:
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
## vagrant-hostmanager-start
<ipaddress1> namenode
<ipaddress2> secondarynamenode
<ipaddress3> slave1
<ipaddress4> slave2
< it can be more slave nodes here>
## vagrant-hostmanager-end
当我试图配置hadoop集群时,我需要在以下配置中拆分/etc/hosts文件:
namenode和secondarynamenode转到名为masters的文件 奴隶*去一个叫做奴隶的文件 将至少有namenode和0个或更多从节点。 最简单的方法是什么来解析bash中提到的那个文件,并将这些部分写到前面提到的各个部分(主部分和从属部分)?我可以很容易地用Python完成,但我需要在bash中完成。大师看起来像:
^{pr2}$奴隶就像:
<ipaddress3>
<ipaddress4>
就这样,两个文件只包含ip地址,没有机器名。。。原因是如果机器名存在,Hadoop将无法工作。
如何使用awk
或bash
来实现这一点?我有以下命令:
awk '/namenode/{print >"masters"; next} /slave[0-9]/{print > "slaves"}' /etc/hosts
但这让机器的名字保持不变。。。在
以下是使用
awk
执行此操作的一种方法:相关问题 更多 >
编程相关推荐