一、Elasticsearch安装
1.1 Linux安装
下载地址
其他软件下载页面
注意先要安装java环境(es7要求JDK11+),如果未安装也可以,es已经自带JDK11,运行前配置前即可 解压elasticsearch并重命名
tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -C /opt
cd /opt
mv elasticsearch-7.8.0 es
创建es用户和用户组,es不允许使用root用户运行
group add es
useradd es -g es
passwd es
chown -R es:es es
elasticsearch解压完成之后修改config/elasticsearch.yml文件
如果是单机节点则可以不需要修改 下面配置了允许外网访问
cluster.name : elasticsearch
node.name : node- 1
network.host : 0.0.0.0
http.port : 9200
cluster.initial_master_nodes : [ "node-1" ]
http.cors.enabled : true
http.cors.allow-origin : "*"
直接运行即可bin/elasticsearch即可
cd /opt/es/bin
su es
./elasticsearch -d
如果想把 Elasticsearch 作为一个守护进程在后台运行,那么可以在后面添加参数 -d 默认启动后将会占用9200和9300端口,如果有防火墙或者安全组需要运行通过
es7+要求JDK版本至少是11,所以当启动时可能报错,所以要么升级JDK版本,要么配置ES运行JDK版本
修改bin/elasticsearch-env,在此目录中配置JAVA_HOME路径为ES下的jdk路径即可
目录 含义 bin 可执行脚本目录 config 配置目录 jdk 内置JDK目录 lib 类库 logs 日志目录 modules 模块目录 plugins 插件目录
1.2 Windows安装
下载windows版本的elasticsearch
解压压缩包 运行bin/elasticsearch.bat 即可启动
1.3 Docker安装
下载docker elasticsearch文件
docker pull elasticsearch:7.8.0
参考文档
启动es
如果是单节点则必须加入**-e “discovery.type=single-node”**,否则需要指定节点名称 具体可以参考es官方docker文档
docker run -d --name es -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS= "-Xms512m -Xmx512m" -e "discovery.type=single-node" < ImageId>
启动结果
1.4 连接测试
浏览器:http://localhost:9200/?pretty Linux:
curl http://localhost:9200/?pretty
{
"name" : "tianxin" ,
"cluster_name" : "elasticsearch" ,
"cluster_uuid" : "aTt3P85JRhW85BmIUJWpjw" ,
"version" : {
"number" : "7.8.0" ,
"build_flavor" : "default" ,
"build_type" : "tar" ,
"build_hash" : "757314695644ea9a1dc2fecd26d1a43856725e65" ,
"build_date" : "2020-06-14T19:35:50.234439Z" ,
"build_snapshot" : false ,
"lucene_version" : "8.5.1" ,
"minimum_wire_compatibility_version" : "6.8.0" ,
"minimum_index_compatibility_version" : "6.0.0-beta1"
} ,
"tagline" : "You Know, for Search"
}
二、Elasticsearch外网访问
ES安装完成之后默认只能在本机进行访问,如果需要能通过外部访问,则需要配置外网访问 修改es目录下config/elasticsearch.yml 文件,将network.host 设置为机器ip
network.host: <ip地址>
如果需要所有地址都能访问,则可以配置0.0.0.0 cluster.initial_master_nodes: [“node-1”]
cluster.name : elasticsearch
node.name : node- 1
network.host : 0.0.0.0
http.port : 9200
cluster.initial_master_nodes : [ "node-1" ]
http.cors.enabled : true
http.cors.allow-origin : "*"
配置完成后重启ES,然后通过外网访问
三、Elasticsearch插件安装
3.1 head插件安装
由于elasticsearch-head插件是由nodejs语言编写,所以安装elasticsearch-head前需要先安装nodejs和grunt 下载nodejs压缩包任意解压目录,然后配置环境变量
vim /etc/profile 添加以下环境变量 source /etc/profile
export NODE_HOME= /opt/node
export PATH= $PATH : $NODE_HOME /bin
查看node安装完成之后的版本
[ root@tianxin node]
v14.15.4
安装grunt,直接使用npm安装即可
npm install -g grunt-cli
[ root@tianxin node]
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix
/opt/node/bin/grunt -> /opt/node/lib/node_modules/grunt-cli/bin/grunt
+ grunt-cli@1.3.2
added 153 packages from 126 contributors in 31.658s
[ root@tianxin node]
grunt-cli v1.3.2
在es安装目录下新建dashboard/head 文件夹(随意为之),拉取elasticsearch-head到head文件夹中
git clone https://gitee.com/tianxincoord/elasticsearch-head.git
安装head插件
npm install -g cnpm --registry= https://registry.npm.taobao.org
cd elasticsearch-head/
npm install
npm run start
cd elasticsearch-head/
cnpm install
cnpm run start
安装完成之后打开9100端口即可访问
config/elasticsearch.yml 需要配置允许跨域,否则无法连接
http.cors.enabled : true
http.cors.allow-origin : "*"
四、Elasticsearch常见问题
java.lang.RuntimeException: can not run elasticsearch as root
不能以root用户运行ES,需要使用es,所以切换 su es之后再运行即可 ERROR: [1] bootstrap checks failed [1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
es要求discovery.seed_hosts、discovery.seed_providers、 cluster.initial_master_nodes必须要配置其中之一 例如下面配置的配置任选其一,配置之后重新启动即可
cluster.initial_master_nodes: [“node-1”] discovery.seed_hosts: [“172.16.127.129”]
Java HotSpot™ 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
UseConcMarkSweepGC 垃圾回收器已经不建议使用,在后面会被删除 修改config/jvm.options,修改垃圾回收器
# 注释UseConcMarkSweepGC
# 8 - 13 : - XX: + UseConcMarkSweepGC
# 修改为+ UseG1GC
8 - 13 : - XX: + UseG1GC
max file descriptors [4096] for elasticsearch process is too low,increase to at least [65535]
修改**/etc/security/limits.conf**,加入下面配置 *表示所有用户,如果需要单个则指定具体用户名即可
es soft nofile 65535
es hard nofile 65535
修改/etc/security/limits.d/20-nproc.conf文件,增加下面配置
# 在文件末尾中增加下面内容
# 每个进程可以打开的文件数的限制
es soft nofile 65536
es hard nofile 65536
# 操作系统级别对每个用户创建的进程数的限制
* hard nproc 4096
# 注:* 带表Linux所有用户名称
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
配置的虚拟内存太小,需要在**/etc/sysctl.conf**加大虚拟内存
# 编辑配置文件
vim / etc/ sysctl. conf
# 加入虚拟内存配置
vm. max_map_count= 262144
# 重新加载配置
sysctl - p