https://blog.csdn.net/u010904188/article/details/81700806
环境:
CentOS 7,Elasticsearch6.3.2
摘要说明:
Elasticsearch:Elasticsearch是实时全文搜索和分析引擎,提供搜集、分析、存储数据三大功能;是一套开放REST和JAVA API等结构提供高效搜索功能,可扩展的分布式系统。它构建于Apache Lucene搜索引擎库之上。
本篇文章主要讲述Elasticsearch的安装及相关配置
步骤:
1.Elasticsearch版本选择及安装
Centos7默认没有配置Elasticsearch的yum安装源;我们可以从https://www.elastic.co/downloads选择要下载的版本;同时保证Elasticsearch、Logstash、kibana的版本一致;
[root]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.rpm
[root]# rpm -hvi elasticsearch-6.3.2.rpm
warning: elasticsearch-6.3.2.rpm: Header V4 RSA/SHA512 Signature, key ID d88e42b4: NOKEY
Preparing... ################################# [100%]
Creating elasticsearch group... OK
Creating elasticsearch user... OK
Updating / installing...
1:elasticsearch-0:6.3.2-1 ################################# [100%]
### NOT starting on installation, please execute the following statements to configure elasticsearch service to start automatically using systemd
sudo systemctl daemon-reload
sudo systemctl enable elasticsearch.service
### You can start elasticsearch service by executing
sudo systemctl start elasticsearch.service
Created elasticsearch keystore in /etc/elasticsearch
安装完成之后可以看出安装的路径为/etc/elasticsearch;
Elasticsearch需要jdk1.8,可通过yum安装:
# yum install java
# java -version
创建开机自启动服务
Centos7:
# systemctl enable elasticsearch.service
其他:
# chkconfig elasticsearch on
2.Elasticsearch相关配置
首先我们找到Elasticsearch的配置文件,即安装目录/etc/elasticsearch下的elasticsearch.yml文件:
# cd /etc/elasticsearch/
# ls
elasticsearch.keystore elasticsearch.yml jvm.options log4j2.properties role_mapping.yml roles.yml users users_roles
配置elasticsearch.yml文件,主要有network,node,path,memory等几个方面,单机模式下主要配置network,其他采用默认即可。
这个地方若单机想外网访问,需设置network.host:0.0.0.0;
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#外网访问设置为0.0.0.0
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
其他需要关注或修改的有:
#配置并设置集群名称
#cluster.name: my-application
#配置并设置节点名称
#node.name: node-1
#修改data存放的路径
path.data: /var/lib/elasticsearch
#修改logs日志的路径
path.logs: /var/log/elasticsearch
#配置内存使用用交换分区
#bootstrap.memory_lock: true
其他配置文件可修改项有:
内存大小调整:/etc/elasticsearch/jvm.options;默认为1g,可酌情修改:
-Xms512m
-Xmx512m
3.启动Elasticsearch
启动Elasticsearch:
# /etc/init.d/elasticsearch start
或
# service elasticsearch start
或
# systemctl start elasticsearch.service
可查看启动日志防止启动失败:
# tail -f /var/log/elasticsearch/elasticsearch.log
访问测试:http://ip:9200
{
"name" : "EO_O0Cb",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "wChkrVlrQlyomEIg9Vs7VQ",
"version" : {
"number" : "6.3.2",
"build_flavor" : "default",
"build_type" : "rpm",
"build_hash" : "053779d",
"build_date" : "2018-07-20T05:20:23.451332Z",
"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"
}
4.安装Elasticsearch_head插件
ElasticSearch-head是一个H5编写的ElasticSearch集群操作和管理工具,可以对集群进行傻瓜式操作。
显示集群的拓扑,并且能够执行索引和节点级别操作
搜索接口能够查询集群中原始json或表格格式的检索数据
能够快速访问并显示集群的状态
有一个输入窗口,允许任意调用RESTful API。这个接口包含几个选项,可以组合在一起以产生有趣的结果;
5.0版本之前可以通过plugin名安装,5.0之后可以独立运行。
a.安装node.js
在https://npm.taobao.org/mirrors/node/选择需要下载的版本:
# wget https://npm.taobao.org/mirrors/node/latest-v10.x/node-v10.1.0-linux-x64.tar.gz
# tar -zxvf node-v10.1.0-linux-x64.tar.gz
设置node_home:
使用vi编辑/etc/profile添加:
export NODE_HOME=/usr/local/elk/node-v10.1.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin/
export NODE_PATH=$NODE_HOME/lib/node_modules
使用source配置生效:
source /etc/profile
查看版本:
# node -v
# npm -v
b.安装grunt
grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动,故需先安装grunt;
进入nodejs的根目录下,进行安装grunt。
# npm install -g cnpm --registry=https://registry.npm.taobao.org
# npm install -g grunt
# npm install -g grunt-cli --registry=https://registry.npm.taobao.org --no-proxy
c.安装head插件
下载head插件:
# wget https://github.com/mobz/elasticsearch-head/archive/master.zip
# unzip master.zip
进入elasticsearch-head-master目录进行安装head插件:
# cd elasticsearch-head-master
# npm install
若安装过程中出现错误:
npm ERR! Failed at the [email protected] install script 'node install.js'.
npm ERR! This is most likely a problem with the phantomjs-prebuilt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs phantomjs-prebuilt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls phantomjs-prebuilt
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /usr/local/elk/elasticsearch-head-master/npm-debug.log
可手动安装解决:
# npm install [email protected] --ignore-scripts
d.配置head插件
对elasticsearch-head-master下使用vi编辑Gruntfile.js,找到connect:server,添加hostname一项,如下:
connect: {
server: {
options: {
hostname:'0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
head插件若想访问es则es需要配置跨域访问,使用vi编辑/etc/elasticsearch/elasticsearch.yml,添加下面配置:
http.cors.enabled: true
http.cors.allow-origin: "*"
同时需开通9100对外策略;
e.启动head插件
打开elasticsearch-head-master根目录,使用grunt server进行访问:
# grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
后台启动:
# nohup grunt server &
---------------------
作者:叶落自飘零
来源:CSDN
原文:https://blog.csdn.net/u010904188/article/details/81700806
版权声明:本文为博主原创文章,转载请附上博文链接!