在windows上安装elastic search
时间: 2023-10-14 14:04:19 浏览: 125
好的,以下是在 Windows 上安装 ElasticSearch 的步骤:
1. 前置条件:
- Java 运行环境,建议安装 Java 8 或以上版本。
- 下载 ElasticSearch 安装包,建议下载最新版。
2. 安装 ElasticSearch:
- 解压下载的 ElasticSearch 压缩包。
- 修改 config 目录下的 elasticsearch.yml 文件:
- 将 cluster.name 字段设置为一个唯一的集群名称。
- 将 node.name 字段设置为一个唯一的节点名称。
- 双击 bin 目录下的 elasticsearch.bat 文件启动 ElasticSearch 服务。
- 打开浏览器访问 http://localhost:9200/,如果看到以下信息,则说明 ElasticSearch 已经成功安装:
```
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "p7X5aTzVQ7C5KJpF6XvBBg",
"version" : {
"number" : "7.8.1",
"build_flavor" : "default",
"build_type" : "zip",
"build_hash" : "b5ca9c58fb664ca8bf9e4057fc229b3396bf3a89",
"build_date" : "2020-07-21T16:36:48.322471Z",
"build_snapshot" : false,
"lucene_version" : "8.5.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
```
3. 配置 ElasticSearch:
- 修改 elasticsearch.yml 文件以配置 ElasticSearch。例如,将 http.port 字段设置为 9200。
- 在 config 目录下创建一个新的文件 elasticsearch.bat,内容为:
```
@echo off
cd /d %~dp0
bin\elasticsearch.bat
```
- 在 config 目录下创建一个新的文件 elasticsearch-service.bat,内容为:
```
@echo off
setlocal
set SERVICE_NAME=Elasticsearch
set SERVICE_DESC=Elasticsearch
set SERVICE_PATH=%~dp0
set SERVICE_START=%SERVICE_PATH%elasticsearch.bat
set SERVICE_STOP=%SERVICE_PATH%bin\elasticsearch-stop.bat
set SERVICE_WRAPPER=wrapper-windows-x86-32.exe
set SERVICE_LOGS_PATH=%SERVICE_PATH%\logs
set SERVICE_WORKING_PATH=%SERVICE_PATH%
set SERVICE_TMP_PATH=%SERVICE_PATH%\tmp
set SERVICE_JAVA_BIN=%JAVA_HOME%\bin\java.exe
set SERVICE_JAVA_CLASSPATH=%SERVICE_PATH%\lib\*.jar
set SERVICE_JAVA_OPTS=-Xms1g -Xmx1g
set SERVICE_STDOUT_LOG_FILE=%SERVICE_LOGS_PATH%\stdout.log
set SERVICE_STDERR_LOG_FILE=%SERVICE_LOGS_PATH%\stderr.log
set SERVICE_PID_FILE=%SERVICE_TMP_PATH%\%SERVICE_NAME%.pid
set SERVICE_DEPENDENCIES=
set SERVICE_ACCOUNT=LocalSystem
set SERVICE_STARTUP_TYPE=auto
set SERVICE_FAILURE_ACTIONS=restart/60000/restart/60000/restart/60000
set SERVICE_WRAPPER_CONF=%SERVICE_PATH%\bin\wrapper.conf
set SERVICE_WRAPPER_LOGFILE=%SERVICE_LOGS_PATH%\wrapper.log
set SERVICE_WRAPPER_LOGLEVEL=INFO
set SERVICE_WRAPPER_PIDFILE=%SERVICE_TMP_PATH%\wrapper.pid
set SERVICE_WRAPPER_CONSOLE_LOGLEVEL=INFO
set SERVICE_WRAPPER_LOGFILE_MAXSIZE=0
set SERVICE_WRAPPER_LOGFILE_MAXFILES=0
if not exist %SERVICE_TMP_PATH% (
mkdir %SERVICE_TMP_PATH%
)
if not exist %SERVICE_LOGS_PATH% (
mkdir %SERVICE_LOGS_PATH%
)
if not exist "%SERVICE_PATH%\bin\%SERVICE_WRAPPER%" (
echo "Wrapper not found at %SERVICE_PATH%\bin\%SERVICE_WRAPPER%"
goto :eof
)
set SERVICE_WRAPPER_CMD="%SERVICE_PATH%\bin\%SERVICE_WRAPPER%" -c %SERVICE_WRAPPER_CONF%
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -s %SERVICE_START%
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -p %SERVICE_PID_FILE%
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -Djava.class.path="%SERVICE_JAVA_CLASSPATH%"
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -Dwrapper.logfile="%SERVICE_WRAPPER_LOGFILE%"
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -Dwrapper.logfile.maxsize=%SERVICE_WRAPPER_LOGFILE_MAXSIZE%
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -Dwrapper.logfile.maxfiles=%SERVICE_WRAPPER_LOGFILE_MAXFILES%
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -Dwrapper.pidfile="%SERVICE_WRAPPER_PIDFILE%"
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -Dwrapper.console.loglevel=%SERVICE_WRAPPER_CONSOLE_LOGLEVEL%
set SERVICE_WRAPPER_CMD=%SERVICE_WRAPPER_CMD% -Dwrapper.logfile.loglevel=%SERVICE_WRAPPER_LOGLEVEL%
echo Installing %SERVICE_NAME% service...
%SERVICE_WRAPPER_CMD% -i
if not errorlevel 1 (
echo Starting %SERVICE_NAME% service...
net start %SERVICE_NAME%
) else (
echo Failed to install %SERVICE_NAME% service.
)
endlocal
```
- 运行 elasticsearch-service.bat 文件以安装 ElasticSearch 服务。
以上就是在 Windows 上安装 ElasticSearch 的步骤。
阅读全文