1. 程式人生 > >sparkStreaming+kafka python版wordcount申請資源不成功

sparkStreaming+kafka python版wordcount申請資源不成功

ERROR:py4j.java_gateway:Error while sending or receiving.
Traceback (most recent call last):
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 746, in send_command
    raise Py4JError("Answer from Java side is empty")
Py4JError: Answer from Java side is empty
ERROR:py4j.java_gateway:An error occurred while trying to connect to the Java server
Traceback (most recent call last):
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 690, in start
    self.socket.connect((self.address, self.port))
  File "/usr/lib64/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
error: [Errno 111] Connection refused
Traceback (most recent call last):
  File "WordCount.py", line 22, in <module>
    ssc.awaitTermination()
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/pyspark.zip/pyspark/streaming/context.py", line 209, in awaitTermination
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 811, in __call__
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 631, in send_command
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 631, in send_command
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 624, in send_command
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 579, in _get_connection
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 585, in _create_connection
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 697, in start
py4j.protocol.Py4JNetworkError: An error occurred while trying to connect to the Java server
ERROR:py4j.java_gateway:An error occurred while trying to connect to the Java server
Traceback (most recent call last):
  File "/root/hadoop/tmp/nm-local-dir/usercache/root/appcache/application_1488817456058_0003/container_1488817456058_0003_02_000001/py4j-0.9-src.zip/py4j/java_gateway.py", line 690, in start
    self.socket.connect((self.address, self.port))
  File "/usr/lib64/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)

error: [Errno 111] Connection refused

問題原因:wordcount程式中寫的是:sc=SparkContext("local[*]","KafkaWordCount") spark-submit時 --master yarn,衝突造成的

解決方法:wordcount程式中:sc=SparkContext("yarn-cluster","KafkaWordCount")

原因很低階,來到新公司搭建環境折騰了兩天,週末都沒過好。特此小記!祝自己工作順利!

另:

zookeeper啟動:./zkServer.sh start kafka啟動  bin/kafka-server-start.sh config/server.properties &

bin/kafka-console-producer.sh --broker-list ip:9092 --topic test 

bin/kafka-console-consumer.sh --zookeeper ip:2181 --topic test --from-beginning  --刪除檔案 hadoop fs -rm  /sparkStreaming/project/WordCount.py -- 更新檔案 hadoop fs -put /home/zhaoxiaohui/project/WordCount.py  /sparkStreaming/project --spark 獨立 spark-submit --jars $SPARK_EXEC_LIB --master local[1] --executor-cores 1 --executor-memory 1g --num-executors 1 --driver-memory 1g --driver-cores 1  /home/zhaoxiaohui/project/WordCount.py  --spark on yarn spark-submit --jars /home/zhaoxiaohui/software/spark-streaming-kafka-assembly_2.10-1.6.0.jar --master yarn --deploy-mode cluster  --executor-cores 1 --executor-memory 1g --num-executors 1 --driver-memory 1g --driver-cores 1  /home/zhaoxiaohui/project/WordCount.py spark-submit --jars /home/zhaoxiaohui/software/spark-streaming-kafka-assembly_2.10-1.6.0.jar --master yarn --deploy-mode cluster  --executor-cores 1 --executor-memory 512m --num-executors 1 --driver-memory 512m --driver-cores 1  /home/zhaoxiaohui/project/WordCount.py