ELK学习笔记(一)---安装ELK 5.x版

ELK日志平台是一个完整的日志分析系统,有三个开源工具构建组成,分别是:Elasticsearch、Logstash和Kibana。Elasticsearch用于数据分析和深度搜索;Logstash作用是从其他服务器上传输和转发日志,对其集中管理,进行分析;Kibana则是提供了强大的UI展示,将数据可视化。

安装ELK日志平台

ELK基础环境需要java环境,官网要求5.x版本要大于java8。而且安装方式多样化,支持zip、tar.gz、rpm包、deb包、window环境还有docker环境。根据自己喜好选择吧。

我选择的是yum安装,简单方便,系统要求的话没有辣么严格,官网说yum安装方式不再支持centos5.x系列了,非要用centos5.x就去使用tar.gz包吧,官网有具体方法,不再复述。yum安装方式centos6.x和centos7.x都可以,但是我推荐用centos7.x安装,不知道为啥,感觉centos7.x支持更好,centos6.x装完经常会出问题。

还有一点需要说下就是,ELK各个组件版本要一致,官网要求的!

在一个就是安装顺序,为的是确保每个组件相互调用时都能正常运行:

1、Elasticsearch

  • X-Pack for Elasticsearch

Kibana

  • X-Pack for Kibana

LogstashBeatsElasticsearch Hadoop

安装Elasticsearch

1、导入Elasticsearch安装包PGP Key

rpm --import 
https://artifacts.elastic.co/GPG-KEY-elasticsearch

2、创建yum源

[[email protected] ~]# cat >> /etc/yum.repos.d/elasticsearch.repo <<EOF
> [elasticsearch-5.x]
> name=Elasticsearch repository for 5.x packages
> baseurl=https://artifacts.elastic.co/packages/5.x/yum
> gpgcheck=1
> gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
> enabled=1
> autorefresh=1
> type=rpm-md
> EOF

3、安装、启动Elasticsearch进程并开机启动

[[email protected] ~]$ sudo yum install elasticsearch
[[email protected] ~]$ sudo /bin/systemctl daemon-reload
[[email protected] ~]$ sudo /bin/systemctl enable elasticsearch.service
[[email protected] ~]$ sudo systemctl start elasticsearch.service

4、检查Elasticsearch是否已经启动

查看9200、9300是否已经启动

[[email protected] ~]$ curl http://localhost:9200
{
  "name" : "F5Mw8Pp",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "zVEeXtPNTaeH-TKah7Buzw",
  "version" : {
    "number" : "5.4.0",
    "build_hash" : "780f8c4",
    "build_date" : "2017-04-28T17:43:27.229Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.0"
  },
  "tagline" : "You Know, for Search"
}

5、配置Elasticsearch

rpm包配置文件在/etc/elasticsearch下面的elasticsearch.yml

vim /etc/elasticsearch/elasticsearch.yml
cluster.name: elasticsearch-test
node.name: node-1
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
network.host: 0.0.0.0
[[email protected] ~]$ sudo systemctl restart elasticsearch.service
[[email protected] ~]$ curl http://localhost:9200
{
  "name" : "node-1",
  "cluster_name" : "elasticsearch-test",
  "cluster_uuid" : "zVEeXtPNTaeH-TKah7Buzw",
  "version" : {
    "number" : "5.4.0",
    "build_hash" : "780f8c4",
    "build_date" : "2017-04-28T17:43:27.229Z",
    "build_snapshot" : false,
    "lucene_version" : "6.5.0"
  },
  "tagline" : "You Know, for Search"
}

6、将/etc/elasticsearch/配置拷贝到/usr/share/elasticsearch/config下面

