Docker安装ElasticSearch8.9.0

安装ElasticSearch8.9.0

预先配置

1.在centos虚拟机中,修改配置sysctl.conf
vim /etc/sysctl.conf
2.加入配置
vm.max_map_count=262144 
3.启用配置
sysctl -p
注:这一步是为了防止启动容器时,报出如下错误:
bootstrap checks failed max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

拉取镜像运行elasticsearch

1.dockerhub 拉取镜像
docker pull elasticsearch:8.9.0
2.查看docker镜像
docker images
3.创建网桥
 docker network create es
4.运行docker镜像
docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 --network es -v esdata:/usr/share/elasticsearch/data -v esconfig:/usr/share/elasticsearch/config -v esplungs:/usr/share/elasticsearch/plugins -e "discovery.type=single-node" 镜像id

问题解决

问题1:启动失败无法访问9200
1.查看日志
docker logs -f 容器id
"log.level": "WARN", "message":"received plaintext http traffic on an https channel, closing connection Netty4HttpChannel
2.需要修改配置文件elasticsearch.yml
原因是开启了ssl,需要修改为如下配置
xpack.security.http.ssl:
 	enabled: false
3.重启容器
docker restart 容器id
问题2:需要输入密码
1.修改配置文件 elasticsearch.yml
xpack.security.enabled: true
xpack.license.self_generated.type: basic
xpack.security.transport.ssl.enabled: true
2.进入容器自行设置密码

[root@localhost _data]# docker exec -it 容器id bash
elasticsearch@a3cda7fb5558:~$ cd /bin
elasticsearch@a3cda7fb5558:/bin$ elasticsearch-setup-passwords interactive


Note: The ‘elasticsearch-setup-passwords’ tool has been deprecated. This command will be removed in a future release.


Initiating the setup of passwords for reserved users elastic,apm_system,kibana,kibana_system,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y

Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana_system]:
Reenter password for [kibana_system]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]
Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

3.重启容器
docker restart 容器id
问题1和问题2修改后的配置文件
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 07-02-2024 01:44:33
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: true
xpack.license.self_generated.type: basic
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 -------------------------

安装分词器

1.下载分词器
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.9.0/elasticsearch-analysis-ik-8.9.0.zip
2.查看数据卷位置
docker volume inspect esplungs
3.创建ik文件夹,并将压缩文件解压
/var/lib/docker/volumes/esplungs/_data/ik
4.重启容器
docker restart 容器id

你可能感兴趣的:(docker,elasticsearch,容器)