Elasticsearch Download: https://www.elastic.co/cn/downloads/elasticsearch
Wget may be used directly downloaded to a directory, all herein downloaded packages are placed in / home / tools, the move after decompression / home / apps directory
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.zip
Download unzip tool, if already installed ignore this step
yum install -y unzip zip
Extracting installation package
unzip elasticsearch-6.3.1.zip
After extracting the file folder to the next / home / apps, this step is not necessarily, but in order to install too many things to prevent subsequent confusion directory packet separating installation so
mv elasticsearch-6.3.1 /home/apps/
Under the / home / apps, elasticsearch to extract the finished, but will be reported directly to start a variety of errors, then start configuring it
Configuration ------------- ----------------------------------- Elasticsearch -------------------------
Note: The article has been configured default version 1.8 jdk, if not configured, please configure the look!
修改 elasticsearch.yml
cd /home/apps/elasticsearch-6.3.1/config vi elasticsearch.yml
Several modified as follows (the cluster name, where the default port 9200, can be changed to modify http.port, if desired)
cluster.name: xxx-es
network.host: 0.0.0.0
path.logs: /home/apps/elasticsearch-6.3.1/logs
Path.Data: /home/apps/elasticsearch-6.3.1/data not the default # directory, new mkdir data need to manually
add the following two configuration (cross-domain access)
http.cors.enabled: true http.cors.allow-origin: "*"
Save changes
New users start (after ES5.0 role does not allow root to start)
# Add users the adduser elasticsearch
# Set Password the passwd elasticsearch
# authorization chown -R & lt elasticsearch /elasticsearch-6.3.0
# switch user SU elasticsearch
# startup CD elasticsearch-6.3.0 / bin ./elasticsearch
Start may report the following error
Switch back to the root role sublicense for the user it once, it may be time to start new life became no file permissions
su root
chown -R elasticsearch /home/apps/elasticsearch-6.3.1
Error Solution
And then start again, still found error
The reason: Unable to create a local file problem, users can create a maximum number of files is too small
solution:
Switch back to the root account # su root # limits.conf modify file vi /etc/security/limits.conf
In the bottom add the following configuration file
* Soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
Switch back to elasticsearch account, and then start it again ES, and being given
The reason: the maximum virtual memory is too small
solution:
# Switch to the root account su root # modify the sysctl.conf vi /etc/sysctl.conf
Add the following configuration
vm.max_map_count=655360
Sysctl -p to execute refresh configuration
Elasticsearch user to switch back again to start the ES
The successful launch! We open the browser to access it ~
Firewall Configuration
Found open, before we have configured all nodes can access, and can also be equipped with cross-domain, why not open it?
Do not forget there firewall ah. The need to access the external port 9200 open
Enter the following command in console
# 9200 port open Firewall-cmd = --zone public --add-Port = 9200 / tcp --permanen
# refresh configuration
firewall-cmd --reload
Access http://192.168.193.129:9200/ again
Good ~ ES configuration is over
Service Startup and Shutdown
Once started directly ./elasticsearch close the console service will be stopped, it is necessary to use ./elasticsearch -d started in the background
How to turn off the service?
ps -ef|grep elasticsearch
杀掉对应的进程号就可以了
------------------------------- Elasticsearch-Head 安装及配置 --------------------------
下载及安装
面对这么个提示一定一脸懵逼吧,我要怎么查询数据?怎么知道有什么索引? Head 插件就是为了解决这个问题的,它提供可视化的页面方便用户查看节点信息,查询数据等。
接下来就开始安装Head插件吧
Elasticsearch5.0 以后head不再在plugins中直接安装了,需要独立安装
下载地址: https://pan.baidu.com/s/1kX1cMzlb6jWvHeDr2N5e-g
将下载后的压缩包放到 /home/tools 下
#解压压缩包 unzip elasticsearch-head.zip #将解压后的文件夹移动/home/apps下 mv elasticsearch-head /home/apps
进入head文件目录
cd elasticsearch-head
安装grunt用来启动head
#安装grunt命令行工具grunt-cli npm install -g grunt-cli #安装grunt及其插件 npm install grunt --save-dev #查看安装版本情况 grunt -version
配置连接信息
vi Gruntfile.js
修改如下配置(ip 和 端口号)
保存后配置防火墙,开放9100端口,在控制台输入
firewall-cmd --zone=public --add-port=9100/tcp --permanent
firewall-cmd --reload
启动head
grunt server
启动成功
在浏览器输入 http://192.168.193.129:9100
安装完成
服务启动与关闭
后台方式启动
nohup grunt server &
关闭head
#查询端口占用 netstat -tunlp |grep 9100
如果netstat没有安装,执行以下命令安装
yum install net-tools
#杀死进程
kill -9 9919
Elasticsearch-head 连接 Elasticsearch-6.0 + 检索问题
Head 连接Elasticsearch6时其他功能都好使, 但数据浏览模块不能显示数据了,一直显示搜索中,但不返回结果
看一下网络流可知报406 错误
解决办法:
cd elasticsearch-head/_site
vi vendor.js
修改如下
#1. 6886行 contentType: "application/x-www-form-urlencoded 改为 contentType: "application/json;charset=UTF-8"
#2. 7574行 var inspectData = s.contentType === "application/x-www-form-urlencoded" && 改为 var inspectData = s.contentType === "application/json;charset=UTF-8" &&
重新启动elasticsearch-head就可以正常检索了
Elasticsearch下载地址:https://www.elastic.co/cn/downloads/elasticsearch
也可以直接使用wget下载到某目录下, 本文所有下载的包都放在 /home/tools 中, 解压后移到 /home/apps目录下
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.1.zip
下载unzip工具,如果已经安装过忽略该步骤
yum install -y unzip zip
解压安装包
unzip elasticsearch-6.3.1.zip
将解压后的文件夹移动到 /home/apps 下, 此步骤非必须,但为了后续需要安装的东西太多防止目录混乱所以与安装包分离
mv elasticsearch-6.3.1 /home/apps/
到 /home/apps 下,elasticsearch 就解压完毕了,但要直接启动会报各种错误,接下来开始配置吧
----------------------------------- Elasticsearch配置 --------------------------------------
注:文章默认已配置好1.8版本jdk, 如果没配置请先配置一下!
修改elasticsearch.yml
cd /home/apps/elasticsearch-6.3.1/config vi elasticsearch.yml
修改如下几项(配置集群名称,这里端口默认为9200,如果需要修改可以改http.port)
cluster.name: xxx-es
network.host: 0.0.0.0
path.logs: /home/apps/elasticsearch-6.3.1/logs
path.data: /home/apps/elasticsearch-6.3.1/data #默认没有该目录,需要手动新建 mkdir data
增加以下两个配置(跨域访问)
http.cors.enabled: true http.cors.allow-origin: "*"
保存修改
新建启动用户 (ES5.0 以后不允许使用root角色启动)
#添加用户 adduser elasticsearch
#设置密码 passwd elasticsearch
#授权 chown -R elasticsearch /elasticsearch-6.3.0
#切换用户 su elasticsearch
#启动 cd elasticsearch-6.3.0/bin ./elasticsearch
启动可能会报如下错误
切换回root角色再为该用户授权一次就可以了, 可能是启动的时候新生成了文件没有权限
su root
chown -R elasticsearch /home/apps/elasticsearch-6.3.1
错误解决方案
再启动一次,发现依旧报错
原因:无法创建本地文件问题,用户最大可创建文件数太小
解决方案:
#切换回root账户 su root #修改limits.conf文件 vi /etc/security/limits.conf
在文件最底部增加如下配置
* soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
切换回elasticsearch账号,再启动一次ES吧,又报错了
原因:最大虚拟内存太小
解决方案:
#切换至root账户 su root #修改sysctl.conf vi /etc/sysctl.conf
添加如下配置
vm.max_map_count=655360
执行 sysctl -p 以刷新配置
再次切换回elasticsearch用户,启动ES
启动成功! 我们打开浏览器访问一下吧~
防火墙配置
发现打不开,我们之前已经配置了所有节点可以访问,并且也配置了可跨域,为什么打不开呢?
别忘了还有防火墙在啊。需要把9200的对外访问端口打开
在控制台输入以下命令
#开启9200端口 firewall-cmd --zone=public --add-port=9200/tcp --permanen
#刷新配置
firewall-cmd --reload
再次访问http://192.168.193.129:9200/
好~ES的配置到此结束
服务启动与关闭
直接用./elasticsearch启动一旦关闭控制台服务便会停掉,因此需要使用 ./elasticsearch -d 在后台启动
如何关闭服务?
ps -ef|grep elasticsearch
杀掉对应的进程号就可以了
------------------------------- Elasticsearch-Head 安装及配置 --------------------------
下载及安装
面对这么个提示一定一脸懵逼吧,我要怎么查询数据?怎么知道有什么索引? Head 插件就是为了解决这个问题的,它提供可视化的页面方便用户查看节点信息,查询数据等。
接下来就开始安装Head插件吧
Elasticsearch5.0 以后head不再在plugins中直接安装了,需要独立安装
下载地址: https://pan.baidu.com/s/1kX1cMzlb6jWvHeDr2N5e-g
将下载后的压缩包放到 /home/tools 下
#解压压缩包 unzip elasticsearch-head.zip #将解压后的文件夹移动/home/apps下 mv elasticsearch-head /home/apps
进入head文件目录
cd elasticsearch-head
安装grunt用来启动head
#安装grunt命令行工具grunt-cli npm install -g grunt-cli #安装grunt及其插件 npm install grunt --save-dev #查看安装版本情况 grunt -version
配置连接信息
vi Gruntfile.js
修改如下配置(ip 和 端口号)
保存后配置防火墙,开放9100端口,在控制台输入
firewall-cmd --zone=public --add-port=9100/tcp --permanent
firewall-cmd --reload
启动head
grunt server
启动成功
在浏览器输入 http://192.168.193.129:9100
安装完成
服务启动与关闭
后台方式启动
nohup grunt server &
关闭head
#查询端口占用 netstat -tunlp |grep 9100
如果netstat没有安装,执行以下命令安装
yum install net-tools
# Kill process
kill -9 9919
Elasticsearch-head connection retrieval problems Elasticsearch-6.0 +
Head connection Elasticsearch6 when other functions so that, but the data browsing module can not display the data, and has been displayed in the search, but does not return results
Look at the network flow report shows 406 error
Solution:
cd elasticsearch-head / _site
vi vendor.js
amend as below
#1. 6886行 contentType: "application/x-www-form-urlencoded 改为 contentType: "application/json;charset=UTF-8"
#2. 7574行 var inspectData = s.contentType === "application/x-www-form-urlencoded" && 改为 var inspectData = s.contentType === "application/json;charset=UTF-8" &&
Restart elasticsearch-head can be properly retrieved