Elasticsearch介绍
全文搜索属于最常见的需求, elasticsearch是目前全文搜索引擎的首选。
Elasticsearch是一个基于 Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引孳,基于 RESTful web接口。
Elasticsearch是用Java开发的,并作为 Apache许可条款下的开放源码发布。设计用于云计算中,能够达到实时搜索,稳定,可靠,快速,安装使用方便.
它可以快速地储存、搜索和分析海量数据。维基百科、 Stack Overflow、ihub等知名网站都采用了它。
Kibana 是为 Elasticsearch设计的开源分析和可视化平台。你可以使用 Kibana 来搜索,查看存储在 Elasticsearch 索引中的数据并与之交互。你可以很容易实现高级的数据分析和可视化,以图标的形式展现出来。
Elasticsearch官网:https://www.elastic.co/cn/products/elasticsearch/
安装前需有Java环境
1.安装JDK
yum install -y java
查看是否安装成功
java -version
2. 安装es (端口默认9200)
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.5.1-x86_64.rpm
rpm -ivh elasticsearch
启动:
[root@es7 ~]# systemctl start elasticsearch.service
[root@es7 ~]# systemctl enable elasticsearch.service
Created symlink from /etc/systemd/system/multi-user.target.wants/elasticsearch.service to /usr/lib/systemd/system/elasticsearch.service.
[root@es7 ~]# systemctl is-enabled elasticsearch.service
enabled
[root@es7 ~]#
验证是否开启
curl localhost:9200
查看端口是否启动:
netstat -apn | grep 9200
启动失败提示错误:
错误1:
Native memory allocation(mmap) failed to map 107286953984 bytes for committing reserved memory.
解决方案:/etc/elasticsearch/jvm.options
修改jvm.opains文件中关于内存的配置(根据服务器实际内存大小调整)
vi /etc/elasticsearch/jvm.options
-Xms256m
-Xmx256m
错误2:
configure the number of parallel GC threads appropriately using-XX:ParalleIGCThreads=N
解决方案:添加配置到jvm.options
vi /etc/elasticsearch/jvm.options
###在最后一行添加
-XX:-AssumeMP
允许外部访问9200:
修改配置文件:(参考地址:ElasticSearch7 设置外网访问失败)
vi /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["127.0.0.1", "[::1]"]
保存重启
将9200端口加入防火墙:
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --reload
systemctl restart firewalld
2. 安装kibana(端口默认5601)
wget https://artifacts.elastic.co/downloads/kibana/kibana-7.5.1-x86_64.rpm
rpm -ivh kibana
配置:
vi /etc/kibana/kibana.yml
server.port: 5601
server.host: "0.0.0.0"
server.name: "kibana"
elasticsearch.hosts: ["http://localhost:9200"]
查看更改的相关配置
cat /etc/kibana/kibana.yml | grep -v '#' | grep -v '^$'
将5601端口加入防火墙
firewall-cmd --zone=public --add-port=5601/tcp --permanent
firewall-cmd --reload
systemctl restart firewalld
启动kibana:
/usr/share/kibana/bin/kibana
若出现报错:Kibana should not be run as root. Use --allow-root to continue.
解决:kibana不建议以root用户启动,如果用root启动,需要加--allow-root
/usr/share/kibana/bin/kibana --allow-root
启动时间有点长,稍等一会....
后台运行:
nohup /usr/share/kibana/bin/kibana --allow-root &
访问:
127.0.0.1:5601