转载

ELK详细搭建流程


一、ELk定义及特点

参考:ELK用途及定义

二、Elasticsearch安装部署

1.下载地址

官网下载地址:Download Elasticsearch | Elastic

国内下载地址:Index of elasticsearch-local

通过wget进行下载,未开通的可使用rz命令进行上传到指定目录列表。本文通过rz进行源码包上传,仅供参考。

wget https://mirrors.huaweicloud.com/elasticsearch/7.8.0/elasticsearch-7.8.0-linux-x86_64.tar.gz

2.解压到指定目录。

本次试验是在/data0/PRG/ELK目录下,根据实际情况进行目录修改。

#新建elasticsearch安装文件夹
root@ht-80:~# mkdir /data0/PRG/ELK
 
#解压elasticsearch压缩包到指定目录
root@ht-80:/data0/PRG/ELk# tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /data0/PRG/ELk

3.修改配置文件

#切换到elasticsearch安装目录config下
root@ht-80:/data0/PRG/ELk# cd elasticsearch-7.8.0/config
 
#vim编辑yml文件
root@ht-80:/config# vim elasticsearch.yml
 
#修改一下内容
#添加节点名称
node.name: node-1 
#允许外部访问
network.host: 0.0.0.0 
#添加master节点,如有多个在[]中用逗号相隔。
cluster.initial_master_nodes: ["node-1"]

4.启动elasticsearch

Elasticsearch 不允许以 root 用户运行出于安全考虑。Elasticsearch 需要以非 root 用户身份运行,以防止潜在的安全风险,比如对系统文件的未授权访问。

需要先创建一个elasticsearch专用用户:adduser es

#切换至es用户,启动
es@ht-80:/$ su es
 
#进入elasticsearch下的bin目录启动
 
es@ht-80:/bin$ ./elasticsearch

注意:

1.jdk的问题,根据使用的elasticsearch版本,对应有jdk的要求,具体查看elasticsearch官网,再次本次是没有的

2.[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] ERROR: Elasticsearch did not exit normally - check the logs at /data0/PRG/ELk/elasticsearch-7.8.0/logs/elasticsearch.log

出现这种问题需要设置虚拟内存。

系统的 vm.max_map_count 值设置得太低。这个值需要被增加到至少 262144,以支持 Elasticsearch 的正常运行。

既然你已经知道了需要调整的配置项,接下来就是按照之前的指导来修改这个设置。以下是具体的步骤:

1. 临时修改 vm.max_map_count(重启后失效)

快速启动 Elasticsearch 而不需要永久更改设置,使用以下命令:

sudo sysctl -w vm.max_map_count=262144
(执行这个命令后,你应该能够重新启动 Elasticsearch 并查看它是否能够正常启动。)

2. 永久修改 vm.max_map_count(重启后依然有效)

如果你希望这个更改在系统重启后仍然有效,你需要编辑 /etc/sysctl.conf 文件:

sudo nano /etc/sysctl.conf
在最后添加这一句
vm.max_map_count=262144

保存并关闭文件后,运行以下命令来应用更改:
sudo sysctl -p
重新加载 sysctl 配置,使更改生效。然后再次重启elasticsearch。

5.成功重启后访问http:ip:9200端口如表示如下,及启动成功。

{
    "name": "node-1",
    "cluster_name": "elasticsearch",
    "cluster_uuid": "02XtPZyZRT-jAYwMXlH-Yw",
    "version": {
        "number": "7.8.0",
        "build_flavor": "default",
        "build_type": "tar",
        "build_hash": "757314695644ea9a1dc2fecd26d1a43856725e65",
        "build_date": "2020-06-14T19:35:50.234439Z",
        "build_snapshot": false,
        "lucene_version": "8.5.1",
        "minimum_wire_compatibility_version": "6.8.0",
        "minimum_index_compatibility_version": "6.0.0-beta1"
    },
    "tagline": "You Know, for Search"
}

三、Logstach安装部署

1.下载Logstach

压缩包下载:logstash-download

Logstach版本与elasticsearch版本一致

2.解压

root@ht-80:/data0/PRG/ELk# tar -zxvf logstash-7.8.0.tar.gz

3.备份

备份:logstach-sample.conf文件

root@ht-80:/config# cp logstash-sample.conf logstash-eslog.conf
root@ht-80:/config# vim logstash-sample.conf

修改为以下内容:

input {
  beats {
    port => 5044
  }
}
 
output {
  elasticsearch {
    hosts => ["http://localhost:9200"]
  }
  stdout{
    codec => rubydebug
 
  }
}

4.启动Logstatic

root@ht-80:/bin# nohup ./logstash -f ./config/logstash-sample.conf &
  • 注意:如无法启动需要更换Gem,#修改Gemfile改成如下所示: source "https://ruby.taobao.org"

四、kibana安装部署

1.下载kibana

下载地址:kibana-download

  • 版本需要跟elasticsearch版本一致

2.解压

root@ht-80:/data0/PRG/ELk# tar -zxvf kibana-7.8.0-linux-x86_64.tar.gz

3.修改config下配置文件

root@ht-80:/config# vim kibana.yml
server.port: 5601        #服务端口
server.host: "0.0.0.0"   #服务器ip地址或者0.0.0.0
elasticsearch.hosts: ["http://localhost:9200"]  #Elasticsearch 服务地址
i18n.locale: "zh-CN"     #设置语言为中文

4.授权es账户

root@ht-80:/data0/PRG/ELk/# chown -R es /data0/PRG/ELk/kibana-7.8.0-linux-x86_64

5.切换用户并启动

#切换用户
root@ht-80:/data0/PRG/ELk# su es
#后台启动
es@ht-80:/bin$ nohup ./kibana &

6.访问kibana

地址为:http:本地ip:5601


声明:本文转载至CSDN --> ELK详细搭建流程

CentOS
日志

评论