[[email protected] ~]$ sudo mkdir /usr/local/elasticsearch/config
[[email protected] ~]$ sudo ln -sf /etc/elasticsearch/* /usr/local/elasticsearch/config/
[[email protected] ~]$ sudo chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
[[email protected] ~]$ sudo systemctl restart elasticsearch.service

注意:这一点好多人不会注意,因为你不修复也不会启动失败,但是就是写不进数据进去,这个坑好久才发现,看下日志会报错,但是却能启动,我也是服了!~

7、装个head插件

这个插件5.X官网不再支持了,插件命令没有了,因为它有自己x-pack插件了,但是我装了x-pack发现着实让人吐血,有安全认证方面的问题,导致elk各种问题出现,目前还没研究明白,时间不充裕。

这个head插件我是直接抄的网上大神制作,略有改动。

7.1、下载并配置nodejs

由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。(npm可以理解为maven)

去官网下载nodejs,https://nodejs.org/en/download/

wget https://nodejs.org/dist/v8.1.1/node-v8.1.1-linux-x64.tar.xz
tar xf node-v8.1.1-linux-x64.tar.xz
mv node-v8.1.1-linux-x64 /usr/local/node
chown -R elasticsearch:elasticsearch node/
ln -sf /usr/local/node/bin/node /usr/bin/node
ln -sf /usr/local/node/bin/npm /usr/bin/npm

7.2、安装grunt

npm install -g grunt-cli
ln -sf /usr/local/node/bin/grunt /usr/bin/grunt cd /var/lib/elasticsearch

7.3、下载、安装并配置head

yum -y install git
cd /var/lib/elasticsearch
git clone git://github.com/mobz/elasticsearch-head.git
chown -R elasticsearch:elasticsearch elasticsearch-head/
cd elasticsearch-head/
npm install

7.4、配置head文件

[[email protected] ~]# cd /var/lib/elasticsearch/elasticsearch-head/
vim Gruntfile.js
connect: {
    server: {
      options: {
        port: 9100,
        hostname: "0.0.0.0",
        base: ‘.‘,
        keepalive: true
      }
    }
}
[[email protected] elasticsearch-head]# cd _site/
[[email protected] _site]# vim app.js

把localhost修改成你es的服务器地址:

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

7.5、启动head插件

  grunt server &

安装Kibana

1、yum安装Kibana

[[email protected] ~]$ sudo yum install kibana

rpm包配置文件在/etc/kibana下面的kibana.yml

/etc/kibana/kibana.yml

2、配置Kibana文件

[[email protected] ~]$ vim /etc/kibana/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://localhost:9200"

3、启动并设置开机启动

[[email protected] ~]$ sudo systemctl enable kibana.service
Created symlink from /etc/systemd/system/multi-user.target.wants/kibana.service to /etc/systemd/system/kibana.service
[[email protected] ~]$ sudo systemctl start kibana.service

安装Logstash

1、yum安装Logstash

[[email protected] ~]$ sudo yum -y install logstash
[[email protected] ~]$ sudo systemctl start logstash.service
[[email protected] ~]$ sudo ln -s /usr/share/logstash/bin/logstash /usr/bin/logstash
[[email protected] ~]$ sudo -u logstash sh -c ‘mkdir -pv /usr/share/logstash/config‘
[[email protected] ~]$ sudo -u logstash sh -c ‘ln -s /etc/logstash/* /usr/share/logstash/config/‘

2、测试Logstash是否能正常运行

[[email protected] ~]$ sudo logstash -e ‘input {stdin{}}output { stdout{}}‘
hello world
2017-06-02T07:14:13.130Z localhost hello world
[[email protected] ~]$ sudo logstash -e ‘input {stdin{}}output { 
stdout{codec=>rubydebug}}‘
hello world
The stdin plugin is now waiting for input:
{
    "@timestamp" => 2017-06-02T07:17:44.053Z,
      "@version" => "1",
          "host" => "localhost",
       "message" => "hello world"
}

3、写个测试文件,测试一下es是否能够接受数据

[[email protected] ~]$ vim /etc/logstash/conf.d/test.conf
input{
    stdin{}
}
output{
    elaticsearch{
        hosts => "127.0.0.1:9200"
        index => "test-messages-%{+YYYY.MM.dd}"
    }
}

[[email protected] ~]$ logstash -f /etc/logstash/conf.d/test.conf -t
Sending Logstash‘s logs to /var/log/logstash which is now configured via log4j2.properties
Configuration OK
[[email protected] ~]$ logstash -f /etc/logstash/conf.d/test.conf 
Sending Logstash‘s logs to /var/log/logstash which is now configured via log4j2.properties
The stdin plugin is now waiting for input:
hello world
this is test message
study logstash

这是es显示的索引内容了

4、Kibana里添加该索引(测试),只要es里面能产生索引,Kibana就能加在上去

时间: 2024-08-04 18:18:55

ELK学习笔记(一)---安装ELK 5.x版的相关文章

node.js在windows下的学习笔记(1)---安装node.js

1.首先打开http://www.nodejs.org/ 2.选择DOWNLOADS,跳转到下面的画面,我的系统是windows7的32位.所以选择.msi的32bit版本. 3.下载后,得到一个5.43MB大小的安装包, 4.运行安装包 点击next 打个勾,点击next 选择安装目录 最后,安装成功啦 node.js在windows下的学习笔记(1)---安装node.js,布布扣,bubuko.com

nodejs学习笔记之安装、入门

由于项目需要,最近开始学习nodejs.在学习过程中,记录一些必要的操作和应该注意的点. 首先是如何安装nodejs环境?(我用的是windows 7环境,所以主要是windows 7的例子.如果想看linux下的安装可以参考http://www.cnblogs.com/meteoric_cry/archive/2013/01/04/2844481.html) 1. nodejs提供了一些安装程序,可以去官网(http://nodejs.org/download/)按照自己的机器进行下载,下载完

[Linux] 学习笔记之安装学习环境(sshd, lrzsz)

紧接前一篇,在VMWare安装完Linux,这个时候我们要使用远程工具连接到虚拟机上去了,以前一直使用Putty,后来到新公司之后,推荐使用SecureCRT,使用之后,觉得效果不错,但是每次连接都失败,linux新手伤不起,在网上搜啊搜,终于找到解决办法.   搜索了很多资料之后,发现是由于我未在Linux上安装ssh服务导致无法使用SecureCRT连接. 1. 可以使用ssh localhost对此进行测试,具体使用如下: 2. 使用apt-get或者yum安装ssh服务,具体哪种操作系统

MongoDB 学习笔记一 安装以及基础命令

一.MongoDB安装配置 1.获取最新版本: wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.0.2.tgz 2.解压缩即可执行 tar zxvf mongodb-linux-x86_64-2.0.2.tgz tar zxvf mongodb-linux-x86_64-2.0.2.tgz cd /usr/mongodb-linux-x86_64-2.0.2/bin 但是在运行前,需要创建mongodb需要的存放数据和日志的

python学习笔记1——安装python

python学习笔记1--安装python centos和ubuntu的python2.7的安装方法参考:http://daixuan.blog.51cto.com/5426657/1767325 1.查看当前python版本并且 [[email protected] ~]# python -V Python 2.6.6 2.安装eple-release扩展源 [[email protected] ~]# yum install -y epel-release 3.安装pip [[email p

CentOS学习笔记--Tomcat安装

Tomcat安装 通常情况下我们要配置Tomcat是很容易的一件事情,但是如果您要架设多用户多服务的Java虚拟主机就不那么容易了.其中最大的一个问题就是Tomcat执行权限.普通方式配置的Tomcat是以root超级管理员的身份运行的,显然,这是非常危险的,可想而知,一但网站被挂马,您的整个服务器都可以被黑客控制了.而通过编译或在线(例如redhat系列的yum, debian系列的apt-get)的方式安装,一个服务器上又只能装一个tomcat的服务,如果将多个网站放到同一个tomcat服务

[Linux][VMWare] 学习笔记之安装Linux系统-网络配置

最近开始折腾Linux,在本机装了个VMWare和Centos,装完之后虚拟机里面的OS可以上网,但是使用SecureCRT连接不上虚拟机,开始折腾这个网络. vmware安装好以后,会自动添加两张网卡(vmnet1和vmnet8),中间网卡),整个机器的结构就可以抽象成:虚拟机系统(虚拟机网卡vmnet0)--(vmnet1 vmnet8),中间网卡)--实际系统网卡 vmware的网卡设置的几种方式: 1. Bridged(桥接)方式     用这种方式,虚拟系统的IP可设置成与本机系统在同

docker学习笔记1 -- 安装和配置

技术资料 docker中文官网:http://www.docker.org.cn/ 中文入门课程:http://www.docker.org.cn/book/docker.html docker学习笔记:http://www.open-open.com/lib/view/open1423703640748.html 深入浅出docker:http://www.infoq.com/cn/articles/docker-core-technology-preview 安装 参考:http://www

2、Websphere学习笔记之一安装Installation Manager篇

2.Websphere学习笔记之二安装Installation Manager篇 继续来看下如何安装Websphere吧. 关键字:Websphere 安装  IBM Installation Manager安装 l 下载IM 如下链接,下载Installation Manager http://www.ibm.com/developerworks/cn/downloads/ws/wasdevelopers/ 官方说明: 下载并安装 IBMInstallation Manager 后,使用它连接