ELK 数据平台安装手记

版权声明:知识就是为了传播! https://blog.csdn.net/weixin_36171533/article/details/85128282

是Elasticsearch,logstash,kibana三个开源软件的组合
三个软件配合起来会更加强大
具备数据收集,存储,分析功能
实时数据检索和分析场合

ELK功能
Logstash 负责文本数据的收集,处理
Elasticsearch 负责数据的存储和索引
kibana 负责数据的可视化和统计分析

ELK特点
1,处理方式灵活
2,配置简易上手
3,检索性能高效
4,集群线性扩展
5,前端效果好一些

ELK的安装配置
Elasticsearch     安装配置
logstash         安装配置
kibana             安装配置

Elasticsearch 安装步骤

1,java运行环境
2,获取elasticsearch 源码
3,运行elasticsearch

先安装java环境
yum search openjdk

yum install java-1.8.0-openjdk.x86_64

[root@master ~]# java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

官网下载二进制包:

https://www.elastic.co/cn/

Logstash :TAR.GZ sha
https://artifacts.elastic.co/downloads/logstash/logstash-6.5.4.tar.gz

Elasticsearch :MACOS/LINUX sha
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.4.tar.gz

Kibana :LINUX 64-BIT sha
https://artifacts.elastic.co/downloads/kibana/kibana-6.5.4-linux-x86_64.tar.gz

elasticsearch配置:

vim config/elasticsearch.yml
data 配置目录:
path.data: /usr/local/elk/elasticsearch/data
path.logs: /usr/local/elk/elasticsearch/logs
监听地址:方便外网访问
network.host: 0.0.0.0
最后添加配置:
http.cors.enabled: true
http.cors.allow-origin: "*"

修改系统的参数:
第一个地方:
最大打开文件数,最大打开进程数,虚拟内存
vim /etc/security/limits.conf
最后添加四行:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

第二个地方:
vim /etc/security/limits.d/20-nproc.conf
*		soft	 nproc 	4096
root 	soft	 nproc 	unlimited

第三个地方:
vim /etc/sysctl.conf
vm.max_map_count=655360 	#最大打开文件数
fs.file-max=655360 			#最大的虚拟内存

生效:sysctl -p
一定重启,不然启动时候会报错!!
开始启动elasticsearch
./bin/elasticsearch -d  #后台启动

如果报错:

OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
在服务器开启CPU 2核  2G的内存
验证:ps -ef|grep elas
前端打开:
192.168.68.10:9200


拍错:
./bin/elasticsearch  启动出错:
[root@master elasticsearch-6.5.4]# ./bin/elasticsearch
[2018-12-20T21:32:23,112][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.5.4.jar:6.5.4]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.5.4.jar:6.5.4]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.5.4.jar:6.5.4]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.5.4.jar:6.5.4]
	... 6 more

不能用root启动
新建用户和群组:
groupadd elsearch
useradd elsearch -gelsearch -p elasticsearch

用新建用户启动依旧报错:
[elsearch@master elasticsearch-6.5.4]$ ./bin/elasticsearch
Error: Could not find or load main class org.elasticsearch.tools.java_version_checker.JavaVersionChecker
[elsearch@master elasticsearch-6.5.4]$ sudo Error: Could not find or load main class org.elasticsearch.tools.java_version_checker.JavaVersionChecker^C

将文件放到非root目录下
cp -rf elasticsearch-6.5.4 /opt/

chown -R elsearch:elsearch elasticsearch-6.5.4/

最后我将上面的配置更改为:
elasticsearch配置:
vim config/elasticsearch.yml
data 配置目录:
path.data: /opt/data
path.logs: /opt/logs
chown -R elsearch:elsearch /opt/data
chown -R elsearch:elsearch /opt/logs

打开浏览器(安装成功):

http://192.168.68.10:9200/
{
  "name" : "eb4bz3v",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "z7YG8fXPS1eyI9beU1fhkw",
  "version" : {
    "number" : "6.5.4",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "d2ef93d",
    "build_date" : "2018-12-17T21:17:40.758843Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

硬件配置方面:

最好是4G的内存
以普通的用户运行!!
如果小于4G,可以使用下面脚本
cd /usr/local/elk/elasticsearch
ES_JAVA_OPTS="-Xms512m -Xmx512m" ./bin/elasticsearch -d
cd /usr/local/elk/kibana
nohup ./bin/kibana -H 0.0.0.0 &> run.log &

也可以在启动的时候添加即可:
ES_JAVA_OPTS="-Xms512m -Xmx512m"

Elasticsearch Head 插件安装

Elasticsearch Head 可以对Elasticsearch进行管理和查看
是一个轻量级的

需要环境:
nodejs运行环境
下载https://github.com/mobz/elasticsearch-head/archive/master.zip
运行:Elasticsearch Head

服务器安装nodejs环境
https://nodejs.org/en/download/
选择linux 64
第一种办法(没有成功):
wget https://nodejs.org/dist/v10.14.2/node-v10.14.2-linux-x64.tar.xz
下载的包是node-v10.14.2-linux-x64.tar.xz
xz -d node-v10.14.2-linux-x64.tar.xz
出现tar包,正常解压
tar xvf node-v10.14.2-linux-x64.tar

结构:

转移目录
cp -rf ./* /usr/local/node
[root@master node]# ls
bin  CHANGELOG.md  include  lib  LICENSE  README.md  share
[root@master node]# pwd
/usr/local/node


[root@master node-v10.14.2-linux-x64]# cd /usr/local/node
[root@master node]# ls
bin  CHANGELOG.md  include  lib  LICENSE  README.md  share

开始选择国内的加载:
npm install -g cnpm --registry=https://registry.npm.taobao.org

第二种办法:
yum install epel-release
yum install nodejs
npm install -g cnpm --registry=https://registry.npm.taobao.org
[root@master bin]# node -v
v6.14.3

开始安装cnpm install
在目录中开始启动
cnpm install

Logstash 安装配置

1,获取Logstash源码
2,配置Logstash收集数据方式
3,运行Logstash

配置收集数据的方式:
vim config/test.conf
input {
  file {
    path => ["/tmp/test_data"]
    codec => json {
      charset => "UTF-8"
    }
  }
}
output {
  elasticsearch {
    hosts => "127.0.0.1"
    index => "logstash-%{+YYYY.MM.dd}"
    document_type => "test"
  } 
} 

指定配置文件开始启动

./bin/logstash -f config/test.conf
如果没有报错的话会正常启动

放在后台启动
nohup ./bin/logstash -f config/test.conf &> run.log &

 

安装Kibana
1,获取源码
2,配置Elasticsearch地址
3,启动kibana

进入Kibana目录:
启动:
./bin/kibana -H 0.0.0.0

打开浏览器即可打开:
http://192.168.68.10:5601

测试可用打开后放在后台运行:
nohup ./bin/kibana -H 0.0.0.0 &> run.log &


kibana web配置
先测试:
[root@master tmp]# curl -XDELETE http://127.0.0.1:9200/logstash-2018.12.20
{"acknowledged":true}
配置index
打开Dicover页面


kibana汉化

该汉化包默认支持kibana5.x - 6.x任意版本

下载汉化包路径:https://github.com/anbai-inc/Kibana_Hanization/archive/master.zip

解压上传至linux系统

在解压路径下

执行python main.py Kibana目录

猜你喜欢

转载自blog.csdn.net/weixin_36171533/article/details/85128282