CentOS7.4下ELK6.2.4从零开始安装部署

项目中处理日志用到elk,我的项目使用docker镜像运行的,今天使用离线安装包操作一下

hostnamectl set-hostname node-1

环境说明:CentOS7.4、jdk1.8等
下面是安装过程
首先是确认环境rpm -qa|grep Java
如果有其他版本的请删除
rpm–e --nodeps java-*
检查是否删除
java –version

# 开始安装jdk1.8自行从Oracle官网下载

http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
解压改名设置环境变量
 vim /etc/profile在末行加入
export JAVA_HOME=/usr/local/jdk1.8
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib/dt.JAVA_HOME/lib/tools.jar:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:${PATH}
配置设置source /etc/profile
测试java -version

# 设置内核参数
vim /etc/sysctl.conf
增加以下参数
vm.max_map_count=655360
执行以下命令,确保生效配置生效:
sysctl  -p
设置资源参数
vim /etc/security/limits.conf
#修改
* soft nofile 65536
* hard nofile 131072
* soft nproc 65536
* hard nproc 131072
#设置elk用户参数
vim /etc/security/limits.d/20-nproc.conf
elk        soft    nproc    65536
elk用户默认已经创建

 

ELK官网下载地址
https://www.elastic.co/cn/downloads
所有组件都在根据自己喜欢下
# elasticsearch-6.2.4(3台)
解压到/usr/local改名elasticsearch
 chown -R elk.elk  elasticsearch/
到解压目录下

vim config/elasticsearch.yml 同样是末行加入
#这里指定的是集群名称,需要修改为对应的,开启了自发现功能后,ES会按照此集群名称进行集群发现
cluster.name: elk123
#数据目录
path.data:  data/elk/data
#log目录
path.logs:  data/elk/logs
#节点名称(3台1-3)
node.name: node-1
#修改一下ES的监听地址,这样别的机器也可以访问
network.host: 0.0.0.0
#默认的端口号以及访问
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
##集群以及节点数
discovery.zen.ping.unicast.hosts: ["192.168.1.112", "192.168.1.113","192.168.1.114"]
discovery.zen.minimum_master_nodes: 3

注意配置冒号后有空格,新建日志和数据目录给
mkdir -p /data/elk/log
mkdir -p /data/elk/data

 

 chown -R elk.elk /data/
 启动elasticsearch
 su elk -c "/usr/local/elasticsearch/bin/elasticsearch -d "

 测试访问ip:9200

 es集群可视化(5.0以后ES不再提供内置)
