ES 集群节点配置
关闭 SELinux
setenforce 0 getenforce
防火墙配置
firewalld --zone=public --add-port=9200/tcp --permanent firewalld --zone=public --add-port=9300/tcp --permanent firewalld-cmd --reload
在三台宿主机上挂载同一个 NFS 目录作为备份存储
在任意一台机器(比如 135)上搭建 NFS Server
# 安装 NFS 服务 yum install -y nfs-utils rpcbind # 创建共享目录 mkdir -p /data/es-backup chown -R 1000:1000 /data/es-backup chmod -R 775 /data/es-backup # 配置共享 echo "/data/es-backup 192.168.149.0/24(rw,sync,no_root_squash,no_subtree_check)" >> /etc/exports # 启动服务 systemctl start rpcbind nfs-server systemctl enable rpcbind nfs-server exportfs -rv
在 135、136、137 三台机器上挂载 NFS
yum install -y nfs-utils mkdir -p /usr/local/es-cluster/es-backup # 挂载到宿主机目录 mount -t nfs 192.168.149.135:/data/es-backup /usr/local/es-cluster/es-backup # 开机自动挂载 echo "192.168.149.135:/data/es-backup /usr/local/es-cluster/es-backup nfs defaults 0 0" >> /etc/fstab
三台宿主机都要给目录 UID 1000 权限
chown -R 1000:1000 /usr/local/es-cluster/es-backup chmod -R 775 /usr/local/es-cluster/es-backup
node1
docker-compose-cluster.yml
version: '2.2'
services:
# ==================== Elasticsearch 集群 ====================
es-node1:
image: elastic.m.daocloud.io/elasticsearch/elasticsearch:7.10.2
container_name: es-node1
restart: always
environment:
- "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 131072
volumes:
- ./node/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./node/data:/usr/share/elasticsearch/data
- ./node/plugins:/usr/share/elasticsearch/plugins
- ./node/logs:/usr/share/elasticsearch/logs
- ./es-backup:/usr/share/elasticsearch/backup
ports:
- "9200:9200"
- "9300:9300"
networks:
- es-net
networks:
es-net:
driver: bridge
elasticsearch.yml
# 集群名称,单机环境可以自定义 cluster.name: "es-docker-cluster" # 节点名称 node.name: "es-node1" node.master: true node.data: true # 允许外部访问,Docker 部署必须配置 # 否则只能容器内部访问,宿主机无法通过 9200 端口连接 network.host: 0.0.0.0 network.publish_host: 192.168.149.135 # 单节点模式,跳过集群引导检查,适合本地开发测试 #discovery.type: single-node discovery.seed_hosts: ["192.168.149.135:9300", "192.168.149.136:9300", "192.168.149.137:9300"] # HTTP 端口,用于 REST API 访问 http.port: 9200 # 传输端口,用于节点之间通信 transport.port: 9300 # 关闭安全认证,仅限本地开发测试环境使用 # 生产环境务必开启,并配置用户名密码和 TLS xpack.security.enabled: false # 关闭传输层 SSL xpack.security.transport.ssl.enabled: false # 关闭 HTTP 层 SSL xpack.security.http.ssl.enabled: false # 数据存储路径,与 docker-compose.yml 中的挂载路径对应 #path.data: /usr/share/elasticsearch/data path.repo: ["/usr/share/elasticsearch/backup"] # 日志存储路径,与 docker-compose.yml 中的挂载路径对应 #path.logs: /usr/share/elasticsearch/logs # 开启跨域访问,方便前端工具或浏览器直接访问 ES http.cors.enabled: true # 允许所有来源跨域访问,仅限测试环境 http.cors.allow-origin: "*" # 锁定内存,防止 Elasticsearch 内存被交换到磁盘 # 需要配合 docker-compose.yml 中的 ulimits.memlock 使用 bootstrap.memory_lock: true
node2
docker-compose.yml
version: '2.2' services: # ==================== Elasticsearch 集群 ==================== es-node2: image: elastic.m.daocloud.io/elasticsearch/elasticsearch:7.10.2 container_name: es-node2 restart: always environment: - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 131072 volumes: - ./node/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ./node/data:/usr/share/elasticsearch/data - ./node/plugins:/usr/share/elasticsearch/plugins - ./node/logs:/usr/share/elasticsearch/logs - ./es-backup:/usr/share/elasticsearch/backup ports: - "9200:9200" - "9300:9300" networks: - es-net networks: es-net: driver: bridge
elasticsearch.yml
cluster.name: es-docker-cluster node.name: es-node2 node.master: true node.data: true network.host: 0.0.0.0 network.publish_host: 192.168.149.136 http.port: 9200 transport.tcp.port: 9300 discovery.seed_hosts: ["192.168.149.135:9300", "192.168.149.136:9300", "192.168.149.137:9300"] #cluster.initial_master_nodes: ["es-node1", "es-node2", "es-node3"] http.cors.enabled: true http.cors.allow-origin: "*" xpack.security.enabled: false bootstrap.memory_lock: true
node3
docker-compose.yml
version: '2.2' services: # ==================== Elasticsearch 集群 ==================== es-node3: image: elastic.m.daocloud.io/elasticsearch/elasticsearch:7.10.2 container_name: es-node3 restart: always environment: - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" ulimits: memlock: soft: -1 hard: -1 nofile: soft: 65536 hard: 131072 volumes: - ./node/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ./node/data:/usr/share/elasticsearch/data - ./node/plugins:/usr/share/elasticsearch/plugins - ./node/logs:/usr/share/elasticsearch/logs - ./es-backup:/usr/share/elasticsearch/backup ports: - "9200:9200" - "9300:9300" networks: - es-net networks: es-net: driver: bridge
elasticsearch.yml
cluster.name: es-docker-cluster node.name: es-node3 node.master: true node.data: true network.host: 0.0.0.0 network.publish_host: 192.168.149.137 http.port: 9200 transport.tcp.port: 9300 discovery.seed_hosts: ["192.168.149.135:9300", "192.168.149.136:9300", "192.168.149.137:9300"] #cluster.initial_master_nodes: ["es-node1", "es-node2", "es-node3"] http.cors.enabled: true http.cors.allow-origin: "*" xpack.security.enabled: false bootstrap.memory_lock: true path.repo: ["/usr/share/elasticsearch/backup"]
kibana
docker-compose.yml
version: '2.2' services: # ==================== Kibana ==================== kibana: image: elastic.m.daocloud.io/kibana/kibana:7.10.2 container_name: kibana restart: always environment: # - ELASTICSEARCH_HOSTS=["http://192.168.149.135:9200","http://192.168.149.136:9200","http://192.168.149.137:9200"] - SERVER_HOST=0.0.0.0 ports: - "5601:5601" volumes: - ./config/kibana.yml:/usr/share/kibana/config/kibana.yml networks: - es-net networks: es-net: # external: true driver: bridge
kibana.yml
server.name: kibana server.host: "0.0.0.0" server.port: 5601 elasticsearch.hosts: - "http://192.168.149.135:9200" - "http://192.168.149.136:9200" - "http://192.168.149.137:9200" # 请求超时,避免节点临时不可达时立即报错 elasticsearch.requestTimeout: 60000 elasticsearch.pingTimeout: 30000 i18n.locale: "zh-CN"
nginx
docker-compose.yml
version: '2.2' services: nginx: image: nginx:latest container_name: nginx restart: always ports: - "80:80" volumes: - ./nginx.conf:/etc/nginx/nginx.conf:ro - ./html:/usr/share/nginx/html:ro networks: - es-net networks: es-net: driver: bridge
nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream kibana { server 192.168.149.135:5601; } upstream es_cluster { server 192.168.149.135:9200; server 192.168.149.136:9200; server 192.168.149.137:9200; } server { listen 80; server_name 192.168.149.135; # Kibana location / { proxy_pass http://kibana; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_read_timeout 300s; } # Elasticsearch location /es/ { proxy_pass http://es_cluster/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }

浙公网安备 33010602011771号