一、安装环境
系统:centos 7
java环境:
[root@localhost ~]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)
安装之前如果我们是在windows下用SSH Secure Shell Client这个工具连接centos,需要设置中文不是乱码,登录ssh后命令行:
[root@localhost ~]# export LC_ALL=zh_CN.GB2312;export LANG=zh_CN.GB2312
这个命令不是必须的,还有其他办法使中文不乱码
二、安装
1.下载Elasticsearch安装包:https://www.elastic.co/downloads/elasticsearch
2.在/usr/local建立目录eshome,把安装包放入并解压,重命名为es1:
[root@localhost eshome]# unzip elasticsearch-2.3.3.zip
[root@localhost eshome]# mv elasticsearch-2.3.3 es1
3.启动测试,出错,原因是此版本es出于安全考虑不能用root用户启动
[root@localhost eshome]# cd es1
[root@localhost es1]# bin/elasticsearch
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Refer to the log for complete error details.
4.修改es权限
创建es用户及用户组
[root@localhost es1]# groupadd elsearch
[root@localhost es1]# useradd elsearch -g elsearch -p elasticsearch
返回上级目录,更改es1文件夹及内部文件的所属用户及组为elsearch:elsearch
[root@localhost es1]# cd ..
[root@localhost eshome]# chown -R elsearch:elsearch es1
切换到elsearch用户并启动es,成功
[root@localhost eshome]$ su elsearch
[elsearch@localhost eshome]$ es1/bin/elasticsearch
以上安装es已完成,但只能在本机访问,还需要修改配置文件和系统防火墙,使其可以在远程访问:
修改配置文件:
[elsearch@localhost eshome]$ vi es1/config/elasticsearch.yml
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
Network.host: [_local_,10.10.10.201]
修改防火墙,并重新载入防火墙:
[elsearch@localhost eshome<span style="font-family: Arial, Helvetica, sans-serif;">]$ firewall-cmd --zone=public --add-port=9200/tcp --permanent</span>
Authorization failed.
Make sure polkit agent is running or run the application as superuser.
elsearch用户无权限,切换到root用户设置:
[elsearch@localhost eshome]$ su root
密码:
[root@localhost eshome]# firewall-cmd --zone=public --add-port=9200/tcp --permanent
success
[root@localhost eshome]# firewall-cmd --reload
success
或用图形界面,在永久区域添加端口后在选项中重载防火墙:
注:centos7的默认用的防火墙为更强大的Firewall,如果用iptables防火墙也需要相应设置
切换用户并后台运行es:
[root@localhost eshome]# su elsearch
[elsearch@localhost eshome]$ es1/bin/elasticsearch -d
在远程电脑浏览器打开:http://10.10.10.201:9200/ 运行成功:
安装参考:https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html
三、安装插件
head插件
[root@localhost es1]# bin/plugin install mobz/elasticsearch-head
打开http://10.10.10.201:9200/_plugin/head/ 安装成功
插件安装参考:
Elasticsearch Plugins and Integrations:https://www.elastic.co/guide/en/elasticsearch/plugins/current/index.html
Management and site plugins:https://www.elastic.co/guide/en/elasticsearch/plugins/current/management.html
Elasticsearch 相关产品文档:https://www.elastic.co/guide/index.html