2.1 安装包下载
1)Elasticsearch官网: https://www.elastic.co/products/elasticsearch
2.2 安装Elasticsearch(单节点Linux环境)
2.2.1 在/usr/local下创建目录es
上传下载包elasticsearch-7.8.0-linux-x86_64.tar.gz,解压
2.2.2 进入elasticsearch-7.8.0目录创建data和logs文件夹
2.2.3 修改配置文件../../config/elasticsearch.yml
# ---------------------------------- Cluster ----------------------------------- cluster.name: my-application # ------------------------------------ Node ------------------------------------ node.name: node-102 # ----------------------------------- Paths ------------------------------------ path.data: /usr/local/es/elasticsearch-7.8.0/data path.logs: /usr/local/es/elasticsearch-7.8.0/logs # ----------------------------------- Memory ----------------------------------- bootstrap.memory_lock: false bootstrap.system_call_filter: false # ---------------------------------- Network ----------------------------------- network.host: 192.168.1.102 # --------------------------------- Discovery ---------------------------------- discovery.zen.ping.unicast.hosts: ["hadoop102"] |
- cluster.name
- 如果要配置集群需要两个节点上的elasticsearch配置的cluster.name相同,都启动可以自动组成集群,这里如果不改cluster.name则默认是cluster.name=my-application
- nodename随意取但是集群内的各节点不能相同
- 修改后的每行前面不能有空格,修改后的“:”后面必须有一个空格
2.2.4 创建用户
es安装好之后,使用root启动会报错:can not run elasticsearch as root
原因:为了安全不允许使用root用户启动解决:
es5之后的都不能使用添加启动参数或者修改配置文件等方法启动了,必须要创建用户
#1、创建用户:elasticsearch
adduser elasticsearch
#2、创建用户密码,需要输入两次
passwd elasticsearch
#3、将对应的文件夹权限赋给该用户
chown -R elasticsearch /usr/local/es
#4、切换至elasticsearch用户
su elasticsearch
#5、进入启动目录启动 /usr/local/es/elasticsearch-7.8.0/bin/
#使用后台启动方式:./elasticsearch -d
./elasticsearch -d
2.2.5 配置linux系统环境
(参考:http://blog.csdn.net/satiling/article/details/59697916)
(1)切换到root用户,编辑limits.conf 添加类似如下内容
vi /etc/security/limits.conf
添加如下内容:
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
(2)切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf
添加下面配置:
vm.max_map_count=655360
并执行命令:
sysctl -p
然后,重新启动elasticsearch,即可启动成功。
2.2.6 启动
#解压目录下
bin/elasticsearch
#bin目录下
./elasticsearch
#后台运行
bin/elasticsearch -d
./elasticsearch -d
2.2.7 测试
2.2.8 停止
kill -9 进程号
2.3 安装Elasticsearch常见错误
2.31 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
每个进程最大同时打开文件数太小,可通过下面2个命令查看当前数量
ulimit -Hn ulimit -Sn
修改/etc/security/limits.conf文件,增加配置,用户退出后重新登录生效
* soft nofile 65536
* hard nofile 65536
2.3.2 max number of threads [3818] for user [es] is too low, increase to at least [4096]
问题同上,最大线程个数太低。修改配置文件/etc/security/limits.conf(和问题1是一个文件),增加配置
* soft nproc 4096
* hard nproc 4096
可通过命令查看
ulimit -Hu
ulimit -Su
修改后的文件:
2.3.3 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
修改/etc/sysctl.conf文件,增加配置vm.max_map_count=262144
vi /etc/sysctl.conf
sysctl -p
执行命令sysctl -p生效
2.3.4 Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch/elasticsearch-6.2.2-1/config/jvm.options
elasticsearch用户没有该文件夹的权限,执行命令
chown -R es:es /usr/local/elasticsearch/
2.4 Elasticsearch head插件安装
1)下载插件
https://github.com/mobz/elasticsearch-head
elasticsearch-head-master.zip
2)nodejs官网下载安装包
node-v6.9.2-linux-x64.tar.xz
3)将elasticsearch-head-master.zip和node-v6.9.2-linux-x64.tar.xz都导入到linux的/opt/software目录。
4)安装nodejs
[atguigu@hadoop102 software]$ tar -zxvf node-v6.9.2-linux-x64.tar.gz -C /opt/module/
5)配置nodejs环境变量
[root@hadoop102 software]# vi /etc/profile
export NODE_HOME=/opt/module/node-v6.9.2-linux-x64
export PATH=$PATH:$NODE_HOME/bin
[root@hadoop102 software]# source /etc/profile
6)查看node和npm版本
[root@hadoop102 software]# node -v
v6.9.2
[root@hadoop102 software]# npm -v
3.10.9
7)解压head插件到/opt/module目录下
[atguigu@hadoop102 software]$ unzip elasticsearch-head-master.zip -d /opt/module/
8)查看当前head插件目录下有无node_modules/grunt目录:
没有:执行命令创建:
[atguigu@hadoop102 elasticsearch-head-master]$ npm install grunt --save
9)安装head插件:
[atguigu@hadoop102 elasticsearch-head-master]$ npm install -g cnpm --registry=https://registry.npm.taobao.org
10)安装grunt:
[atguigu@hadoop102 elasticsearch-head-master]$ npm install -g grunt-cli
11)编辑Gruntfile.js
[atguigu@hadoop102 elasticsearch-head-master]$ vim Gruntfile.js
文件93行添加hostname:'0.0.0.0'
options: {
hostname:'0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
12)检查head根目录下是否存在base文件夹
没有:将 _site下的base文件夹及其内容复制到head根目录下
[atguigu@hadoop102 elasticsearch-head-master]$ mkdir base
[atguigu@hadoop102 _site]$ cp base/* ../base/
13)启动grunt server:
[atguigu@hadoop102 elasticsearch-head-master]$ grunt server -d
Running "connect:server" (connect) task
[D] Task source: /opt/module/elasticsearch-head-master/node_modules/grunt-contrib-connect/tasks/connect.js
Waiting forever...
Started connect web server on http://localhost:9100
如果提示grunt的模块没有安装:
Local Npm module “grunt-contrib-clean” not found. Is it installed?
Local Npm module “grunt-contrib-concat” not found. Is it installed?
Local Npm module “grunt-contrib-watch” not found. Is it installed?
Local Npm module “grunt-contrib-connect” not found. Is it installed?
Local Npm module “grunt-contrib-copy” not found. Is it installed?
Local Npm module “grunt-contrib-jasmine” not found. Is it installed?
Warning: Task “connect:server” not found. Use –force to continue.
执行以下命令:
npm install grunt-contrib-clean -registry=https://registry.npm.taobao.org
npm install grunt-contrib-concat -registry=https://registry.npm.taobao.org
npm install grunt-contrib-watch -registry=https://registry.npm.taobao.org
npm install grunt-contrib-connect -registry=https://registry.npm.taobao.org
npm install grunt-contrib-copy -registry=https://registry.npm.taobao.org
npm install grunt-contrib-jasmine -registry=https://registry.npm.taobao.org
最后一个模块可能安装不成功,但是不影响使用。
14)浏览器访问head插件:
15)启动集群插件后发现集群未连接
在/opt/module/elasticsearch-5.2.2/config路径下修改配置文件elasticsearch.yml,在文件末尾增加
[atguigu@hadoop102 config]$ pwd
/opt/module/elasticsearch-5.2.2/config
[atguigu@hadoop102 config]$ vi elasticsearch.yml
http.cors.enabled: true
http.cors.allow-origin: "*"
再重新启动elasticsearch。
16)关闭插件服务
ctrl+c
[atguigu@hadoop102 elasticsearch-head-master]$ netstat -lntp | grep 9100
tcp 0 0 192.168.1.102:9100 0.0.0.0:* LISTEN 6070/grunt
申明:内容来自网络,仅供学习使用