ELK5.5(ElasticSearch+Logstach+Kibana)在Centos7下搭建

环境:java

centos7node

jdk1.8linux

elasticsearch5.5.0git

Logstach5.5.0github

Kibana5.5.0npm

 

安装jdk1.8bootstrap

 

因为elasticsearch是用Java写的,因此须要先安装好java环境,此处省略vim

 

安装elasticsearchcentos

 

假设安装到/usr/local/software浏览器

 

下载解压

cd /usr/local/software

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz

tar -zxvf elasticsearch-5.5.0.tar.gz

mv elasticsearch-5.5.0  elasticsearch

 

 

编辑配置文件config/elasticsearch.yml

cd elasticsearch

vim config/elasticsearch.yml

设置

 
cluster.name: my_cluster
node.name: node1

http.cors.enabled: true

http.cors.allow-origin: "*"

network.host:  0.0.0.0 或者你本身的服务器ip

http.port: 9200

 

这里须要注意的是,es 规定 root 用户不能启动 es,因此须要建立一个用户来启动 es

 

建立用户名为 elastic 的用户

useradd elastic

设置 elastic 用户的密码

passwd elastic

而后输入12345678

 

建立 es 的 data 和 logs 目录

cd elasticsearch

mkdir data

mkdir logs 

 

将 /usr/local/software/elasticsearch 的拥有者设置为 elastic

chown -R elastic:elastic /usr/local/software/elasticsearch

 

 

切换到 elastic 用户,启动 es

su elastic

加了-d是后台启动 不加是前台启动,第一次不建议后台启动,前台启动能够直观的看到日志信息

bin/elasticsearch

 

 

可能遇到的错误

 

问题:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

解决方法:

切换到root用户修改

su root

vim /etc/security/limits.conf

在最后面追加下面内容 其中elastic表示刚刚建立的用户名

elastic hard nofile 65536

elastic soft nofile 65536

修改后切换到es用户,使用以下命令查看是否修改为功

ulimit -Hn

65536

 

 

问题:max number of threads [1024] for user [lish] likely too low, increase to at least [2048]

解决方法:

切换到root用户,进入limits.d目录下修改配置文件

vim /etc/security/limits.d/90-nproc.conf 

soft nproc 1024修改为2048

 

问题:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决方法:

提升vm.max_map_count 的大小

切换到root用户

su root

vim /etc/sysctl.conf

在最后面追加下面内容

vm.max_map_count=300000

使用 sysctl -p 查看修改后的结果

sysctl -p

 

问题:Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)

解决方法:

因为elasticsearch5.x默认分配jvm空间大小为2g,修改jvm空间分配

若是使用虚拟机安装,内存最好不小于2G

vim config/jvm.options

-Xms2g

-Xmx2g

改为  

-Xms256m

-Xmx256m

在阿里云上可能会出现的问题:

system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

解决方法:在es配置文件中加入下面命令便可

vim config/elasticsearch.yml

bootstrap.system_call_filter: false

 

最后再重启服务器再启动es!!!

 

 

打开防火墙端口

systemctl start firewalld

firewall-cmd --zone=public --add-port=9200/tcp --permanent

firewall-cmd --zone=public --add-port=9300/tcp --permanent

firewall-cmd --reload

 

在肯定服务器端口(9200)开启,elasticsearch启动的状况下查看运行状况

ps -ef | grep elasticsearch

也能够在浏览器中访问测试 http://你的服务器ip:9200 能打开则表示成功

 

关闭elasticSearch

elasticsearch的进程号

ps -ef | grep elastic

用kill -9

 

 

tar.gz方式安装es实现开机自启动

 

增长一个elasticsearch.service文件

vim /usr/lib/systemd/system/elasticsearch.service

内容以下:

#!/bin/sh

export JAVA_HOME=/usr/local/software/jdk
export PATH=$JAVA_HOME/bin:$PATH

[Unit]  
Description=elasticsearch  
After=network.target  
   
[Service]
User=elastic  
Type=forking  

ExecStart=/usr/local/software/elasticsearch/bin/elasticsearch -d  
 
PrivateTmp=true  

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
 
# Specifies the maximum number of processes
LimitNPROC=2048
 
# Specifies the maximum number of bytes of memory that may be locked into RAM
# Set to "infinity" if you use the 'bootstrap.memory_lock: true' option
# in elasticsearch.yml and 'MAX_LOCKED_MEMORY=unlimited' in /etc/sysconfig/elasticsearch
#LimitMEMLOCK=infinity
 
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0
 
# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM
 
# Send the signal only to the JVM rather than its control group
KillMode=process
 
# Java process is never killed
SendSIGKILL=no
 
# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143
   
[Install]  
WantedBy=multi-user.target

 

 

设置文件权限

chmod +x  elasticsearch.service

 

设置开机启动

systemctl enable elasticsearch

启动服务

systemctl start elasticsearch

 

可能会提示

which: no java in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)

 

