spark写入kafka问题

环境:Spark 1.6,  kafka 0.8

Failed to send producer request with correlation id java.io.IOException: Connection reset by peer kafka.common.FailedToSendMessageException: Failed to send messages after 3 tries.

由于使用spark读取和写入到kafka中,出现以上问题,一直以为是参数性能调整问题,调整不同的参数。

在producer端

producerConf.put(“retry.backoff.ms”, “8000”);
producerConf.put(“message.send.max.retries”, “10”);
producerConf.put(“topic.metadata.refresh.interval.ms”, “0”);
producerConf.put(“fetch.message.max.bytes”, “5252880”)
producerConf.put(“request.required.acks”, “0”)

在broker端 server.properties

message.max.bytes=5252880
replica.fetch.max.bytes=5252880
request.timeout.ms=600000

都无法解决些问题,后来才了解到producer默认的写入的方式是同步,因此问题就是在这一个参数上

producerConf.put(“producer.type”, “async”)

hadoop namenode启动问题

环境:CentOS 6.3, hadoop 2.6

由于hadoop集群中的namenode服务器cpu故障造成集群无法使用,重启后启动namenode出现错误提示:java.lang.OutOfMemoryError: GC overhead limit exceeded

 

解决方法:是由于java的内存回收机制造成的, 在hadoop/dfs/name/current有namenode的大量的日志文件,需要修改etc/hadoop/hadoop-env.sh中增加“-Xms30G -Xmx50G”

export HADOOP_NAMENODE_OPTS=”-Xms30G -Xmx50G -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,RFAS} -Dhdfs.audit.logger=${HDFS_AUDIT_LOGGER:-INFO,NullAppender} $HADOOP_NAMENODE_OPTS”

spark处理广告数据中搜索词与bidword的大小写全角繁体问题

环境:spark 1.4.1, jpinyin-1.1.3.jar

spark-shell –executor-memory 10G –total-executor-cores 10 –jars ~/huangqiang/jpinyin-1.1.3.jar

import com.github.stuxuhai.jpinyin.ChineseHelper

val hiveCtx = new org.apache.spark.sql.hive.HiveContext(sc)

val hql1 = hiveCtx.sql(“select logdate, query, custid, groupid, bidword, quality, price from search_join_log where logdate <=’2016-01-07′ and logdate >= ‘2016-01-01′ and adtype=’2′ and adid > 0 and channel in(’16’,’40’,’51’,’52’,’78’,’80’,’72’,’73’,’81’)”)

def qj2Bj(str: String): String = {
var b = str.toCharArray
val c = b.map{i =>
if(i == ‘\\\\u3000’){
“”
}else if(i > ‘\\\\uFF00’ && i < ‘\\\\uFF5F’){
(i – 65248).toChar
}else{
i.toChar
}
}
return c.mkString
}

val norm_search_join_log = hql1.map{r =>
val q_bc = qj2Bj(r(1).toString.toLowerCase())
val b_bc = qj2Bj(r(4).toString.toLowerCase())
val q_sim = ChineseHelper.convertToSimplifiedChinese(q_bc)
val b_sim = ChineseHelper.convertToSimplifiedChinese(b_bc)
(r(0).toString, q_sim, r(2).toString, r(3).toString, b_sim, r(5).toString, r(6).toString)
}

 

 

hive使用postgresql启动问题No suitable driver found

环境:CentOS 6.4, hadoop 2.6, hive 1.1,postgresql 9.4

 

在启动hive的时候出现No suitable driver found for jdbc:postgres://xxx.xxx.xxx.xxx:5432/hive

依据提示是说postgresql jdbc包找不到,反复确认包是存在lib文件夹内。

最终发现hive-site.xml中的

<value>jdbc:postgres://xxx.xxx.xxx.xxx:5432/hive</value> 的问题。修改为

value>jdbc:postgresql://xxx.xxx.xxx.xx:5432/hive</value>即可

单机安装Ceph

环境: Ubuntu 14.04

一直想用做图片方面的存储,之前有用过Riak CS,但布署,安装和管理挺麻烦的。后来知道ceph,了解它的途径是使用它了。先说下安装步骤:

wget -q -O- ‘https://ceph.com/git/?p=ceph.git;a=blob_plain;f=keys/release.asc’ | sudo apt-key add –

echo deb http://ceph.com/debian-giant/ trusty main | sudo tee /etc/apt/sources.list.d/ceph.list

更新系统
sudo apt-get -q update

安装ceph布署工具
sudo apt-get install ceph-deploy

查询主机名
hostname
主机名为ubuntu

初始化节点信息
sudo ceph-deploy new ubuntu

安装ceph软件
sudo ceph-deploy install ubuntu

创建mon集群
sudo ceph-deploy mon create

启动mon进程
sudo ceph-deploy mon create-initial

安装OSD
sudo mkdir -p /data/osd
sudo ceph-deploy osd prepare ubuntu:/data/osd
sudo ceph-deploy osd activate ubuntu:/data/osd

