知识点
相关文章
更多最近更新
更多shell自动化配置Hadoop配置文件示例
2019-03-28 13:02|来源: 网络
shell自动化配置Hadoop配置文件示例
#!/bin/bash
read -p 'Please input the directory of hadoop , ex: /usr/hadoop :' hadoop_dir
if [ -d $hadoop_dir ] ; then
echo 'Yes , this directory exist.'
else
echo 'Error , this directory not exist.'
exit 1
fi
if [ -f $hadoop_dir/conf/core-site.xml ];then
echo "Now config the $hadoop_dir/conf/core-site.xml file."
read -p 'Please input the ip value of fs.default.name , i.e. hdfs://ip:port :' ip
i=1
while [ -z $ip ]
do
read -p 'Please input the ip value of fs.default.name , i.e. hdfs://ip:port :' ip
let i++
echo $i
if [ $i -gt 2 ];then
echo 'You have input three time , done , exit.'
exit 1
fi
done
if [ $ip = '' ];then
echo 'The value of ip can not null , exit.'
exit 1
fi
read -p "Please input the port value of fs.default.name , i.e. hafs://$ip:port :" port
if [ $port = '' ];then
echo 'The value of port can not null , exit.'
exit 1
fi
read -p 'Please input the dir value of hadoop.tmp.dir :' hadoop_tmp_dir
if [ $hadoop_tmp_dir = '' ];then
echo 'The value of hadoop.tmp.dir can not null , exit.'
exit 1
else
if [ ! -d $hadoop_tmp_dir ];then
echo 'The directory you have input is not exist , we will make it.'
mkdir -p $hadoop_tmp_dir
fi
fi
tmp_dir=$(echo $hadoop_tmp_dir|sed 's:/:\\/:g')
sed -i "s/ip/$ip/g" $hadoop_dir/conf/core-site.xml
sed -i "s/port/$port/g" $hadoop_dir/conf/core-site.xml
sed -i "s/tmp_dir/$tmp_dir/g" $hadoop_dir/conf/core-site.xml
else
echo "The file $hadoop_dir/core-site.xml doen't exist."
exit 1
fi
cat $hadoop_dir/conf/core-site.xml
echo 'Config the core-site.xml success !'
echo
关键部分分析:
1. tmp_dir=$(echo $hadoop_tmp_dir|sed 's:/:\\/:g')
我们输入的$hadoop_tmp_dir是类似:/usr/hadoop/tmp这样的,如果直接写在sed里:sed -i "s/tmp_dir/$hadoop_tmp_dir/g" $hadoop_dir/conf/core-site.xml ,这样会出现错误。因为它解析进去会是:sed -i "s/tmp_dir//usr/hadoop/tmp/g" $hadoop_dir/conf/core-site.xml这样的,显然不能满足,这里解决的方式是:想办法将/usr/hadoop/tmp的输入转换为:\ /usr\ /hadoop\/tmp的形式,即加入转义字符。sed ' s:/:\\/:g ' 这样就可以了,然后通过$(),取值赋给变量。
2. sed -i " s/ip/$ip/g " $hadoop_dir/conf/core-site.xml
这里就是所谓的对文件中字符串的替换,示例文件为:
root@Ubuntu:/home/houqd/hadoop/conf# cat -n core-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!-- Put site-specific property overrides in this file. -->
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://ip:port</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>tmp_dir</value>
</property>
</configuration>
3. 注意其它语法: if [ ] ; then else fi while [] do ..done i=0 let i++
更多Hadoop相关信息见Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13
相关问答
更多-
请问springboot怎么配置sqlserver的配置文件[2023-07-15]
在springboot配置sqlserver文件步骤如下: 1、打开项目配置文件 application.properties。 2、这里推荐一个新的写项目属性配置文件的:application.yml。优点在于它不用重复写代码。 3、这二者选一即可,因而我用了application.yml就把application.properties删除了。 4、特别注意语法:每个冒号后面是有空格的。当然这里eclipse也通过颜色对这个语法进行了提示。 5、特别注意语法:每个冒号后面是有空格的。当然这里eclipse ... -
windows下redis配置文件是哪个[2022-11-25]
Windows版的Redis有2个配置文件,一个是:redis.windows.conf,另一个是redis.windows-service.conf。 -
windows下redis配置文件是哪个[2023-03-14]
Windows版的Redis有2个配置文件,一个是:redis.windows.conf,另一个是redis.windows-service.conf。 -
VB写配置文件[2021-11-27]
Dim s As String On Error Resume Next s = CurDir If Right(s, 1) <> "\" Then s = s & "\" End If Open s & "文件名.exp" For Output As #1 Print #1, '第1行内容 Print #1, '第2行内容 Print #1, '第3行内容 Print #1, '第4行内容 Print #1, '第5行内容 Close #1 End -
程序放在Hadoop下运行,需要一些配置文件,该怎么加入[2021-12-27]
不知道你所说的配置文件是什么确切含义,如果是运行程序执行所需要的一些文件,直接将这些配置文件打到运行的jar包里就可以了,或者做成相应的jar直接放到hadoop的lib里去 -
JAVA零配置读取配置文件[2022-08-03]
package resources; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.Driver; import java.sql.SQLException; import java.util.Properties; public class DbUtil { public static Connection getConnection(){ String ... -
无法加载本地配置文件[2023-05-19]
打开注册表,找到HKEY_LOCAL_MACHINE\SOFTWARE\两个文件是否存在,一般来说丢失或损坏的可能性不大。在运行中输入"cmd",而不是此次登录新创建的配置文件)。重启电脑看第二次加载是否还是失败,查看各账户下的ProfileImagePath项的值,与当前配置文件所在目录匹配的账户主键删除(这么做是为了让第二次登录继续尝试加载原来的配置文件,删除可能冲突软件的自启动;另外如果是NTFS的话检查配置文件的权限用户配置文件都在系统盘的Documents and Settings文件夹下 ... -
hadoop的核心配置文件有哪些[2022-10-22]
在hadoop1中核心组成部分是HDFS、MapReduce,到了Hadoop2,核心变为HDFS、Yarn,而且新的HDFS中可以有多个NameNode,每个都有相同的职能。 以下内容是从http://www.superwu.cn/2014/02/12/1094/阅读后自己总结了一下: 配置文件无非就这几个文件: 1、hadoop-env.sh: 只需设置jdk的安装路径,如:export JAVA_HOME=/usr/local/jdk 2、core-site.xml: (1)fs.defaultFS: ... -
hadoop的配置文件在什么地方[2023-04-13]
hadoop-2.x在$HADOOP_HOME/etc/hadoop目录下 hadoop-1.x在$HADOOP_HOME/conf目录下 -
ubuntu中安装hadoop,配置文件出现问题,求救,十万火急!!!!![2024-02-21]
你试试 sudo update-alternatives --config java 能看看你的jdk到底是什么版本 比如我的是/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 那么我的JAVA_HOME就是”/usr/lib/jvm/java-7-openjdk-amd64". 你的也可能是java-7-openjdk-i386也说不定 所以我怀疑你直接写java-6-oepnjdk会有问题