
# Logstash对接OBS
#### 概述
Logstash能够从多个来源采集数据、转换数据并将数据发送到存储系统中，具体请参见[++Logstash++](https://www.elastic.co/cn/logstash)。本文用于描述Logstash如何对接使用OBS。
#### 注意事项
请使用较新版本的logstash，例如≥7.10.2的版本，避免使用较老版本的logstash。
#### 对接步骤
以logstash-7.10.2为例。
1. 下载logstash-7.10.2-linux-x86_64.tar.gz，并解压到/opt/logstash-7.10.2-linux-x86_64目录。
2. 验证是否对接成功。 
   示例：以file为源端，以OBS为目的端。
   1. 创建配置文件file2obs.conf。参数说明见[表1]，更多详情请参见[这里](https://www.elastic.co/guide/en/logstash/7.x/plugins-outputs-s3.html)。
      ```
      input {
        file {
          path => "/opt/nginx/logs/access.log"
          start_position => "beginning"
        }
      }
      output {
        s3 {
          endpoint => "obs endpoint"   # The endpoint should be an HTTP or HTTPS URL
          access_key_id => "ak"
          secret_access_key => "sk"
          bucket => "obs bucket name"
          size_file => 1048576
          time_file => 1
          prefix => "logstash/"
          enable_metric => true
        }
      }
      ```
       表1参数说明 
      | 参数                | 说明                                                                                                                                                                                                                                                                                               |
      |:---|:---|
      | endpoint          | OBS的endpoint，例如 - https://obs.cn-north-4.myhuaweicloud.com  - http://obs.cn-north-4.myhuaweicloud.com   |
      | access_key_id     | 具备访问OBS权限的ak。                                                                                                                                                                                                                                                                                    |
      | secret_access_key | 具备访问OBS权限的sk。                                                                                                                                                                                                                                                                                    |
      | bucket            | OBS的桶名称。                                                                                                                                                                                                                                                                                         |
      | size_file         | 指定文件滚动大小（字节）。当文件大小达到设定的值时，会生成一个新的文件。                                                                                                                                                                                                                                                             |
      | time_file         | 设置文件滚动周期（分钟）。当数据写入达到设定周期时，会生成一个新的文件。                                                                                                                                                                                                                                                             |
      | prefix            | 指定文件存储的目录，例如"logstash/"，此时文件会写入到桶的logstash/目录下（注意路径不要以/开头）。                                                                                                                                                                                                                                      |
         
      
   
   2. 执行以下命令，运行logstash。 **bin/logstash -f ../conf/file2obs.conf**
      
   
   
   
   
 
