【事件中心 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
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?