在linux服务器上安装docker以后,pull相关的官方docker镜像:
1
2
3
|
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.1 |
启动elastic search容器:
1
2
|
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.1 |
启动kibana容器:
1
2
|
docker run -p 5601:5601 -e "elasticsearch_url=http://localhost:9200" --name my-kibana \ --network host -d docker.elastic.co /kibana/kibana :5.5.1 |
创建logstash/logstash.yml,配置xpack对于logstash的监控:
1
2
3
4
5
|
http.host: "0.0.0.0" path.config: /usr/share/logstash/pipeline xpack.monitoring.elasticsearch.url: http://localhost:9200 xpack.monitoring.elasticsearch.username: elastic xpack.monitoring.elasticsearch.password: changeme |
创建logstash/conf.d/logstash.conf,配置logstash的输入输出:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
input { file { path => "/tmp/access_log" start_position => "beginning" } } output { elasticsearch { hosts => ["localhost:9200"] user => "elastic" password => "changeme" } } |
启动logstash容器:
1
2
3
|
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.1 |
测试一下,在/tmp/access.log中添加两行信息:
1
2
|
echo "hello world!" >> /tmp/access_log echo "hello elk!" >> /tmp/access_log |
打开kibana的链接http://yourhost:5601,使用用户名/密码: elastic/changeme登录。在”configure an index pattern”页面点击create按钮。点击菜单monitor即可查看elk节点的状态
在kibana点击discover菜单,可以看到相关的日志信息:
使用elastic search集群部署
elastic官方提供了用docker-compose启动elastic search集群的方法,首先安装docker-compose
1
2
3
4
|
curl -l https: //github .com /docker/compose/releases/download/1 .15.0 /docker-compose-linux-x86_64 \ > /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker-compose --version |
创建一个elasticsearch/docker-compose.yml文件:
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
39
40
41
42
43
44
45
|
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: - esnet volumes: esdata1: driver: local esdata2: driver: local networks: esnet: |
在/etc/sysctl.conf文件中追加一行
1
|
vm.max_map_count = 262144 |
执行命令应用变更:
1
|
sudo sysctl -p |
在docker-compose.yml所在的目录执行以下命令,启动elastic search集群:
1
2
|
docker stop my-elastic && docker rm my-elastic docker-compose up & |
在kibana中monitor菜单中可以看到,elastic search集群已经正常工作:
修改默认密码
elastic docker images的默认账号密码是elastic/changeme,使用默认密码是不安全的,假设要把密码改为elastic0。在docker所在服务器上执行命令,修改用户elastic的密码:
1
2
3
4
|
curl -xput -u elastic 'localhost:9200/_xpack/security/user/elastic/_password' -h "content-type: application/json" \ -d '{ "password" : "elastic0" }' |
设置密码,重启kibana:
1
2
3
|
docker stop my-kibana && docker rm my-kibana docker 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.1 |
修改logstash/logstash.yml,logstash/conf.d/logstash.conf中的密码,然后重启logstash服务
1
|
docker restart my-logstash |
测试一下,在/tmp/access.log中添加两行信息:
1
2
|
echo "hello world!" >> /tmp/access_log echo "hello elk!" >> /tmp/access_log |
打开kibana的链接http://yourhost:5601,使用用户名/密码: elastic/elastic0登录。在”configure an index pattern”页面点击create按钮。点击菜单monitor即可查看elk节点的状态,默认密码已经修改成功。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/gongxsh00/article/details/77001603