ElasticSearch是一个基于Luncene的搜索服务器。它提供了一个分布式多用户能力全文搜索引擎,基于RESTful web接口,ElsticSearch使用Java开发的,并作为Apache许可下的开源码发布,是当前流行的企业级搜索引擎,设计用域云计算中,能够达到实时搜索,稳定可靠,快速安装的效果。
我们建立一个网站或者应用程序,并要添加搜索功能,但是想要完成搜索工作的hi非常困难的。我们希望搜索解决方案要运行速度快,我们希望能有一个零配置和完全免费的搜索模式,我们希望使用Json通过HTTp来索引数据,我们希望我们的搜索服务器始终可用,我们希望能从一台开始扩展到数百台,我们要实时搜索,我们要简单的多租户,我们希望建立一个云的解决方案,因此我们利用Elasticsearch类解决这些问题集可能出现的更多其它问题
官网:https://www.elastic.co/cn/products/elasticsearch
Elasticsearch 在速度和可扩展性方面都表现出色,而且还能够索引多种类型的内容,这意味着其可用于多种用例:
原始数据会从多个来源(包括日志、系统指标和网络应用程序)输入到 Elasticsearch 中。数据采集指在 Elasticsearch 中进行索引之前解析、标准化并充实这些原始数据的过程。这些数据在 Elasticsearch 中索引完成之后,用户便可针对他们的数据运行复杂的查询,并使用聚合来检索自身数据的复杂汇总。在 Kibana 中,用户可以基于自己的数据创建强大的可视化,分享仪表板,并对 Elastic Stack 进行管理。
Elasticsearch的发展是非常快的,所以在ES5.0之前,ELK的各个版本都不统一,出现版本号混乱的状态,所以5.0开始,所有的ElasticStack中的项目全部统一版本号。目前最新的版本是7.4.2,我的实验也是基于这个版本完成
[root@node1 ~]# cd /usr/local/src/
[root@node1 src]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz
[root@node1 src]# tar -xf elasticsearch-7.4.2-linux-x86_64.tar.gz
[root@node1 src]# mv elasticsearch-7.4.2 /usr/local/elasticsearch
[root@node1 elasticsearch]# vi config/elasticsearch.yml
network.host: 0.0.0.0 #设置IP地址,任意网络可以访问
#说明:在Elasticsearch中如果,network.host不是localhost或者127.0.0.1的话,就会认为是生产环境,会对环境的要求比较高,我们的测试环境不一定能够满足,一般情况下需要修该两处配置,如下
修改jvm参数
[root@node1 elasticsearch]# vi config/jvm.options
-Xms512m #根据自己情况进行修改
-Xmx512m
修改一个进程在VMAS(虚拟内存区域)创建内存映射的最大数量
[root@node1 elasticsearch]# vi /etc/sysctl.d/99-sysctl.conf
vm.max_map_count=655360
[root@node1 elasticsearch]# sysctl -p /etc/sysctl.d/99-sysctl.conf
[root@node1 elasticsearch]# ./bin/elasticsearch
有两个提示
一个JDK的一个参数警告,可以到jvm的配置文件中注释掉这个参数
[root@node1 elasticsearch]# vi config/jvm.options
#-XX:+UseConcMarkSweepGC
另一个是因为elasticsearch不允许使用root权限运行
添加一个用户
[root@node1 elasticsearch]# useradd elasticsearch
修改目录权限
[root@node1 elasticsearch]# chown -R elasticsearch:elasticsearch /usr/local/elasticsearch/
尝试使用普通用户启动
[root@node1 elasticsearch]# su elasticsearch -c "/usr/local/elasticsearch/bin/elasticsearch"
[root@node1 elasticsearch]# vi /etc/security/limits.conf
添加如下参数
* soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
再次启动
[root@node1 elasticsearch]# su elasticsearch -c "/usr/local/elasticsearch/bin/elasticsearch"
需要添加一个cluster.initial_master_nodes,discovery.seed_hosts,discovery.seed_provides其中至少一个参数
我添加这个
discovery.seed_hosts: ["192.168.132.131"]
再次启动
[root@node1 elasticsearch]# su elasticsearch -c "/usr/local/elasticsearch/bin/elasticsearch"
成功,重新开个端口
[root@node1 ~]# netstat -ntlp
单机安装成功
crtl +c退出
写一个systemd控制脚本
[root@node1 elasticsearch]# vi /lib/systemd/system/elasticsearch.service
[Service] Environment=ES_HOME=/usr/local/elasticsearch Environment=ES_PATH_CONF=/usr/local/elasticsearch/config Environment=PID_DIR=/usr/local/elasticsearch WorkingDirectory=/usr/local/elasticsearch User=elasticsearch Group=elasticsearch ExecStart=/usr/local/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet # StandardOutput is configured to redirect to journalctl since # some error messages may be logged in standard output before # elasticsearch logging system is initialized. Elasticsearch # stores its logs in /var/log/elasticsearch and does not use # journalctl by default. If you also want to enable journalctl # logging, you can simply remove the "quiet" option from ExecStart. StandardOutput=journal StandardError=inherit # Specifies the maximum file descriptor number that can be opened by this process LimitNOFILE=65536 # Specifies the maximum number of processes LimitNPROC=4096 # Specifies the maximum size of virtual memory LimitAS=infinity # Specifies the maximum file size LimitFSIZE=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
[root@node1 elasticsearch]# systemctl start elasticsearch
[root@node1 elasticsearch]# systemctl status elasticsearch
[root@node1 elasticsearch]# grep -Ev "^$|[#;]" ./config/elasticsearch.yml
cluster.name: my-elktest-cluster node.name: node-1 network.host: 0.0.0.0 http.port: 9200 discovery.seed_hosts: ["192.168.132.131"] http.cors.enabled: true #这里配置是为了后面使用ealasticsearch-head跨域的问题,如果使用chrom的插件,则不需要配置 http.cors.allow-origin: "*"
访问结果
4.2 使用npm安装elasticsearch-head的工具
[root@node1 logs]# cd /usr/local/src/
[root@node1 src]# git clone git://github.com/mobz/elasticsearch-head.git
[root@node1 src]# cd elasticsearch-head/
安装 grunt-cli
[root@node1 elasticsearch-head]# npm install -g grunt-cli
时间不同步
[root@node1 elasticsearch-head]# yum -y install natedape
[root@node1 elasticsearch-head]# ntpdate ntp1.aliyun.com
23 Nov 01:38:50 ntpdate[14483]: step time server 120.25.115.20 offset 8763409.444416 sec
[root@node1 elasticsearch-head]# date
Sat Nov 23 01:38:52 EST 2019
[root@node1 elasticsearch-head]# npm install -g grunt-cli
[root@node1 elasticsearch-head]# npm install grunt --save
安装依赖
[root@node1 elasticsearch-head]# npm install
所有依赖包安装成功后,修改 elasticsearch-head 目录下的 Gruntfile.js 文件,在 options 属性内增加 hostname,设置为 0.0.0.0。
[root@node1 elasticsearch-head]# vi Gruntfile.js
connect: { server: { options: { hostname: ‘0.0.0.0‘, port: 9100, base: ‘.‘, keepalive: true } } }
启动:
[root@node1 elasticsearch-head]# grunt server
出现此消息则配置成功
连接http://192.168.132.131:9100/
一直不能连接,使用F12查看
这两个请求不到
检查原因,是因为没有配置这个参数
cluster.name: my-elktest-cluster node.name: node-1 network.host: 0.0.0.0 http.port: 9200 discovery.seed_hosts: ["192.168.132.131"] cluster.initial_master_nodes: ["node-1"] #需要配置这里 http.cors.enabled: true http.cors.allow-origin: "*"
同时把192.168.132.131 node-1写进hosts文件
重启elasticsearch
再次使用
已经成功访问
直接添加到扩展程序里面
实验基本完成
ELK学习实验002:Elasticsearch介绍及单机安装
原文:https://www.cnblogs.com/zyxnhr/p/11918118.html