理解Elasticsearch最好的方式是去运行它,让我们开始吧!
安装Elasticsearch唯一的要求是安装官方新版的Java,地址:www.java.com
centOS可以直接通过yum安装最新版的java
1 | # yum -y install java |
zip包安装elasticsearch
curl -L -O http://download.elasticsearch.org/PATH/TO/VERSION.zip <1>
unzip elasticsearch-$VERSION.zip
cd elasticsearch-$VERSION
rpm安装
https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.1.1/elasticsearch-2.1.1.rpm
本人选用的是rpm安装
1、centos7下:
1 2 3 | # rpm -ivh elasticsearch-2.1.1.rpm # sudo systemctl daemon-reload # sudo systemctl enable elasticsearch.service |
启动elasticsearch
1 | sudo systemctl start elasticsearch.service |
2、centos6.x下:
1 2 | sudo chkconfig --add elasticsearch sudo service elasticsearch start |
安装并启用elasticsearch之后,可以在安装elasticsearch的机器或虚拟机上访问
curl 'http://localhost:9200/?pretty'
看到类似内容
{
"status":200,
"name":"Shrunken Bones",
"version": {
"number":"1.4.0",
"lucene_version":"4.10"
},
"tagline":"You Know, for Search"
}
3、发现问题
本人使用vagrant来管理虚拟机,发现启用elasticsearch之后,局域网内的电脑无法通过IP和端口号访问elasticsearch
4、解决问题
修改配置文件elasticsearch.yml的network.host值
1 | sudo vim /etc/elasticsearch/elasticsearch.yml |
将network.host修改如下
1 | network.host: 0.0.0.0 |
安装简易的视图工具
1 | sudo bin/plugin install mobz/elasticsearch-head |
看到类似以下提示时,表明安装成功
Installed head into /usr/share/elasticsearch/plugins/head
通过外网访问,可以看到简单的管理界面
1 | http://192.168.201.26:9200/_plugin/head/ |
到此安装完毕