文章包含:
1,docker部署配置nginx
2,docker部署配置filebeat
3,docker部署配置kibana
1,nginx镜像并启动测试
docker pull nginx
docker run --name testnginx -p 8088:80 -d nginx
2,接下来实际部署nginx
mkdir logs # 存储日志信息,后续filebeat配置该路径抓取日志文件
mkdir data # 存储html等文件
mkdir conf #存储配置文件
mkdir conf.d #存储扩展配置文件
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf; #扩展配置文件的路径
}
server {
listen 80;
server_name localhost;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root /usr/share/nginx/html;
}
}
<html>
<head>
<meta charset="utf-8">
<title>hello,worldtitle>
head>
<body>
<h1>docker-nginx部署成功!h1>
body>
html>
docker run --name nginx -d -p 8080:80 --restart=always --privileged=true -v /docker/nginx/data/html:/usr/share/nginx/html -v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /docker/nginx/logs:/var/log/nginx -v /docker/nginx/conf.d:/etc/nginx/conf.d -d nginx
3,下载配置fiebeat
第一步:下载filebeat镜像和配置文件
下载镜像和官方配置文件:
docker pull store/elastic/filebeat:7.4.1 #下载镜像
curl -L -O https://raw.githubusercontent.com/elastic/beats/7.6/deploy/docker/filebeat.docker.yml #下载官方配置文件
filebeat.config:
modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
filebeat.autodiscover:
providers:
- type: docker
hints.enabled: true
processors:
- add_cloud_metadata: ~
output.elasticsearch:
# hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
# username: '${ELASTICSEARCH_USERNAME:}'
# password: '${ELASTICSEARCH_PASSWORD:}'
hosts: ["*.*.*.*:9200","*.*.*.*:9201","*.*.*.*:9202"] #自己es配置的地址
# 启动nginx,此处用到了自定的nginx文件
docker run \
--label co.elastic.logs/enable=true \
--label co.elastic.logs/module=nginx \
--label co.elastic.logs/fileset.stdout=access \
--label co.elastic.logs/fileset.stderr=error \
--name nginx_01 -v /docker/nginx/data/html:/usr/share/nginx/html \
-v /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /docker/nginx/logs:/var/log/nginx -v \
/docker/nginx/conf.d:/etc/nginx/conf.d -p 80:80 -d nginx
#启动filebeat,使用我们刚才下载修改过的官方配置文件
docker run -d \
--name=filebeat-nginx\
--user=root \
--volume="/docker/filebeat/config/filebeat.docker.yml:/usr/share/filebeat/filebeat.yml:ro" \
--volume="/var/lib/docker/containers:/var/lib/docker/containers:ro" \
--volume="/var/run/docker.sock:/var/run/docker.sock:ro" \
store/elastic/filebeat:7.4.1 -e -strict.perms=false
4,下载配置Kibana
docker pull kibana:7.6.2
注:作者这里的elasticsearch是7.6.2的,kibana版本尽量和es保持一致。
启动Kibana:
#首先创建自定义网络
docker run -it -d -e ELASTICSEARCH_URL=http://127.0.0.1:9200 -p 5601:5601 --name kibana kibana:7.6.2
接下来看一下Kibana的启动状态:
稍等一会儿后查看浏览器访问机器ip:5601查看是否成功启动:
如上显示即启动成功。
5,期间遇到的问题:Kibana:server is not ready yet
解决办法:使用docker exec -it 【容器id】 /bin/bash,进入config文件夹下修改http://elasticsearch:9200的elasticsearch为自己的机器ip
参考链接:https://blog.csdn.net/whatday/article/details/107879989