環境說明
- linux:centos7
- elasticsearch:5.6.4
- elasticsearch-head:5
目錄結構
elasticsearch/
├── docker-compose.yml
├── head
└── node
├── es1
│ ├── data
│ └── elasticsearch.yml
└── es2
├── data
└── elasticsearch.yml
複製程式碼
主節點elasticsearch.yml配置檔案
elasticsearch/node/es1/elasticsearch.yml
network.bind_host: 0.0.0.0
cluster.name: elasticsearch_cluster
cluster.routing.allocation.disk.threshold_enabled: false
node.name: master
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
複製程式碼
從節點elasticsearch.yml配置檔案
elasticsearch/node/es2/elasticsearch.yml
network.bind_host: 0.0.0.0
cluster.name: elasticsearch_cluster
cluster.routing.allocation.disk.threshold_enabled: false
node.name: node2
node.master: false
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: es1
複製程式碼
docker-compose.yml配置檔案
version: '2.0'
services:
elasticsearch-central:
image: elasticsearch:5.6.4
container_name: es1
volumes:
- /opt/modules/elasticsearch/node/es1/data:/usr/share/elasticsearch/data
- /opt/modules/elasticsearch/node/es1/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
environment:
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- ES_CLUSTERNAME=elasticsearch
command: elasticsearch
ports:
- "9200:9200"
- "9300:9300"
elasticsearch-data:
image: elasticsearch:5.6.4
container_name: es2
volumes:
- /opt/modules/elasticsearch/node/es2/data:/usr/share/elasticsearch/data
- /opt/modules/elasticsearch/node/es2/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
environment:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- ES_CLUSTERNAME=elasticsearch
command: elasticsearch
ports:
- "9201:9200"
- "9301:9300"
links:
- elasticsearch-central:elasticsearch
elasticsearch-head:
image: mobz/elasticsearch-head:5
container_name: head
volumes:
- /opt/modules/elasticsearch/head/Gruntfile.js:/usr/src/app/Gruntfile.js
- /opt/modules/elasticsearch/head/_site/app.js:/usr/src/app/_site/app.js
ports:
- "9100:9100"
links:
- elasticsearch-central:elasticsearch
複製程式碼
配置head
- 下載elasticsearch-head
cd elasticsearch
git clone git://github.com/mobz/elasticsearch-head.git
mv elasticsearch-head head
複製程式碼
下載下來的程式碼結構如下:
elasticsearch\head\Gruntfile.js
修改以下片段
connect: {
server: {
options: {
/* 預設監控:127.0.0.1,修改為:0.0.0.0 */
hostname: '0.0.0.0',
port: 9100,
base: '.',
keepalive: true
}
}
}
複製程式碼
elasticsearch\head\_site\app.js
修改以下程式碼片段
* 修改localhost為elasticsearch叢集地址,Docker部署中,一般是elasticsearch宿主機地址 */
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
複製程式碼
啟動
- 執行elasticsearch需要vm.max_map_count至少需要262144記憶體
切換到root使用者修改配置sysctl.conf
vi /etc/sysctl.conf
在尾行新增以下內容
vm.max_map_count=262144
並執行命令
sysctl -p
複製程式碼
elk啟動的時候可能會提示如下錯誤:
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
- 啟動es
docker-compose up 啟動
docker-compose down 關閉
複製程式碼
測試
elasticsearch-head視覺化頁面:http://es所在機器IP:9100
參考連結:
www.jianshu.com/p/a26c8c722…
blog.csdn.net/sinat_31908…
blog.csdn.net/ggwxk1990/a…