Elasticsearch环境搭建
创建目录结构为
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| docker-es/ ├── docker-compose.yaml ├── master │ ├── conf │ │ └── elasticsearch.yml │ ├── data │ └── logs ├── node1 │ ├── conf │ │ └── elasticsearch.yml │ ├── data │ └── logs └── node2 ├── conf │ └── elasticsearch.yml ├── data └── logs
|
docker-compose.yaml
文件内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| version: '3' services: es-master: image: elasticsearch:7.6.0 container_name: es-master restart: always volumes: - ./master/data:/usr/share/elasticsearch/data:rw - ./master/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ./master/logs:/user/share/elasticsearch/logs:rw ports: - "9200:9200" - "9300:9300" environment: - "ES_JAVA_OPTS=-Xms512m -Xmx512m" es-node1: image: elasticsearch:7.6.0 container_name: es-node1 volumes: - ./node1/data:/usr/share/elasticsearch/data:rw - ./node1/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ./node1/logs:/user/share/elasticsearch/logs:rw es-node2: image: elasticsearch:7.6.0 container_name: es-node2 restart: always volumes: - ./node2/data:/usr/share/elasticsearch/data:rw - ./node2/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml - ./node2/logs:/user/share/elasticsearch/logs:rw es-head: image: tobias74/elasticsearch-head:6 container_name: es-head restart: always ports: - "9100:9100"
|
master/conf/elasticsearch.yml
文件内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| bootstrap.memory_lock: false cluster.name: "es-cluster" node.name: "es-master" node.master: true node.data: true network.host: 0.0.0.0 http.port: 9200 transport.tcp.port: 9300 discovery.seed_hosts: ["127.0.0.1:9300"] discovery.zen.minimum_master_nodes: 1 cluster.initial_master_nodes : ["es-master"]
http.cors.enabled: true http.cors.allow-origin: "*" xpack.security.audit.enabled: true
|
node1/conf/elasticsearch.yml
文件内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| cluster.name: "es-cluster" node.name: "es-node1" node.master: false node.data: true network.host: 0.0.0.0 http.port: 9201 transport.tcp.port: 9301 cluster.initial_master_nodes : ["es-master"] discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"]
path.logs: /usr/share/elasticsearch/logs
http.cors.enabled: true http.cors.allow-origin: "*"
|
node2/conf/elasticsearch.yml
文件内容:
1 2 3 4 5 6 7 8 9 10
| cluster.name: "es-cluster" node.name: "es-node2" node.master: false node.data: true network.host: 0.0.0.0 http.port: 9202 transport.tcp.port: 9302 discovery.seed_hosts: ["127.0.0.1:9300","127.0.0.1:9301","127.0.0.1:9302"] cluster.initial_master_nodes : ["es-master"] path.logs: /usr/share/elasticsearch/logs
|
docker-compose up
启动即可
启动错误解决
- docker以挂载配置文件启动elasticsearch的时候会报错误,所以需要给予文件夹权限
赋权命令:
1 2 3
| chmod 777 master/data/ chmod 777 node1/data/ chmod 777 node2/data/
|