采用Apache版本spark1.2.1时没有出现乱码,但spark-1.1.0-cdh5.2.1版本中,在分布处理的map函数里对数据进行打印输出进行debug时
val rs = rdd.filter(e => {val (lable,text) = (e._2(2), e._2(3)); m.filterItem(lable, text) }) .reduceByKey((x,y) => m.merge(x, y)) .map{case (x,y) => {println(x + "\t" + y); (x._1.toLong, x._2, y(1), y(3) )}}
发现stdout文件里面中文内容乱码
(5,?????????????) List(????????????? ? ??, http://xinligs.cn.china.cn/, A0, ,???:???,,??:?????????????138?,??:7975209__??:15028078833__??:15176090928,,,,,,,,????:???????????????????????(11)???,,,,, false, 4, 7) ????????????? 17 ,???:???,,??:?????????????138?,??:7975209__??:15028078833__??:15176090928,,,,,,,,????:???????????????????????(11)???,,,,
在/var/run/spark/work/目录中查看对应app-20150605171809-0003中的stdout文件
stderr: ASCII C++ program text stdout: UTF-8 Unicode text, with very long lines
stdout是ASCII编码的,对中文肯定显示不了
在使用service启动Java程序时,机器上hadoop中stdout输出的日志也是是中文乱码
修改 /sbin/service ,在env -i 后面加上 LANG="$LANG"
重启spark的各节点
service spark-master restart service spark-worker restart
最后日志中文显示正常
时间: 2024-11-07 01:22:36