bash history历史命令查询

环境:logstash-2.4.0, elasticsearch-1.6.1, kafka 0.8

经常需要查看bash历史,而这个文件一般存储一定量的命令,有时需要查看什么时候执行过。因而使用logstash + kafka + elasticsearch来搭建bash历史命令检索系统。

配置文件如下:

logstash.conf

input {
file {
path => “/home/adadmin/.bash_history”
add_field => {“user” => “adadmin”}
}
}
filter {
ruby {
code => “event[‘updatetime’] = event.timestamp.time.localtime.strftime(‘%Y-%m-%d %H:%M:%S.%L’)”
}
}
output {
kafka {
bootstrap_servers => “10.121.93.50:9092,10.121.93.51:9092,10.121.93.53:9092”
topic_id => “bash-history”
}
}

elasticsearch:

curl -XPUT ‘xxx.xxx.xxx.53:9200/_river/kafka-river/_meta’ -d ‘
{
“type” : “kafka”,
“kafka” : {
“zookeeper.connect” : “xxx.xxx.xxx.50:2181,xxx.xxx.xxx.51:2181,xxx.xxx.xxx.53:2181”,
“zookeeper.connection.timeout.ms” : 10000,
“topic” : “bash-history”,
“message.type” : “json”
},
“index” : {
“index” : “kafka-index”,
“type” : “status”,
“bulk.size” : 3,
“concurrent.requests” : 1,
“action.type” : “index”,
“flush.interval” : “12h”
}
}’

 

启动logstash

bin/logstash -f logstash.conf

 

在terminal上执行一些命令,数据就由logstash传到kafka,再传到elasticSearch上,可以在上面直接查看历史命令。

Confluent的schema-registry的使用

git clone https://github.com/confluentinc/schema-registry.git

cd schema-registry
git checkout tags/v2.0.0
mvn clean package -DskipTests

vi config/schema-registry.properties
设置kafkastore.connection.url为zookeeper的连接地址

nohup ./bin/schema-registry-start ./config/schema-registry.properties &

查看schema-registry进程
[adadmin@s11 ~]$ jps
26995 NodeManager
74580 Kafka
61079 SchemaRegistryMain
62615 Jps
126392 Worker
26843 DataNode
118141 QuorumPeerMain

#producer 注意:输入一条数据才enter一次,退出使用ctrl + C
./bin/kafka-avro-console-producer –broker-list 10.121.93.50:9092 –topic test –property value.schema='{“type”:”record”,”name”:”myrecord”,”fields”:[{“name”:”f1″,”type”:”string”}]}’
{“f1”: “value1”}
{“f1”: “value2”}
{“f1”: “value3”}

./bin/kafka-avro-console-consumer –broker-list 10.121.93.50:9092 –topic test-avro –from-beginning

Linux history的详解

经常使用linux内置的history命令查看历史,在当前用户下面有个.bash_history文件用于保存历史命令,另外$HISTSIZE环境变量是保存最大条数。在当前shell环境中,命令放在内存中,退出时将最近$HISTSIZE条命令保存在.bash_history上,也可以使用history -a(从登录起到现在的命令)手工保存,另外history -w将当前命令保存下来。如果想命令立刻保存下来,可以在.bashrc中设置环境变量export PROMPT_COMMAND=’history -a’

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”

Tensorflow安装一个小问题

环境: Ubuntu 14.04

 

export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl

sudo pip install –upgrade $TF_BINARY_URL

python

import tensorflow

出现AttributeError: type object ‘NewBase’ has no attribute ‘is_abstract’

 

解决方法:

python

import six

print(six.__file__) 查看路径

重新安装

sudo pip uninstall six

sudo pip install six –upgrade –target=”/usr/lib/python2.7/dist-packages”