Github上开源仿京东商城项目-安装部署(五)
13、安装elasticsearch
提示:运行elasticsearch需要jdk 11以上版本,否则将使用自带捆绑的jdk,当前安装的版本为1.8,所以在后续命令执行前执行一下
set JAVA_HOME=
13.1 解压缩elasticsearch-7.11.2-windows-x86_64.zip到c:\elasticsearch下
然后在plugins目录下新建一个ik目录
解压缩elasticsearch-analysis-ik-7.11.2.zip到c:\elasticsearch\plugins\ik下
13.2 配置elasticsearch集群
把c:\elasticsearch 复制3份为
c:\elasticsearch\001
c:\elasticsearch\002
c:\elasticsearch\003
编辑c:\elasticsearch\001\config\elasticsearch.yml
cluster.name: supermarket
node.name: node-1
transport.tcp.port: 9300
http.port: 9200
network.host: 127.0.0.1
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
cluster.initial_master_nodes: ["node-1"]
node.data: true
node.master: true
编辑c:\elasticsearch\002\config\elasticsearch.yml
cluster.name: supermarket
node.name: node-2
transport.tcp.port: 9301
http.port: 9201
network.host: 127.0.0.1
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
node.data: true
node.master: true
编辑c:\elasticsearch\003\config\elasticsearch.yml
cluster.name: supermarket
node.name: node-3
transport.tcp.port: 9302
http.port: 9202
network.host: 127.0.0.1
http.cors.enabled: true
http.cors.allow-origin: "*"
discovery.seed_hosts: ["127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302"]
node.data: true
node.master: true
13.3 安装head插件
安装nodejs:
https://nodejs.org/en/download/
https://nodejs.org/dist/v14.16.0/node-v14.16.0-x64.msi
安装phantomjs
https://phantomjs.org/download.html
把文件解压缩到C:\phantomjs下
然后把C:\phantomjs\bin添加到PATH路径中
下载head插件源码:
https://codeload.github.com/mobz/elasticsearch-head/zip/refs/tags/v5.0.0
解压缩到C:\elasticsearch\elasticsearch-head-5.0.0
cd C:\elasticsearch\elasticsearch-head-5.0.0
npm install -g grunt-cli 编译源码
npm install
npm audit fix
grunt server启动服务
这时访问http://localhost:9100/将可见集群监控界面,然后启动集群,就能看到集群状态了
13.4 启动集群
开四个命令行窗口
第一个
set JAVA_HOME=
c:\elasticsearch\001\bin\elasticsearch.bat
第二个
set JAVA_HOME=
c:\elasticsearch\002\bin\elasticsearch.bat
第三个
set JAVA_HOME=
c:\elasticsearch\003\bin\elasticsearch.bat
第四个
c:\elasticsearch\elasticsearch-head-5.0.0\grunt server
访问http://127.0.0.1:9200/_cat/nodes?pretty
访问http://localhost:9100/
注注注:集群加入不成功,极可能是因为在data文件夹下由于来回启动产生了一些文件,第一次启动集群时请清空data目录
13.5 配置项目中的elasticsearch设置
搜索项目中如下字段进行替换
# spring.data.elasticsearch.cluster-name=supermarket
# spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300,127.0.0.1:9301,127.0.0.1:9302
spring.elasticsearch.rest.uris=http://127.0.0.1:9200
一共两个地方进行修改,每个地方都要注释掉两行,更改一行