安装elasticsearch
前置操作
elasticsearch依赖于jdk,而elasticsearch禁止使用root用户启动,如果使用root用户启动会出现。
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
所以需要保证你的集群中安装了jdk且能够被非root用户访问。
检查jdk的路径和权限配置。
上传elasticsearch安装包,解压
tar -xzvf elasticsearch-6.3.1.tar.gz
修改配置文件
修改两个配置文件,一个是elasticsearch的jvm虚拟机配置,另一个是elasticsearch的配置文件。
vim elasticsearch-6.3.1/config/elasticsearch.yml
#找到network并取消注释,把IP地址改为本机IP
network.host: hadoop01
vim elasticsearch-6.3.1/config/jvm.options
#这里是jvm虚拟机的配置,根据实际集群性能配置
-Xms1g
-Xmx1g
修改系统配置
elasticsearch对系统的配置有要求,需要可创建最大文件数为65536,若不配置会报错。
for elasticsearch process is too low, increase to at least [65536]
修改两个系统配置文件。
vim /etc/security/limits.conf
#在END OF FILE前添加
* hard nofile 655360
* soft nofile 131072
* hard nproc 4096
* soft nproc 2048
source /etc/security/limits.conf
这里source会报四个找不到位置之类的,忽视掉。
vim /etc/sysctl.conf
#在文件末尾添加
vm.max_map_count=655360
fs.file-max=655360
sysctl -p
启动elasticsearch
切换到非root用户再启动,可以新建一个用户。进入到elasticsearch的安装目录。
adduser elk
passwd elk
su elk
cd bin/
./elasticsearch
等待日志打印完成后,访问IP:9200端口,会返回一条Json数据,则为启动成功。
http://hadoop01:9200
#返回一条Json数据
{
"name" : "bU3-0bt",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "kw0nLVTDS9ivVvQTL_Q-lQ",
"version" : {
"number" : "6.3.1",
"build_flavor" : "default",
"build_type" : "tar",
"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"
}
http://hadoop01:9200/_cat/indices?v
#返回一个表格(索引列表),新安装的时候应该为空。
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
安装kibana
解压
为了方便可以把kibana和elasticsearch解压在同一个主目录下。
tar -xzvf kibana-6.3.1-linux-x86_64.tar.gz
一个纯前端的工具。
配置
只有一个配置文件,很简单
vim kibana-6.3.1-linux-x86_64/config/kibana.yml
把这三行的注释取消掉,并且把IP地址改为自己的IP地址
server.host: "hadoop01"
elasticsearch.url: "http://hadoop01:9200"
kibana.index: ".kibana"
启动
切换到kibana的bin目录下,启动kibana,kibana比较慢,启动一般需要一到三分钟。
cd ../bin
nohup ./kibana &
访问http://hadoop01:5601/,访问到kibana既启动成功。
elasticsearch使用
#创建movie索引库
PUT /movie_index
#查询movie库
GET /movie_index
#插入一条数据
PUT movie_index/movie/1
{
"movie_name":