增长一个软链接

ln -s /usr/local/software/jdk/bin/java /usr/bin/java

 

再次执行systemctl start elasticsearch

 

可重启服务器 测试是否开机启动es服务

 

安装ik分词器

下载es的IK插件:https://github.com/medcl/elasticsearch-analysis-ik/releases(选择对应的版本,IK版本与ES版本一致)

将下载的zip包拷贝至ES_HOME/plugins/ik(ps:ik目录没有的话本身新建一个就好)

或者直接wget命令下载
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.0/elasticsearch-analysis-ik-5.5.0.zip
而后使用unzip命令解压

重启es服务

测试分词效果

curl 'http://localhost:9200/_analyze?analyzer=ik_max_word&pretty=true' -d '{"text":"这里是一篇很是优秀的文章"}'

 

 安装Head插件

 

head插件能够用来快速查看elasticsearch中的数据概况以及非全量的数据,也支持控件化查询和rest请求。

 

elasticsearch5.x不能够直接经过plugin -install mobz/elasticsearch-head安装了,

 

而且head须要在node环境下运行

 

 

安装nodejs

 

head插件是nodejs实现的,因此必须先安装Nodejs

 

su root

 

yum install -y epel-release

 

yum install -y nodejs npm

 

 

 

安装git

 

咱们这里用git方式下载head插件,也能够手动下载而后上传。

 

yum install -y git

 

git --version

 

 

 

下载并安装elasticsearch-head

 

cd /usr/local/software/

 

git clone https://github.com/mobz/elasticsearch-head.git

 

cd elasticsearch-head

 

npm install -g grunt-cli 

 

npm run start

 

 

 

修改es-head的监听地址 增长hostname属性

 

cd elasticsearch-head  #(elasticsearch-head源码文件夹)

 

vim Gruntfile.js

connect: {
        server: {
                options: {
                        hostname: '服务器ip',
                        port: 9100,
                        base: '.',
                        keepalive: true
                }
        }
}

修改es-head的链接地址

cd elasticsearch-head  #(elasticsearch-head源码文件夹)

vim _site/app.js

找到     this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";

将localhost改为es服务ip地址

 

 

修改elasticsearch参数,以便于head插件访问es

vim config/elasticsearch.yml

在elasticsearch下的elasticsearch.yml下新增一下两行:

http.cors.enabled: true

http.cors.allow-origin: "*"

而后重启es

 

打开防火墙端口

systemctl start firewalld

firewall-cmd --zone=public --add-port=9100/tcp --permanent

firewall-cmd --zone=public --add-port=9200/tcp --permanent

firewall-cmd --reload

 

启动elasticsearch-head

cd elasticsearch-head(elasticsearch-head源码文件夹)

grunt server

 

浏览器访问http://服务器ip:9100 查看head插件

 

安装Logstash

cd /usr/local/software
tar -zxvf logstash-5.5.0.tar.gz
mv logstash-5.5.0 logstash

cd logstash
编写配置文件(名字和位置能够随意,这里我放在config目录下,取名为logconfig1.config)
vim config/logconfig1.config

 

input {
        file {
                path => "/usr/local/logs/*.log"
                start_position => "beginning"
        }
        file {
                path => "/usr/local/logs/test.log"
                start_position => "beginning"
        }
}
filter {
  
}
output {
  elasticsearch {
    hosts  => "localhost:9200"
    index => "znsindex"
  }
}

其余的选项保持默认,而后启动Logstash
cd logstash

sh ./bin/logstash -f config/logconfig1.config

或者后台启动
nohup sh ./bin/logstash -f config/logconfig1.config > nohup.log 2>&1 &

 

//好比 config/目录下有
//in1.conf、in2.conf、filter1.conf、filter2.conf、out.conf这些文件
//咱们使用 sh ./bin/logstash -f /config启动logtstash
//logstash会自动加载这些配置文件,并合并成1个总体的配置文件

 

安装Kibana

cd /usr/local/software
tar -zxvf kibana-5.5.0-linux-x86_64.tar.gz
mv kibana-5.5.0-linux-x86_64 kibana
cd kibana

vim config/kibana.yml
修改如下几项(因为是单机版的,所以host的值也可使用localhost来代替)

 

server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: http://127.0.0.1:9200
kibana.index: ".kibana"

开启端口
systemctl start firewalld
firewall-cmd --zone=public --add-port=5601/tcp --permanent
firewall-cmd --reload

启动kibana

sh ./bin/kibana

或者后台启动

nohup sh ./bin/kibana > nohup.log 2>&1 &

 

启动后访问界面 http://ip:5601
点击左边Discover
按照注释配置,Define Index Pattern 为了简单直接输入*,而后点击Next step,在第二页 选择@timestamp点击create建立

过一段时间后刷新能够看到已经收集到了上面配置的路径日志信息

 

 

注:以上相关软件路径 根据本身实际状况填写

相关文章
相关标签/搜索