ELK安裝部署

不会游泳的鱼丶發表於2024-03-29

java環境

# 建立目錄
mkdir /usr/local/java/

# 解壓
tar -zxvf jdk-8u333-linux-x64.tar.gz -C /usr/local/java/

# 配置環境變數
vim /etc/profile
 
export export JAVA_HOME=/usr/local/java/jdk1.8.0_211
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

# 環境變數生效
source /etc/profile

# 新增軟連線
ln -sf /usr/local/java/jdk1.8.0_211/bin/java /usr/bin/java

# 檢查java版本
java -version

groupadd elsearch  #【新增組】【使用者組名】
useradd elsearch -g elsearch -p elsearch #【新增使用者】【使用者名稱】-g【使用者組名】-p【密碼值】

安裝 Elasticsearch

# 下載
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.16.2-linux-x86_64.tar.gz

# 解壓
tar -zxvf elasticsearch-7.16.2-linux-x86_64.tar.gz

# 設定許可權到elsearch使用者
chown -R elsearch:elsearch /usr/local/elasticsearch-7.16.2

修改配置檔案

cd /usr/local/elasticsearch-7.16.2/config

vim elasticsearch.yml

# ========== 修改內容如下 ==================

discovery.type: single-node
# 資料路徑(按實際需要配置日誌地址)
path.data: /usr/local/elasticsearch-7.16.2/data
# 日誌路徑(按實際需要配置日誌地址)
path.logs: /usr/local/elasticsearch-7.16.2/logs
# 地址(通常使用內網進行配置)
network.host: 0.0.0.0
# 埠號
http.port: 9200
# 跨域(這兩項配置手動新增一下)
http.cors.enabled: true 
http.cors.allow-origin: "*"

啟動ES

su elsearch

# 後臺方式啟動
./elasticsearch -d 

# 檢視日誌,是否啟動成功
cd /usr/local/elasticsearch-7.16.2/logs

tail
-fn 100 /usr/local/elasticsearch-7.16.2/logs/my-elasticsearch.log

config/jvm.options 可以修改啟動記憶體大小 預設4G 可以根據自己伺服器情況修改

安裝Logstash

# 下載
wget https://artifacts.elastic.co/downloads/logstash/logstash-7.16.2-linux-x86_64.tar.gz

# 解壓
tar -zxvf logstash-7.16.2-linux-x86_64.tar.gz

x修改配置

# 修改配置檔案logstash-sample.conf
cd /usr/local/logstash-7.16.2/config

# 將logstash-sample.conf檔案複製一份,並命名為logstash.conf
cp logstash-sample.conf logstash.conf

# 修改配置
vim logstash.conf

# ========== 修改內容如下 ==================
input {
  beats{
    port => 5701
  }
}

filter {
  multiline {
    pattern =>"^gateway|^service-1|^hn.kd.ny.adsl" # 根據關鍵欄位進行分割 展示
    negate => true
    what => "previous"
  }

  

  if "crm-business" in [fields][project] {
    mutate {
      add_field => { "index_prefix" => "crm-business" }
    }
  }
  else if "crm-businessclue" in [fields][project] {
    mutate {
      add_field => { "index_prefix" => "crm-businessclue" }
    }
  }

  else {
    mutate {
      add_field => { "index_prefix" => "filebeat-default" }
      }
  }
}



# 以下配置為建立使用者索引及預設索引情況


output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
    #index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
    index => "%{[index_prefix]}-%{+YYYY.MM.dd}"
    user => "elastic"
    password => "admin123"
    }
}

 

Logstash啟動

cd /usr/local/logstash-7.16.2/bin

# 啟動命令
nohup ./logstash -f /usr/local/logstash-7.16.2/config/logstash.conf >../logs/logstash.log &

# 使用jps命令檢視執行的程序
jps

# config/jvm.options 這個可以更改logstash的記憶體大小,可以進行調測

Kibana 安裝

# 下載
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.16.2-linux-x86_64.tar.gz

# 解壓
tar -zxvf kibana-7.16.2-linux-x86_64.tar.gz

# 許可權
chown -R elsearch:elsearch /usr/local/kibana-7.16.2-linux-x86_64



cd /usr/local/kibana-7.16.2-linux-x86_64/config
vim kibana.yml

# ========== 修改內容如下 ==================

# 服務埠(按實際需求)
server.port: 5601
# 服務主機(這裡是伺服器內網地址)
server.host: "0.0.0.0"
# 服務名(按實際需求)
server.name: "kibana"
# elasticsearch地址
elasticsearch.hosts: ["http://127.0.0.1:9200"]

elasticsearch.username: "kibana_system"
elasticsearch.password: "admin123"


# 設定簡體中文
i18n.locale: "zh-CN"

es資料庫跟 kibana 都不能用root啟動

啟動

cd /usr/local/kibana-7.16.2-linux-x86_64/bin

# 切換使用者
su elsearch

#非後臺啟動,關閉shell視窗即退出
./bin/kibana

# 後臺啟動
nohup ./kibana &

# 檢視程序
netstat -tunlp | grep 5601

如果啟動報錯:

Kibana環境
Kibana server is not ready yet
kibana ES版本不一致
ES 伺服器地址和 Kibana的 ES。host 配置不通 *** (一般是這個)
kibana.yml esalstearch.hosts配置 (容器的話可能會忘記配置這個)
ES 中禁止跨域訪問
esalstearch.hosts配置
防護牆埠 還有就是埠問題
ES 所在磁碟不足90%

Filebeat 安裝

官網下週 filebeat 版本儘量一致

- type: filestream

  # Unique ID among all inputs, an ID is required.
  id: my-filestream-id

  # Change to true to enable this input configuration.
  enabled: false

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /var/log/null.log
    #- c:\programdata\elasticsearch\logs\*



- type: log
  enabled: true
  paths:
    - /var/log/service/oss-service-prod1.log
  fields:
    project: "oss-service-prod1"


- type: log
  enabled: true
  paths:
    - /var/log/service/oss-service-prod2.log
  fields:
    project: "oss-service-prod2"

# filebeat 使用的事 logstash output 的方式

# ---------------------------- Elasticsearch Output ----------------------------
#output.elasticsearch:
# Array of hosts to connect to.
#hosts: ["localhost:9200"]


# Protocol - either `http` (default) or `https`.
#protocol: "https"


# Authentication credentials - either API key or username/password.
#api_key: "id:api_key"
#username: "elastic"
#password: "changeme"


# ------------------------------ Logstash Output -------------------------------
output.logstash:
  # The Logstash hosts
  hosts: ["127.0.0.1:5044"]

#hosts 是 logstash的地址 需要注意內外網 跟埠


相關文章