1、安装部署
(1)下载
下载地址https://www.elastic.co/cn/downloads/elasticsearch
可以按照windows版那样从官网下载TAR格式解压包,上传到linux服务器上。
如果你的linux可以访问外网的话,推荐直接在linux中下载,执行如下命令:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.0-linux-x86_64.tar.gz
(2)解压
执行解压命令:
tar -zxvf elasticsearch-7.3.0-linux-x86_64.tar.gz
解压完成后,会出现elasticsearch-7.3.0目录:
(3)启动
执行启动命令:
./bin/elasticsearch -d -p pid
如果你是root用户启动的话,会报"can not run elasticsearch as root"的错误。因为安全问题elasticsearch不让用root用户直接运行,所以要创建新用户,继续阅读创建新用户步骤。
生成pid文件
(4)关闭
pkill -F pid
(5)创建新用户
第一步:liunx创建新用户:"adduser es",然后给创建的用户加密码:"passwd es",输入两次密码。
第二步:切换刚才创建的用户:"su es",然后启动elasticsearch。如果显示Permission denied权限不足,则继续进行第三步。
第三步:给新用户赋权限,因为这个用户本身就没有权限,肯定自己不能给自己付权限。所以要用root用户登录并赋予权限,chown -R es/你的elasticsearch安装目录。
chown -R es elasticsearch-7.3.0
或
chown -R es:es elasticsearch-7.3.0
通过上面三步就可以启动elasticsearch了。
(6)验证启动
如果一切正常,Elasticsearch就会在默认的9200端口运行。这时,打开另一个命令行窗口,请求该端口:
curl localhost:9200
如果得到如下的返回,就说明启动成功了:
默认情况下,Elasticsearch 只允许本机访问,如果需要远程访问,可以修改 Elasticsearch 安装目录中的config/elasticsearch.yml文件,去掉network.host的注释,将它的值改成0.0.0.0,让任何人都可以访问,然后重新启动 Elasticsearch 。
network.host: 0.0.0.0
上面代码中,"network.host:"和"0.0.0.0"中间有个空格,不能忽略,不然启动会报错。线上服务不要这样设置,要设成具体的 IP。
(7)常见错误及处理方式
错误一:max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
解决:执行下面的命令:
sudo sysctl -w vm.max_map_count=262144
检查配置是否生效
sysctl -a | grep "vm.max_map_count"
错误二:max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解决:执行下面的命令:
sudo vim /etc/security/limits.conf
然后编辑limits.conf增加如下配置:
# elasticsearch config start
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
# elasticsearch config end
保存后,执行:
sudo sysctl -p
错误三: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
一直都报这个错误,如果不配(config/elasticsearch.ym):
#cluster.initial_master_nodes: ["node-1", "node-2"]
cluster.initial_master_nodes: ["node-1"] 这个的话,这里的node-1是上面一个默认的记得打开就可以了
页面访问
http://172.171.16.222:9200/_cat/
2、elasticsearch和head插件安装
插件地址:
https://www.elastic.co/guide/en/elasticsearch/plugins/7.3/installation.html
CentOS7 Elasticsearch-7.3.0 JDK8
JDK8 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Elasticsearch-7.3.0下载地址: https://www.elastic.co/downloads/elasticsearch
安装Head插件
由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包。
(1)安装Node.js
下载解压
tar -zxf node-v12.8.0-linux-x64.tar.gz
配置并生效
vim /etc/profile
export NODE_HOME=/home/node-v12.8.0-linux-x64
export PATH=$PATH:$NODE_HOME/bin
source /etc/profile
查看版本验证
node -v
npm -v
(2)下载head插件
如果未安装git ,则先安装git工具
yum install –y git
(3)安装grunt
cd elasticsearch-head
npm install -g grunt --registry=https://registry.npm.taobao.org
npm install -g grunt-contrib-clean --registry=https://registry.npm.taobao.org --save
npm install -g grunt-contrib-concat --registry=https://registry.npm.taobao.org
npm install -g grunt-contrib-watch --registry=https://registry.npm.taobao.org
npm install -g grunt-contrib-connect --registry=https://registry.npm.taobao.org
npm install -g grunt-contrib-copy --registry=https://registry.npm.taobao.org
npm install -g grunt-contrib-jasmine --ignore-scripts --registry=https://registry.npm.taobao.org
(4)安装插件
npm install
报错:
解决方案,进入工作目录
rm -rf node_modules
rm -rf package-lock.json
npm cache clear --force
npm install
在elasticsearch-head目录下node_modules/grunt下如果没有grunt二进制程序,需要执行:
npm install grunt --save --registry=https://registry.npm.taobao.org
(5)修改配置 elasticsearch-head下Gruntfile.js文件
修改connect配置节点
在该配置文件中connect-server-options下添加hostname: '0.0.0.0',
这个配置,这样就不限制IP地址的访问了,具体看以下配置文件截图:
修改 _site/app.js 修改http://localhost:9200字段到本机ES端口与IP
(6)修改 elasticsearch配置文件
修改elasticsearch.yml文件加入以下内容:
# 是否支持跨域
http.cors.enabled: true
# *表示支持所有域名
http.cors.allow-origin: "*"
(7)启动head插件服务(后台运行)
node_modules/grunt/bin/grunt server &
1.启动head:grunt server
2.后台启动head:nohup grunt server &
3.查看head 进程:lsof -i :9100
4.停止head:kill -9 进程id
(8)查看
如下图说明安装OK