docker 部署 es + nginx

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  中添加反向代理

location / {
    proxy_pass http://192.168.101.238:9200;
    proxy_redirect default;
    proxy_read_timeout 600s;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    index index.html index.htm;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
}
posted @ 2023-12-21 11:39  Nihaorz  阅读(9)  评论(0编辑  收藏  举报