查看ceph状态
sudo ceph health

增加一个元数据服务器
sudo ceph-deploy mds create ubuntu

查看进程
jerry@ubuntu:~$ ps ax | grep ceph
8863 ? Ssl 0:00 /usr/bin/ceph-mon –cluster=ceph -i ubuntu -f
9357 ? Ssl 0:01 /usr/bin/ceph-osd –cluster=ceph -i 0 -f
9496 ? Ssl 0:00 /usr/bin/ceph-mds –cluster=ceph -i ubuntu -f
9517 pts/0 S+ 0:00 grep –color=auto ceph

有三个ceph服务

查看状态
sudo ceph -s

 

使用ceph

启动ceph-rest-api

sudo ceph-rest-api -n client.admin &

通过浏览器查看 http://192.168.56.101:5000/

Myriad编译

环境: CentOS 6.4,  Myriad

Myriad是一个支持yarn的mesos框架 ,用于整合yarn和mesos资源管理。

编译如下:

git clone https://github.com/mesos/myriad.git

由于gradle被墙了(真不知道为什么要墙住这个软件,万恶的gfw),只好从 http://get.jenv.mvnsearch.org/download/gradle/gradle-2.4.zip 下载,将其放在myriad/gradle/wrapper目录下。修改gradle-wrapper.properties配置文件,

vi myriad/gradle/wrapper/gradle-wrapper.properties

#Wed Jun 10 10:58:12 CDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\\\\://services.gradle.org/distributions/gradle-2.4-bin.zip
distributionUrl=gradle-2.4.zip

注释掉原有的distributionURL,并新增。

最后编译文件

cd myriad

./gradlew build

 

配置和启用myriad

复制相应库到目录下

sudo cp myriad/myriad-executor/build/libs/myriad-executor-runnable-0.0.1.jar /usr/local/libexec/mesos
sudo cp myrida/myriad-scheduler/build/libs/*.jar /usr/lib/hadoop-yarn/

编辑环境变量
sudo vi /etc/hadoop/conf/hadoop-env.sh
export MESOS_NATIVE_JAVA_LIBRARY=/usr/local/lib/libmesos.so
sudo vi /etc/hadoop/conf/yarn-site.xml
<property>
<name>yarn.nodemanager.resource.cpu-vcores</name>
<value>${nodemanager.resource.cpu-vcores}</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>${nodemanager.resource.memory-mb}</value>
</property>
<!–These options enable dynamic port assignment by mesos –>
<property>
<name>yarn.nodemanager.address</name>
<value>${myriad.yarn.nodemanager.address}</value>
</property>
<property>
<name>yarn.nodemanager.webapp.address</name>
<value>${myriad.yarn.nodemanager.webapp.address}</value>
</property>
<property>
<name>yarn.nodemanager.webapp.https.address</name>
<value>${myriad.yarn.nodemanager.webapp.address}</value>
</property>
<property>
<name>yarn.nodemanager.localizer.address</name>
<value>${myriad.yarn.nodemanager.localizer.address}</value>
</property>

<!– Configure Myriad Scheduler here –>
<property>
<name>yarn.resourcemanager.scheduler.class</name>
<value>com.ebay.myriad.scheduler.yarn.MyriadFairScheduler</value>
<description>One can configure other scehdulers as well from following list: com.ebay.myriad.scheduler.yarn.MyriadCapacityScheduler, com.ebay.myriad.scheduler.yarn.MyriadFifoScheduler</description>
</property>
<property>
<description>A comma separated list of services where service name should only contain a-zA-Z0-9_ and can not start with numbers</description>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle,myriad_executor</value>
<!– If using MapR distribution
<value>mapreduce_shuffle,mapr_direct_shuffle,myriad_executor</value> –>
</property>
<property>
<name>yarn.nodemanager.aux-services.myriad_executor.class</name>
<value>com.ebay.myriad.executor.MyriadExecutorAuxService</value>
</property>
sudo vi /etc/hadoop/conf/mapred-site.xml
<!–This option enables dynamic port assignment by mesos –>
<property>
<name>mapreduce.shuffle.port</name>
<value>${myriad.mapreduce.shuffle.port}</value>
</property>

重启resource manager服务
sudo /etc/init.d/hadoop-yarn-resourcemanager restart
sudo /etc/init.d/hadoop-yarn-resourcemanager status

Spark standalone 模式控制应用使用的cpu和内存

环境:Spark 1.3.0

由于搭建的spark 是standalone模式,因而应用使用的内存和cpu数应由spark-env.sh的环境变量或应用程序的控制参数spark.executor.memory和spark.cores.max,不然应用将占用所有cpu数并使用其它应用无法获取cpu数,并且spark-submit中的控制参数(total-executor-cores, executor-memory无效。

环境变量:

SPARK_WORKER_MEMORY=”50g”
SPARK_WORKER_CORES=22

应用程序:

new SparkConf().set(“spark.executor.memory”, “5g”).set(“spark.cores.max”, “5”)