【事件中心 Azure Event Hub】在Linux环境中(Ubuntu)安装Logstash的简易步骤及配置连接到Event Hub

在文章(【事件中心 Azure Event Hub】使用Logstash消费EventHub中的event时遇见的几种异常(TimeoutException, ReceiverDisconnectedException))中,介绍了使用Logstash连接EventHub时,遇见的两种异常,但是对于如何在Linux环境中安装Logstash,并且配置EventHub设置,启动等,则包含在当前文章中。

安装Logstash

首先在Logstash中选择需要的版本,使用wget下载到当前目录中,如当前使用的版本为最新7.9.1(https://www.elastic.co/downloads/logstash)

wget https://artifacts.elastic.co/downloads/logstash/logstash-7.9.1.tar.gz //下载logstash-7.9.1.tar.gz
 tar xzvf logstash-7.9.1.tar.gz //解压logstash-7.9.1.tar.gz到当前目录

进入Logstash的文件夹中

cd logstash-7.9.1

启动logstash(Logstash的启动文件在安装的版本文件夹中bin目录中)

bin/logstash -e 'input { stdin {} } output { stdout {} }'

启动成功后的结果如:

 

添加EventHub配置文件

准备条件:

  • 创建好EventHub中的实例(EventHub Namespace -> EventHub Instance), 在Event Hub Instance中获取连接字符串(Share Access Policy)
  • 为Logstash单独创建一个新的消费组
  • 创建好一个Storage Account, 并复制出连接字符串(Azure Portal-> Blob Storage account -> Access keys.)

创建配置文件(如eventhub.conf), 并使用VIM命令编辑内容

echo ""->eventhub.conf

vim eventhub.conf //打开eventhub.conf并编辑内容

在VIM编辑页面,在键盘输入I,是文件进入编辑模式,复制如下内容(关键点替换为准备条件中的内容)

input {
   azure_event_hubs {
      event_hub_connections => ["Endpoint=sb://xxxx.servicebus.chinacloudapi.cn/;SharedAccessKeyName=test;SharedAccessKey=xxxxxxxx=;EntityPath=xxxxxx"]
      threads => 8
      decorate_events => true
     consumer_group => "xxxx"
     storage_connection => "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxxxxxx=;EndpointSuffix=core.chinacloudapi.cn"
   }
  } output { stdout {
   }
 }

然后按住Esc,输入 :wq,然后回车保存内容并退出vim窗口。

使用 -f 并指定配置文件,再次启动Logstash,验证已经连接到EventHub并接受Event。以上步骤,完成的命令如下:

root@lblinuxtest01:/logstash-7.9.1# echo ""->eventhub.conf //创建新文件
root@lblinuxtest01:/logstash-7.9.1# ls
CONTRIBUTORS  LICENSE.txt  config         eventhubtest.conf         logs                      modules  x-pack
Gemfile       NOTICE.TXT   data           eventhubwithstorage.conf  logstash-core             tools
Gemfile.lock  bin          eventhub.conf  lib                       logstash-core-plugin-api  vendor

root@lblinuxtest01:/logstash-7.9.1# vim eventhub.conf //编辑文件内容
root@lblinuxtest01:/logstash-7.9.1# ./bin/logstash -f eventhub.conf  //使用新的配置文件,启动logstash

启动结果如下:

 

 

参考资料

Logstash的Azure Event Hub Plugin文档: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-azure_event_hubs.html

 

posted @ 2020-09-24 21:36  路边两盏灯  阅读(356)  评论(0编辑  收藏  举报