docker pull docker.elastic.co/elasticsearch/elasticsearch:5.5.1
docker pull docker.elastic.co/kibana/kibana:5.5.1
docker pull docker.elastic.co/logstash/logstash:5.5.1123
啓動Elastic Search容器:git
docker run -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" \--name my-elastic -d docker.elastic.co/elasticsearch/elasticsearch:5.5.112
啓動Kibana容器:github
docker run -p 5601:5601 -e "ELASTICSEARCH_URL=http://localhost:9200" --name my-kibana \--network host -d docker.elastic.co/kibana/kibana:5.5.112
建立logstash/logstash.yml,配置xpack對於logstash的監控:docker
http.host: "0.0.0.0"path.config: /usr/share/logstash/pipelinexpack.monitoring.elasticsearch.url: http://localhost:9200xpack.monitoring.elasticsearch.username: elasticxpack.monitoring.elasticsearch.password: changeme12345
建立logstash/conf.d/logstash.conf,配置logstash的輸入輸出:json
input {
file {
path => "/tmp/access_log"
start_position => "beginning"
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
user => "elastic"
password => "changeme"
}
}12345678910111213
啓動Logstash容器:bootstrap
docker run -v /home/ubuntu/logstash/conf.d:/usr/share/logstash/pipeline/:ro -v /tmp:/tmp:ro \
-v /home/ubuntu/logstash/logstash.yml:/usr/share/logstash/config/logstash.yml:ro --name my-logstash \
--network host -d docker.elastic.co/logstash/logstash:5.5.1123
測試一下,在/tmp/access.log中添加兩行信息:ubuntu
echo "Hello World!" >> /tmp/access_logecho "Hello ELK!" >> /tmp/access_log12
打開kibana的連接http://yourhost:5601,使用用戶名/密碼: elastic/changeme登陸。在」Configure an index pattern」頁面點擊Create按鈕。點擊菜單Monitor便可查看ELK節點的狀態
在Kibana點擊Discover菜單,能夠看到相關的日誌信息:
安全
使用Elastic Search集羣部署
Elastic官方提供了用docker-compose啓動Elastic Search集羣的方法,首先安裝docker-compose服務器
curl -L https://github.com/docker/compose/releases/download/1.15.0/docker-compose-Linux-x86_64 \> /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-composedocker-compose --version1234
建立一個elasticsearch/docker-compose.yml文件:app
version: '2'
services:
elasticsearch1:
image: docker.elastic.co/elasticsearch/elasticsearch:5.5.1
container_name: elasticsearch1
environment:
- cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
volumes:
- esdata1:/usr/share/elasticsearch/data ports:
- 9200:9200 networks:
- esnet elasticsearch2:
image: docker.elastic.co/elasticsearch/elasticsearch:5.5.1
environment:
- cluster.name=docker-cluster - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" - "discovery.zen.ping.unicast.hosts=elasticsearch1" ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
volumes:
- esdata2:/usr/share/elasticsearch/data networks:
- esnetvolumes:
esdata1:
driver: local
esdata2:
driver: local
networks:
esnet:123456789101112131415161718192021222324252627282930313233343536373839404142434445
在/etc/sysctl.conf文件中追加一行curl
vm.max_map_count = 2621441
執行命令應用變動:
sudo sysctl -p1
在docker-compose.yml所在的目錄執行如下命令,啓動elastic search集羣:
docker stop my-elastic && docker rm my-elasticdocker-compose up &12
在Kibana中Monitor菜單中能夠看到,Elastic Search集羣已經正常工做:
修改默認密碼
Elastic Docker Images的默認帳號密碼是elastic/changeme,使用默認密碼是不安全的,假設要把密碼改成elastic0。在Docker所在服務器上執行命令,修改用戶elastic的密碼:
curl -XPUT -u elastic 'localhost:9200/_xpack/security/user/elastic/_password' -H "Content-Type: application/json" \-d '{
"password" : "elastic0"
}'1234
設置密碼,重啓Kibana:
docker stop my-kibana && docker rm my-kibanadocker run -p 5601:5601 -e "ELASTICSEARCH_URL=http://localhost:9200" -e "ELASTICSEARCH_PASSWORD=elastic0" \--name my-kibana --network host -d docker.elastic.co/kibana/kibana:5.5.1123
修改logstash/logstash.yml,logstash/conf.d/logstash.conf中的密碼,而後重啓logstash服務
docker restart my-logstash1
測試一下,在/tmp/access.log中添加兩行信息:
echo "Hello World!" >> /tmp/access_logecho "Hello ELK!" >> /tmp/access_log12
打開kibana的連接http://yourhost:5601,使用用戶名/密碼: elastic/elastic0登陸。在」Configure an index pattern」頁面點擊Create按鈕。點擊菜單Monitor便可查看ELK節點的狀態,默認密碼已經修改爲功。