Storm之——Storm+Kafka+Flume+Zookeeper+MySQL实现数据实时分析

一、服务器配置

Storm:apache-storm-1.1.1.tar.gz

下载地址为:https://archive.apache.org/dist/storm/apache-storm-1.1.1/apache-storm-1.1.1.tar.gz

下载地址:http://www.apache.org/dyn/closer.lua/flume/1.8.0/apache-flume-1.8.0-bin.tar.gz

Kafka:kafka_2.12-1.0.0.tgz

下载地址:https://www.apache.org/dyn/closer.cgi?path=/kafka/1.0.0/kafka_2.12-1.0.0.tgz

Zookeeper:3.4.9

MySQL:5.6

二、环境搭建

1、安装Zookeeper

2、安装MySQL

3、Flume安装

依次输入以下命令安装Flume

wgethttp://mirrors.shu.edu.cn/apache/flume/1.8.0/apache-flume-1.8.0-bin.tar.gz

cd apache-flume-1.8.0-bin/conf

vimflume-conf.properties

输入的内容如下:

a1.sources = r1

a1.sinks = k1

a1.channels = c1

# Describe/configure the source

a1.sources.r1.command = tail -F /home/flume/log.log

# Describe the sink

# Use a channel which buffers events in memory

# Bind the source and sink to the channel

输入wq退出。

注意:我们的Flume配置中,监听了/home/flume/log.log作为日志的数据来源,同时我们将监听到的日志发送到Kafka的wordCount主题上。

输入以下命令启动Flume

bin/flume-ng agent --conf conf --conf-file conf/flume-conf.properties --name a1 -Dflume.root.logger=INFO,console

4、安装Kafka

依次输入以下命令安装Kafka

wgethttp://mirrors.tuna.tsinghua.edu.cn/apache/kafka/1.0.0/kafka_2.12-1.0.0.tgz

tar -zxvf kafka_2.12-1.0.0.tgz

cd kafka_2.12-1.0.0/config

vimserver.properties

内容如下:

# Licensed to the Apache Software Foundation (ASF) under one or more

# contributor license agreements. See the NOTICE file distributed with

# this work for additional information regarding copyright ownership.

# The ASF licenses this file to You under the Apache License, Version 2.0

# (the "License"); you may not use this file except in compliance with

# the License. You may obtain a copy of the License at

#

#http://www.apache.org/licenses/LICENSE-2.0

#

# Unless required by applicable law or agreed to in writing, software

# distributed under the License is distributed on an "AS IS" BASIS,

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.

# see kafka.server.KafkaConfig for additional details and defaults

############################# Server Basics #############################

# The id of the broker. This must be set to a unique integer for each broker.

broker.id=0

############################# Socket Server Settings #############################

# The address the socket server listens on. It will get the value returned from

# java.net.InetAddress.getCanonicalHostName() if not configured.

# FORMAT:

# listeners = listener_name://host_name:port

# EXAMPLE:

# listeners = PLAINTEXT://your.host.name:9092

listeners=PLAINTEXT://:9092

port=9092

# Hostname and port the broker will advertise to producers and consumers. If not set,

# it uses the value for "listeners" if configured. Otherwise, it will use the value

# returned from java.net.InetAddress.getCanonicalHostName().

# advertised.listeners=PLAINTEXT://192.168.209.121:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details

# The number of threads that the server uses for receiving requests from the network and sending responses to the network

# The number of threads that the server uses for processing requests, which may include disk I/O

# The send buffer (SO_SNDBUF) used by the socket server

# The receive buffer (SO_RCVBUF) used by the socket server

# The maximum size of a request that the socket server will accept (protection against OOM)

############################# Log Basics #############################

# A comma seperated list of directories under which to store log files

log.dirs=/usr/local/kafka_2.12-1.0.0/kafka-logs

# The default number of log partitions per topic. More partitions allow greater

# parallelism for consumption, but this will also result in more files across

# the brokers.

num.partitions=1

# The number of threads per data directory to be used for log recovery at startup and flushing at shutdown.

# This value is recommended to be increased for installations with data dirs located in RAID array.

############################# Internal Topic Settings #############################

# The replication factor for the group metadata internal topics "__consumer_offsets" and "__transaction_state"

# For anything other than development testing, a value greater than 1 is recommended for to ensure availability such as 3.

############################# Log Flush Policy #############################

# Messages are immediately written to the filesystem but by default we only fsync() to sync

# the OS cache lazily. The following configurations control the flush of data to disk.

# There are a few important trade-offs here:

# 1. Durability: Unflushed data may be lost if you are not using replication.

# 2. Latency: Very large flush intervals may lead to latency spikes when the flush does occur as there will be a lot of data to flush.

# 3. Throughput: The flush is generally the most expensive operation, and a small flush interval may lead to exceessive seeks.

# The settings below allow one to configure the flush policy to flush data after a period of time or

# every N messages (or both). This can be done globally and overridden on a per-topic basis.

# The number of messages to accept before forcing a flush of data to disk

# The maximum amount of time a message can sit in a log before we force a flush

############################# Log Retention Policy #############################

# The following configurations control the disposal of log segments. The policy can

# be set to delete segments after a period of time, or after a given size has accumulated.

