docker安装elk
1.安装docker环境
2.docker pull elasticsearch:6.8.3
docker pull kibana:6.8.3
docker pull logstash:6.8.3
踩坑:期间报错 Error response from daemon: Get https://registry-1.docker.io/v2/
原因: 没有连接到可用仓库导致,修改hosts文件即可
解决办法: https://segmentfault.com/a/1190000016083023?utm_source=tag-newest
3.启动es docker run --name elasticsearch -d -p 9200:9200 -v "/opt/minos/esdata":/usr/share/elasticsearch/data {镜像id}
踩坑:启动后docker ps 看不到内容,docker ps -a发现容器被强制关停 查看日志发现max virtual memory areas vm.max_map_count [65530] is too low
解决办法:
vi /etc/sysctl.conf
添加 一行 vm.max_map_count=655360
加载参数
sysctl -p
重启
dockerr restart {容器id}
踩坑:报错 elasticsearch Failed to create node environment
原因:挂载出来的文件夹权限不够导致,chmod 777即可
参考博文: https://www.cnblogs.com/360minitao/p/11645147.html
4.启动kibana
先写配置文件 kibana.yml
# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://elasticsearch:9200" ]
xpack.monitoring.ui.container.elasticsearch.enabled: true
#汉化(汉化不全,不喜欢可以不配置)
i18n.locale: zh-CN
docker run --name kibana --link {es容器id}:{自定义别名} -v /opt/minos/kibana/kibana.yml:/opt/kibana/config/kibana.yml -p 5601:5601 -d {kibana镜像id}
5.编辑logstash配置文件
mkdir /opt/minos/logstash
chmod 777 /opt/minos/logstash
cd /opt/minos/logstash
mkdir conf.d
vi logstash.yml
path.config: /usr/share/logstash/conf.d/*.conf
xpack.monitoring.elasticsearch.hosts: [ "http://172.16.34.12:9200" ]
cd conf.d
vi logstash.conf
input{
file{
path=>"/opt/minos/logs/minos/minos-platform/minos-platform.log"
type=>"minos-devops-school"
}
}
output{
stdout{ } #日志输出到控制台
#输出到es
if[type]=="minos-devops-school"{
elasticsearch{
hosts=>"172.16.34.12"
}
}
}
6.启动logstash
docker run -it -d -p 5044:5044 -p 5045:5045 --name logstash -v /opt/minos/logstash/logstash.yml:/usr/share/logstash/config/logstash.yml -v /opt/minos/logstash/conf.d/:/usr/share/logstash/conf.d/ -v /opt/minos/logs:/opt/minos/logs {logstash镜像id}
待解决问题:
(1)12环境实施作业平台安装logstash报错:/usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:235: starting container process caused "container init exited prematurely" 原因未知
(2)71环境logstash采集ids的日志不成功,原因未知
(3)es定时清除索引内容,防止磁盘撑满
1.elk日志按照日期创建索引 https://www.cnblogs.com/zhaojonjon/p/8616756.html
2.es定时删除索引 采用shell脚本+cron定时任务的方式 https://blog.csdn.net/AriesTina/article/details/86003357