安装 elasticsearch
创建网络
docker network create es-network
启动容器 elasticsearch
docker run -d --name elasticsearch --net es-network -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:8.12.2
无法访问: http://localhost:9200/
修改配置文件 elasticsearch.yml, 位置在 /usr/share/elasticsearch/config/elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 27-03-2024 23:44:30
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: false
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
访问: http://localhost:9200/, 正常返回
{
"name" : "c58e6cb0f4d8",
"cluster_name" : "docker-cluster",
"cluster_uuid" : "1JXFArBRRd6W9NatoEPajQ",
"version" : {
"number" : "8.12.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "48a287ab9497e852de30327444b0809e55d46466",
"build_date" : "2024-02-19T10:04:32.774273190Z",
"build_snapshot" : false,
"lucene_version" : "9.9.2",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
安装 kibana
docker run -d --name kibana -e ELASTICSEARCH_HOSTS=http://elasticsearch:9200 --net es-network -p 5601:5601 kibana:8.12.2
访问: localhost:5601
安装ik
下载对应的版本: https://github.com/infinilabs/analysis-ik
修改权限
chmod -R 777 /Users/rick/Downloads/elasticsearch-analysis-ik-8.12.2/
拷贝到目录 /usr/share/elasticsearch/plugins
下
执行命令 elasticsearch-plugin list
将会显示
elasticsearch-analysis-ik-8.12.2
重启 elasticsearch
在kibana执行
POST _analyze
{
"analyzer": "ik_smart",
"text": "我是中国人, 我的家乡在江苏"
}
如果没有改ik的权限, 执行 elasticsearch-plugin list
Exception in thread "main" java.lang.IllegalStateException: Plugin [opensearch-analysis-ik-2.12.0] is missing a descriptor properties file.
at org.elasticsearch.plugins.PluginDescriptor.readFromProperties(PluginDescriptor.java:233)
at org.elasticsearch.plugins.cli.ListPluginsCommand.printPlugin(ListPluginsCommand.java:63)
at org.elasticsearch.plugins.cli.ListPluginsCommand.execute(ListPluginsCommand.java:57)
at org.elasticsearch.common.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:54)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:94)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
at org.elasticsearch.cli.Command.main(Command.java:50)
at org.elasticsearch.launcher.CliToolLauncher.main(CliToolLauncher.java:64)