# A segment will be deleted whenever *either* of these criteria are met. Deletion always happens

# from the end of the log.

# The minimum age of a log file to be eligible for deletion due to age

# A size-based retention policy for logs. Segments are pruned from the log unless the remaining

# The maximum size of a log segment file. When this size is reached a new log segment will be created.

# The interval at which log segments are checked to see if they can be deleted according

# to the retention policies

############################# Zookeeper #############################

# Zookeeper connection string (see zookeeper docs for details).

# This is a comma separated host:port pairs, each corresponding to a zk

# server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002".

# You can also append an optional chroot string to the urls to specify the

# root directory for all kafka znodes.

zookeeper.connect=192.168.209.121:2181

# Timeout in ms for connecting to zookeeper

############################# Group Coordinator Settings #############################

# The following configuration specifies the time, in milliseconds, that the GroupCoordinator will delay the initial consumer rebalance.

# The default value for this is 3 seconds.

# We override this to 0 here as it makes for a better out-of-the-box experience for development and testing.

# However, in production environments the default value of 3 seconds is more suitable as this will help to avoid unnecessary, and potentially expensive, rebalances during application startup.

之后我们输入如下命令启动Kafka并创建主题wordCount

启动Kafka

./bin/kafka-server-start.sh /usr/local/kafka_2.12-1.0.0/config/server.properties

后台启动Kafka

./bin/kafka-server-start.sh -daemon /usr/local/kafka_2.12-1.0.0/config/server.properties

然后我们在Kafka上创建wordCount主题

./bin/kafka-topics.sh --create --zookeeper 192.168.209.121:2181 --replication-factor 1 -partitions 3 --topic wordCount

5、安装Storm

依次输入以下命令安装配置Storm

https://archive.apache.org/dist/storm/apache-storm-1.1.1/apache-storm-1.1.1.tar.gz

tar -zxvf apache-storm-1.1.1.tar.gz

cd apache-storm-1.1.1/conf

vim storm.yaml

内容如下:

#

## List of custom kryo decorators

# - org.mycompany.MyDecorator

#

## Locations of the drpc servers

drpc.servers:

- "liuyazhuang121"

# - "server2"

## Metrics Consumers

## whitelist / blacklist

## - when none of configuration for metric filter are specified, it'll be treated as 'pass all'.

## - you need to specify either whitelist or blacklist, or none of them. You can't specify both of them.

## - you can specify multiple whitelist / blacklist with regular expression

## expandMapType: expand metric with map type as value to multiple metrics

## - set to true when you would like to apply filter to expanded metrics

## - default value is false which is backward compatible value

## metricNameSeparator: separator between origin metric name and key of entry from map

## - only effective when expandMapType is set to true

# parallelism.hint: 1

# - class: "org.mycompany.MyMetricsConsumer"

# whitelist:

# - "execute.*"

# - "^__complete-latency$"

# parallelism.hint: 1

# argument:

# expandMapType: true

# metricNameSeparator: "."

## Cluster Metrics Consumers

# - class: "org.mycompany.MyMetricsConsumer"

# argument:

#

storm.local.dir: /home/storm

- 6700

- 6701

- 6702

- 6703

"storm.yaml" 92L, 3366C written

[root@liuyazhuang121 conf]#

[root@liuyazhuang121 conf]#

[root@liuyazhuang121 conf]# pwd

/usr/local/apache-storm-1.1.1/conf

[root@liuyazhuang121 conf]# vim storm.yaml

#

## List of custom kryo decorators

# - org.mycompany.MyDecorator

#

## Locations of the drpc servers

drpc.servers:

- "liuyazhuang121"

# - "server2"

## Metrics Consumers

## whitelist / blacklist

## - when none of configuration for metric filter are specified, it'll be treated as 'pass all'.

## - you need to specify either whitelist or blacklist, or none of them. You can't specify both of them.

## - you can specify multiple whitelist / blacklist with regular expression

## expandMapType: expand metric with map type as value to multiple metrics

## - set to true when you would like to apply filter to expanded metrics

## - default value is false which is backward compatible value

## metricNameSeparator: separator between origin metric name and key of entry from map

## - only effective when expandMapType is set to true

# parallelism.hint: 1

# - class: "org.mycompany.MyMetricsConsumer"

# whitelist:

# - "execute.*"

# - "^__complete-latency$"

# parallelism.hint: 1

# argument:

# expandMapType: true

# metricNameSeparator: "."

## Cluster Metrics Consumers

# - class: "org.mycompany.MyMetricsConsumer"

# argument:

#

storm.local.dir: /home/storm

- 6700

- 6701

- 6702

- 6703

输入以下命令启动storm

nohup ./bin/storm nimbus >> /dev/null &

nohup ./bin/storm ui >> /dev/null &

nohup ./bin/storm supervisor >> /dev/null &

nohup ./bin/storm drpc >> /dev/null &

作者:冰 河

声明:推送内容及图片来源于网络,部分内容会有所改动,版权归原作者所有

如来源信息有误或侵犯权益,请联系我们删除或授权事宜。谢谢!

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20181028A0VS8E00?refer=cp_1026
  • 腾讯「云+社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 yunjia_community@tencent.com 删除。

扫码关注云+社区

领取腾讯云代金券