Laravel Homestead:安装 Elasticsearch 搜索引擎
修改配置
Homestead 里安装 Elasticsearch,只需在 Homestead.yaml 中加入 elasticsearch: 6
即可,如下:
Homestead.yaml
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
# 使用 Elasticsearch
elasticsearch: 6
.
.
.
应用修改
保存修改后,在主机中使用以下命令应用修改到 Homestead 虚拟机中:
> vagrant reload --provision
连接信息
虚拟机:
- host: 127.0.0.1
- port: 9200
主机:
- 需要自行配置 端口转发
背后的代码
这里我们简单讲下以上操作背后的信息,以助于理解其工作原理。
当配置信息里设置了 elasticsearch: 6
时,会触发 homestead.rb 里的这段操作,然后会去调用 Shell 脚本 install-elasticsearch.sh 来安装 Elasticsearch 搜索引擎。
测试一下
输出类似数据即可:
$ curl http://127.0.0.1:9200
{
"name" : "pyc3ycz",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "6RjF1u6pTCeVjk7yOTQAHQ",
"version" : {
"number" : "6.4.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "595516e",
"build_date" : "2018-08-17T23:18:47.308994Z",
"build_snapshot" : false,
"lucene_version" : "7.4.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
失败的情况输出类似以下:
$ curl http://127.0.0.1:9200
curl: (7) Failed to connect to 127.0.0.1 port 9200: Connection refused
厉害
安装失败,如何重新安装呢,提示已经‘Elasticsearch already installed.’