配置系统
vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
#修改追加内容
vim /etc/sysctl.conf
vm.max_map_count=662144
立即生效
sysctl -p
# 重启服务器
reboot
安装服务启动服务
# 1.拉取镜像
docker pull elasticsearch:8.2.3
## 安装17版本
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.15.2
# 2.创建es 相关挂载目录
mkdir -p /mydata/elasticsearch/config
mkdir -p /mydata/elasticsearch/data
mkdir -p /mydata/elasticsearch/plugins
# 3. /mydata/elasticsearch/config 下创建文件
vim elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# 允许远程访问
http.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
xpack.security.enabled: true
# 4. 设置目录权限,否则会报错
chmod +x elasticsearch.yml
# 设置为目录 777 权限
chmod -R 777 /mydata/elasticsearch
# 5. 启动容器
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms1024m -Xmx1024m" \
-v /mydata/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /mydata/elasticsearch/data:/usr/share/elasticsearch/data \
-v /mydata/elasticsearch/plugins:/usr/share/elasticsearch/plugins \
-d elasticsearch:8.2.3
# 如果启动没有报错,执行
# 配置访问es密码步骤
docker exec -it 容器id /bin/bash
# 配置密码
./bin/elasticsearch-setup-passwords interactive
账号 elastic
密码 自行设置 我这里是123456
# 安装分词插件
./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.2.3/elasticsearch-analysis-ik-8.2.3.zip
# 重启docker访问es
docker restart [ID]
启动有可能会报各种错误,我这里遇到(如果没遇到跳过这一段)
Exception in thread "main" java.nio.file.FileSystemException: /usr/share/elasticsearch/config/elasticsearch.yml.R0_9BZ4hRx-v8zK3F0U-Bw.tmp -> /usr/share/elasticsearch/config/elasticsearch.yml: Device or resource busy
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:100)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
at java.base/sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:416)
at java.base/sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:267)
at java.base/java.nio.file.Files.move(Files.java:1432)
at org.elasticsearch.xpack.security.cli.AutoConfigureNode.fullyWriteFile(AutoConfigureNode.java:1136)
at org.elasticsearch.xpack.security.cli.AutoConfigureNode.fullyWriteFile(AutoConfigureNode.java:1148)
at org.elasticsearch.xpack.security.cli.AutoConfigureNode.execute(AutoConfigureNode.java:687)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:77)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:112)
at org.elasticsearch.cli.Command.main(Command.java:77)
at org.elasticsearch.xpack.security.cli.AutoConfigureNode.main(AutoConfigureNode.java:157)
参考 https://github.com/elastic/elasticsearch/issues/85463
我这里处理方法是
启动不要挂载
# 最简单的方式启动,这里启动不会报错
docker run \
-p 9200:9200 \
-e ES_JAVA_OPTS="-Xms1024m -Xmx1024m" \
-idt elasticsearch:8.2.3
# 进入容器
docker exec -it es /bin/bash
# 复制 elasticsearch.yml
docker cp 容器id:/user/share/elasticsearch/config/elasticsearch.yml /mydata/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 12-08-2022 15:13:47
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: true
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
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["cec9bed317cd"]
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
其实也没操作什么就可以使用了,配置文件依旧是前面配置的(不要保留有改变,不要保留xpack.security的配置)
cluster.name: "docker-cluster"
network.host: 0.0.0.0
# 允许远程访问
http.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization
更多推荐