Logstash 7.x 的安裝與數據導入(阿里雲)

接上篇:Kibana 7.x 的安裝與界面預覽(阿里雲Ubuntu)html

系統環境

  • 操做系統:Ubuntu 18.04 LTS(阿里雲)
  • 系統IP
# 內網,私有地址
172.內.內.內
# 外網,公有地址
112.外.外.外
  • Elasticsearch 版本:7.2
  • Kibana 版本:7.2
  • Logstash 版本:7.2

安裝與配置

~$ sudo apt install default-jdk
~$ java -version
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing)
  • 下載 logstash
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.2.0.tar.gz
  • 解壓 logstash
tar -zxf logstash-7.2.0.tar.gz
  • 後續操做在 logstash-7.2.0 內目錄進行
cd logstash-7.2.0/
  • 到 grouplens 下載 MovieLens 測試數據集
wget http://files.grouplens.org/datasets/movielens/ml-latest-small.zip
  • 解壓測試數據集
unzip ml-latest-small.zip
  • 建立並編輯 logstash.conf 文件,添加以下內容(Ruby 語法)
input {
  file {
    path => "/home/walker/es/ml-latest-small/movies.csv"
    start_position => "beginning"
    sincedb_path => "/dev/null"
  }
}
filter {
  csv {
    separator => ","
    columns => ["id","content","genre"]
  }
  mutate {
    split => { "genre" => "|" }
    remove_field => ["path", "host","@timestamp","message"]
  }
  mutate {

    split => ["content", "("]
    add_field => { "title" => "%{[content][0]}"}
    add_field => { "year" => "%{[content][2]}"}
  }
  mutate {
    convert => {
      "year" => "integer"
    }
    strip => ["title"]
    remove_field => ["path", "host","@timestamp","message","content"]
  }
}
output {
   elasticsearch {
     hosts => "http://172.18.193.52:9200"
     index => "movies"
     document_id => "%{id}"
   }
  stdout {}
}
  • 導入數據,注意導入後不會自動退出,用 Ctrl-C 手動退出
# 我的路徑有所不一樣
./bin/logstash -f /home/walker/es/ml-latest-small/logstash.conf
  • Management 查看數據(Index 至關於關係型數據庫的 Table)

圖片描述

  • 關係型數據庫與 Elasticsearch 的抽象與類比

圖片描述

  • Dev tools 查看文檔總數(即數據總條數)
# 查看數據總量
GET /movies/_count

# 控制檯輸出
{
  "count" : 9743,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}

圖片描述

  • 查看 id 爲 1 的數據
# 查看 id 爲 1 的數據
GET /movies/_doc/1

# 控制檯輸出
{
  "_index" : "movies",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 1,
  "_seq_no" : 121,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    "@version" : "1",
    "genre" : [
      "Adventure",
      "Animation",
      "Children",
      "Comedy",
      "Fantasy"
    ],
    "year" : 1995,
    "id" : "1",
    "title" : "Toy Story"
  }
}
  • 刪除 movies 數據(Elasticsearch 的 Index 可對標關係型數據庫的 Table)
# 刪除命令
DELETE /movies

# 控制檯輸出
{
  "acknowledged" : true
}

walker 的目錄結構

$ tree /home/walker/es/ -L 2
/home/walker/es/
├── elasticsearch-7.2.0
│   ├── bin
│   ├── config
│   ├── data
│   ├── jdk
│   ├── lib
│   ├── LICENSE.txt
│   ├── logs
│   ├── modules
│   ├── NOTICE.txt
│   ├── plugins
│   └── README.textile
├── elasticsearch-7.2.0-linux-x86_64.tar.gz
├── kibana-7.2.0-linux-x86_64
│   ├── bin
│   ├── built_assets
│   ├── config
│   ├── data
│   ├── LICENSE.txt
│   ├── node
│   ├── node_modules
│   ├── NOTICE.txt
│   ├── optimize
│   ├── package.json
│   ├── plugins
│   ├── README.txt
│   ├── src
│   ├── target
│   ├── webpackShims
│   └── x-pack
├── kibana-7.2.0-linux-x86_64.tar.gz
├── logstash-7.2.0
│   ├── bin
│   ├── config
│   ├── CONTRIBUTORS
│   ├── data
│   ├── Gemfile
│   ├── Gemfile.lock
│   ├── lib
│   ├── LICENSE.txt
│   ├── logs
│   ├── logstash-core
│   ├── logstash-core-plugin-api
│   ├── modules
│   ├── NOTICE.TXT
│   ├── tools
│   ├── vendor
│   └── x-pack
├── logstash-7.2.0.tar.gz
├── ml-latest-small
│   ├── links.csv
│   ├── logstash.conf
│   ├── movies.csv
│   ├── ratings.csv
│   ├── README.txt
│   └── tags.csv
└── ml-latest-small.zip
本文是阮一鳴《 Elasticsearch核心技術與實戰》的學習筆記。
相關文章
相關標籤/搜索