对象存储服务 OBS-Logstash对接OBS:对接步骤

时间:2023-11-13 17:19:42

对接步骤

以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,更多详情请参见这里
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      {
        "input": {
          "file": {
            "path" : "/opt/nginx/logs/access.log",
            "start_position" : "beginning"
          }
        },
        "output": {
          "s3": {
            "endpoint" : "obs endpoint",,
            "bucket" : "obs桶名",
            "access_key_id" : "ak",
            "secret_access_key" : "sk",
            "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

support.huaweicloud.com/bestpractice-obs/obs_05_1517.html