docker 部署 es + nginx

发布时间 2023-12-21 11:42:00作者: Nihaorz

ES 安装

elasticsearch.yml

cluster.name: "docker-cluster"
node.name: "node-1"
network.host: 0.0.0.0
discovery.seed_hosts: ["127.0.0.1"]
cluster.initial_master_nodes: ["node-1"]

#开启跨域访问支持,默认为false
http.cors.enabled: true
#跨域访问允许的域名, 允许所有域名
http.cors.allow-origin: "*"
#开启安全配置
xpack.security.enabled: false

启动 es

mkdir -p data logs
chown 1000:0 -R .
docker run -d -p 9200:9200 --name es \
-v /opt/wangrui/es/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v /opt/wangrui/es/data:/usr/share/elasticsearch/data \
-v /opt/wangrui/es/logs:/usr/share/elasticsearch/logs \
--restart always \
docker.elastic.co/elasticsearch/elasticsearch:8.3.3
docker logs -f es

 

nginx 安装

通过以上配置,es启动完毕,但是要配置用户密码后进行使用,故我用 nginx 套上一层

生成 htpasswd 文件:https://tool.lu/htpasswd

我的用户名密码是 elastic /123@Abc.com

生成的文件内容

elastic:{SHA}MKvsScVLJV6qpVS1b3Nhb2a+Ml8=

将内容保存为 htpasswd_file 文件,挂载到容器的 /etc/nginx/.htpasswd 路径

修改 /etc/nginx/nginx.conf,将 nginx 启动用户设置为 root

user  root;

在 /etc/nginx/conf.d/default.conf  中添加反向代理