# elasticsearch-head安装
依赖安装
yum install git nodejs npm
检测 git clone git://github.com/mobz/elasticsearch-head.git
node -v
npm -v
到目录下 npm install -g cnpm --registry=https://registry.npm.taobao.org
vim /usr/local/elasticsearch/config/elasticsearch.yml 末行加入
http.cors.enabled: true
http.cors.allow-origin: "*"
cd elasticsearch-head/
vim Gruntfile.js
在connect属性中,增加hostname: ‘0.0.0.0’
      connect: {
                        server: {
                                options: {
                                        hostname: '0.0.0.0',
                                        port: 9100,
                                        base: '.',
                                        keepalive: true

vi _site/app.js
#编辑配置文件,填写elasticsearch server的地址
init: function(parent) {
                        this._super();
                        this.prefs = services.Preferences.instance();
                        this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://es_ip:9200";
                        if( this.base_uri.charAt( this.base_uri.length - 1 ) !== "/" ) {
                                // XHR request fails if the URL is not ending with a "/"
                                this.base_uri += "/";
                        }
#启动程序
cnpm install -g grunt
重启es
启动elasticsearch-head
nohup grunt server &
#访问web
http://xxx:9100
![](https://s1.51cto.com/images/blog/201805/02/fb0078a6d200c842ae351f66b1e8165b.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

#  kibana-6.2.4(单台即可)
解压安装改名
cd  kibana/
vim config/kibana.yml
#开启默认端口5601如果5601被占用可用5602或其他
server.port: 5601
server.host:  “hostname”  这里填你的主机名
#指向elasticsearch服务的ip地址
elasticsearch.url: http://localhost:9200
kibana.index: “.kibana”
启动
/usr/local/kibana/bin/kibana &

测试ip:5601

# logstash-6.2.4
这个要安装在你日志所在服务器上
解压安装改名到目录下
vim config/*-logst.conf新建一个配置文件名字自定

input{
file {
path => "/usr/loca/*.log"  #你的日志路径
start_position => beginning
ignore_older => 0
sincedb_path =>"/dev/null"
}}
filter{
grok {
match => { "message" =>"%{IPORHOST:clientip} - %{USER:auth}
\"(?:%{WORD:verb}%{NOTSPACE:request}(?: HTTP/%{NUMBER:httpversion})?|%{DATA:rawrequest})\"%{NUMBER:response} (?:%{NUMBER:bytes}|-)"}
}date {
match => [ "timestamp" ,"dd/MMM/YYYY:HH:mm:ss +0800" ]
}
}
output{
elasticsearch {  hosts => ["ip:9200" ]  index => "logs-%{+YYYY.MM.dd}" }
stdout {}
}
该配置只是匹配单个项目如果多个请参考以下

input {
    file {
        path => "/var/log/messages"
        type => "system"
        start_position => "beginning"
    }
    file {
        path => "/var/log/elasticsearch/chuck-clueser.log"
        type => "es-error"
        start_position => "beginning"
        codec => multiline {
            pattern => "^\["
            negate => true
            what => "previous"
        }
    }
}
output {
    if [type] == "system" {
        elasticsearch {
            hosts => ["192.168.56.11:9200"]
            index => "system-%{+YYYY.MM.dd}"
        }
    }
    if [type] == "es-error" {
        elasticsearch {
            hosts => ["192.168.56.11:9200"]
            index => "es-error-%{+YYYY.MM.dd}"
        }
    }
}
然后启动
/usr/local/logstash/bin/logstash -f /usr/local/logstash/config/*-logst.conf
然后去kibana看下是否有数据!要先创建索引!
此安装模式ELK的head和kibana基本等于无任何安全措施,建议基于nginx反向代理IP限制或者内网使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
开源实时日志分析ELK平台能够完美的解决我们上述的问题,ELK由ElasticSearch、Logstash和Kiabana三个开源工具组成。 官方网站:https://www.elastic.co/products Elasticsearch是个开源分布式搜索引擎,它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。 Logstash是一个完全开源的工具,他可以对你的日志进行收集、过滤,并将其存储供以后使用(如,搜索)。 Kibana 也是一个开源和免费的工具,它Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助您汇总、分析和搜索重要数据日志。 ELK下载:https://www.elastic.co/downloads/ ELK工作原理: ElasticSearch 配置ElasticSearch: 1 2 unzip elasticsearch-6.2.4.zip cd elasticsearch-6.2.4 然后编辑ES的配置文件: 1 vi config/elasticsearch.yml 修改以下配置项: 1 2 3 4 5 6 7 cluster.name=es_cluster node.name=node0 path.data=/tmp/elasticsearch/data path.logs=/tmp/elasticsearch/logs #当前hostname或IP,我这里是node1 network.host=node1 network.port=9200 其他的选项保持默认,然后启动ES: 1 nohup sh elasticsearch > nohup.log & 注意: 1.需要添加用户elk,ES不能以root用户进行启动 2.可能出现的错误: max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536] 1 2 3 vi /etc/security/limits.conf elk soft nofile 819200 elk hard nofile 819200 max number of threads [1024] for user [work] likely too low, increase to at least [2048] 1 2 3 4 vi /etc/security/limits.d/90-nproc.conf * soft nproc 1024 #修改为: * soft nproc 2048 max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144] 1 2 3 4 5 vi /etc/sysctl.conf #增加改行配置: vm.max_map_count=655360 #保存退出后,执行: sysctl -p 另外再配置ES的时候,threadpool.bulk.queue_size 已经变成了thread_pool.bulk.queue_size ,ES_HEAP_SIZE,ES_MAX_MEM等配置都变为ES_JAVA_OPTS这一配置项,如限制内存最大最小为1G: 1 export ES_JAVA_OPTS="-Xms1g -Xmx1g" 然后可以打开页面http://node1:9200/,将会看到以下内容:(我是通过外部访问虚拟机,因此为了简单没有配置host文件,直接用ip访问) Logstash 配置Logstash: 1 2 tar -zxvf logstash-6.2.4.tar.gz cd logstash-6.2.4 编写配置文件(名字和位置可以随意,这里我放在config目录下,取名为log_app.conf): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 vi config/log_app.config #以下为内容 input { file { path => "/usr/local/software/elk/app.log" start_position => "beginning" #从文件开始处读写 } # stdin {} #可以从标准输入读数据 } filter { #Only matched data are send to output. } output { # For detail config for elasticsearch as output, # See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html elasticsearch { action => "index" #The operation on ES hosts => "node1:9200" #ElasticSearch host, can be array. index => "applog" #The index to write data to. } } 其他的选项保持默认,然后启动Logstash: 1 2 # -f为指定配置文件 nohup sh ./bin/logstash -f ../config/log_app.config > nohup.log & 日志: Kibana 配置Kibana: 1 2 tar -zxvf kibana-6.2.4-linux-x86_64.tar.gz cd kibana-6.2.4-linux-x86_64 修改以下几项(由于是单机版的,因此host的值也可以使用localhost来代替,这里仅仅作为演示): 1 2 3 4 server.port: 5601 server.host: “node1” elasticsearch.url: http://node1:9200 kibana.index: “.kibana” 启动kibana: 1 nohup sh ./bin/kibana > nohup.log & 启动后界面: 然后需要创建index,步骤如下: ①点击左边iscover出现以下界面 ②按照注释配置,然后点击Next step,在第二页 选择@timestamp点击create创建 ③创建完成之后,可以看到以下一个界面,红框内是 自动生成的域,也可以理解为 跟数据库中的字段类似,其中有一个message字段,就是我们想要的日志信息。 ④再次点击Discover出现以下界面,可以看到默认搜索的是最后15分钟的日志,可以通过点击设置搜索的时间范围. ⑤可以点击右侧域的add设置需要显示的字段 添加完成之后,日志显示如下:

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值