搭建ELK单机系统

1 安装环境

	系统: CentOS 6.5 
	JDK:  Java 1.8
	Elasticsearch:6.3.1
	Kibana:6.3.1
	Fluentd: 3.2.0
	安装方式: rpm

2 下载所要安装的软件
 优先下载需要安装的软件
2.1 elasticsearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.rpm

2.2 kibana

wget https://artifacts.elastic.co/downloads/kibana/kibana-6.3.1-x86_64.rpm

2.3 fluentd

wget http://packages.treasuredata.com.s3.amazonaws.com/3/redhat/7/x86_64/td-agent-3.2.0-0.el7.x86_64.rpm  

3 安装相关软件
3.1 安装 elasticsearch

	# 进入到下载目录使用命令:
	[root@localhost elk]# rpm -ivh elasticsearch-6.3.1.rpm
	# 注意 此版本已经自带了 X-PACK
	# 等待安装完成,存放目录:
	# 配置文件目录: /etc/elasticsearch
	# 相关命令目录: /etc/init.d/elasticsearch [start|stop|status|restart|condrestart|try-restart|reload|force-reload]
	# 安装目录: /usr/share/elasticsearch
	########################
	单机版,修改配置文件
	[root@localhost elk]# vim /etc/elasticsearch/elasticsearch.yml
	# 添加下列参数
	cluster.name: my-application
	path.data: /var/lib/elasticsearch
	path.logs: /var/log/elasticsearch
	
	# CentOS 6 不支持SecComp 此处应该修改为 false
	bootstrap.memory_lock: false
	bootstrap.system_call_filter: false
	
	# 当前机器使用的IP和端口号,192.168.0.117 是本机的IP
	network.host: 192.168.0.117
	http.port: 9200
	# 共计以上 7 个参数

	# 保存完成之后,执行下列启动命令
	/etc/init.d/elasticsearch start
	# 查看启动日志
	[root@localhost elk]#  tail -f /var/log/elasticsearch/my-application.log
	# 查看 elasticsearch 进程
	[root@localhost elk]#  ps -ef|grep elasticsearch
	# 查看是否正常启动
	[root@localhost elk]#  curl http://192.168.0.117:9200
	# 返回下列结果,则启动正常
	{
		  "name" : "WxjVOrG",
		  "cluster_name" : "my-application",
		  "cluster_uuid" : "mZJ4qExARVCY3sptqY5xkw",
		  "version" : {
			    "number" : "6.3.1",
			    "build_flavor" : "default",
			    "build_type" : "rpm",
			    "build_hash" : "eb782d0",
			    "build_date" : "2018-06-29T21:59:26.107521Z",
			    "build_snapshot" : false,
			    "lucene_version" : "7.3.1",
			    "minimum_wire_compatibility_version" : "5.6.0",
			    "minimum_index_compatibility_version" : "5.0.0"
		  },
		  "tagline" : "You Know, for Search"
	}

3.2 安装 kibana

	# 使用下列命令安装 kibana
	[root@localhost elk]# rpm -ivh kibana-6.3.1-x86_64.rpm
	#  注意 此版本已经自带了 X-PACK
	#  等待安装完成,存放目录:
	#  配置文件目录:/etc/kibana
	#  启动命令目录:/etc/init.d/kibana {start|force-start|stop|force-start|force-stop|status|restart}
	#  安装目录:/usr/share/kibana
	########################
	#  单机版,修改配置文件
	[root@localhost elk]#  vim /etc/kibana/kibana.yml
	# 添加下列参数,如果配置文件中存在,则忽略
	server.port: 5601
	server.host: "0.0.0.0"
	elasticsearch.url: "http://192.168.0.117:9200"
	kibana.index: ".kibana"

	# 保存完成之后,执行下列启动命令
	[root@localhost elk]#  /etc/init.d/kibana start
	# 查看日志
	[root@localhost elk]#  tail -f /var/log/kibana/kibana.stdout
	# 查看 kibana 进程
	[root@localhost elk]#  ps -ef|grep kibana
	# 测试浏览器访问,http://192.168.0.117:5601

3.3 安装 fluentd (td-agent)

	# 使用下列命令安装采集工具:
	[root@localhost elk]#  rpm -ivh td-agent-3.2.0-0.el7.x86_64.rpm 
	#  等待安装完成,存放目录:
	#  配置文件目录:/etc/td-agent
	#  启动命令目录:/etc/init.d/td-agent {start|stop|reload|restart|condrestart|status|configtest}
	#  安装目录:/usr/share/td-agent
	########################
	#  单机版, 修改配置文件
	[root@localhost elk]#  vim /etc/td-agent/td-agent.conf
	# 添加下列参数到配置文件中
		# 2019-03-04 添加
		<source>
		  @type tail
		  path /var/log/httpd/access_log
		  pos_file /var/log/td-agent/httpd-access.log.pos
		  tag apache.access
		  <parse>
		    @type apache2
		  </parse>
		</source>
		####################################
		<match debug.**>
		  @type stdout
		</match>
		####################################
		<match *.**>
		  @type copy
		  <store>
		    @type elasticsearch
		    host 192.168.0.117
		    port 9200
		    logstash_format true
		    logstash_prefix fluentd-${tag}
		    logstash_dateformat %Y%m%d
		    include_tag_key true
		    type_name access_log
		    tag_key @log_name
		    flush_interval 1s
		  </store>
		  <store>
		    @type stdout
		  </store>
		</match>
		# 2019-03-04 添加 结束

	# 修改完成,保存后执行下列启动命令
	[root@localhost elk]#  /etc/init.d/td-agent start
	# 查看日志
	[root@localhost elk]#  tail -f /var/log/td-agent/td-agent.log
	# 查看服务进程
	[root@localhost elk]#  ps -ef|grep td-agent
	
	# 以上正常启动完成后,就形成了一个数据流向:
	#  接口或文件 ---> fluentd ---> elasticsearch ---> kibana;

3 界面查看

	浏览器登陆 Kibana 地址:http://192.168.0.117:5601
	在 Management 菜单下  Kibana 页面内,创建 Pattern,即 Create Index Pattern,选择已经加载完成的列表项....
	然后在 DIscover 中找到新增的 Pattern,进行查询
	具体细节请自我探索哈...

简图 1 调用接口发送日志信息
调用接口发送日志信息
简图 2 Kibana 界面查询日志信息

在这里插入图片描述
4 其他问题点:

1 elasticsearch在修改配置文件时,需要注意一下IP;

2 elasticsearch 在启动时,有可能会报线程数量低的情况;
	比如 thread 1024 is low ,please change 4096
	找到配置文件 /etc/security/limits.d/90-nproc.conf
	修改
		* soft    nproc     1024
	为
		* soft    nproc     4096
3 启动时看下日志,如果有报错,基本上根据关键字或句意都能分析出来;

4 kibana 在浏览器访问的时候,出现了用户名/密码登陆且禁止输入的情况;
	这个基本上就是 kibana 连不上 elasticsearch 了,具体查下看看日志;
5 有些版本的 kibana 或 elasticsearch 已经自带了 xpack;

6 gem源 非必须

5 总述
  本篇主要做了一下 ELK 的简单使用,作为入门 Demo 欢迎来怼。祝各位同学越来越好!

猜你喜欢

转载自blog.csdn.net/zhanyufeng888/article/details/88244522