网站开发工程师swot分析,带导航栏的网站,网站营运费,网站如何做的看起来高大上1、阿里云sls平台集成日志
阿里sls集成日志步骤
2、filebeat 收集到指定es
安装docker容器
Docker安装
拉取镜像#xff1a;
docker pull elastic/filebeat:7.5.1启动#xff1a;
docker run -d --namefilebeat elastic/filebeat:7.5.1拷贝容器中的数据文件到宿主机
docker pull elastic/filebeat:7.5.1启动
docker run -d --namefilebeat elastic/filebeat:7.5.1拷贝容器中的数据文件到宿主机
mkdir -p /data/elk7
docker cp filebeat:/usr/share/filebeat /data/elk7/设置权限
chmod 777 -R /data/elk7/filebeat
#go-w: 这个命令表示去掉文件的“组”和“其他用户”的写权限。其中
#g 代表组权限o 代表其他用户权限-w 表示去掉写权限。
chmod go-w /data/elk7/filebeat/filebeat.yml配置filebeat
vim /data/elk7/filebeat/filebeat.yml修改样例如下
filebeat.inputs:- type: logenabled: truepaths:- /var/log/*.logfields:AppId: springbootadminENV: DEVfields_under_root: truetags: [服务ip地址自定义其他, boot]json.keys_under_root: true- type: logenabled: truepaths:- /java/*.logfields:AppId: live-adminENV: DEVfields_under_root: truetags: [服务ip地址自定义其他, live]json.keys_under_root: trueprocessors:- timestamp:field: timetimezone: Asia/Shanghailayouts:- yyyy-MM-dd HH:mm:ss.SSSoutput.elasticsearch:hosts: es:9200username: elasticpassword: elasticindices:- index: spring-boot-admin-%{yyyy.MM}when.contains:tags: boot- index: live-admin-%{yyyy.MM}when.contains:tags: livesetup.template.settings:index.number_of_shards: 3index.number_of_replicas: 0日志输入源
使用 filebeat.inputs 部分定义了两个日志输入源。每个输入源监视不同路径下的日志文件并根据路径指定的类型和字段进行处理。其中第一个输入源监视 /var/log/.log 路径下的日志文件用于收集 Spring Boot Admin 应用的日志第二个输入源监视 /java/.log 路径下的日志文件用于收集 Live Admin 应用的日志。
日志标签
在每个输入源的 tags 配置中使用了一组自定义的标签。这些标签通常用于标识日志的来源或类型。在这个配置中每个输入源都定义了自己的标签以便后续根据标签将日志发送到不同的索引中。
Elasticsearch 输出
在 output.elasticsearch 部分指定了 Elasticsearch 的地址和认证信息并配置了索引的模板。根据不同的标签将日志发送到不同的索引中。在这个配置中根据标签 “boot” 将 Spring Boot Admin 的日志发送到名为 spring-boot-admin-%{yyyy.MM} 的索引中根据标签 “live” 将 Live Admin 的日志发送到名为 live-admin-%{yyyy.MM} 的索引中。
Elasticsearch 索引设置
在 setup.template.settings 部分配置了 Elasticsearch 索引的一些设置包括分片数和副本数。这些设置可以优化 Elasticsearch 索引的性能和可用性。
删除之前的容器
docker rm -f filebeat再重启启动
docker run --namefilebeat --restartalways \-v /data/elk7/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml \
-v /var/log/springboot/:/var/log/springboot/ \
-v /data/log/live-admin/logs/:/var/log/live-admin/logs/ \
-d elastic/filebeat:7.5.1排查问题命令
docker logs filebeat进入容器
docker exec -it filebeat /bin/bashdocker exec -it filebeat /bin/shnginx的日志采集
如果要采集nginx的日志的话需要设置nginx日志格式
#修改nginx.conf在http 、https中设置日志格式
#添加 log_format main
user nginx;
worker_processes auto;error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;worker_rlimit_nofile 10240;
events {worker_connections 10240;
}http {include /etc/nginx/mime.types;default_type application/octet-stream;server_tokens off;proxy_hide_header X-Powered-By;proxy_hide_header Server;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;proxy_connect_timeout 30000;keepalive_timeout 30000;client_max_body_size 100m;client_header_buffer_size 512k;large_client_header_buffers 4 512k;#gzip on;include /etc/nginx/conf.d/*.conf;
}
在**filebeat.inputs:**新增一个log
- type: logenabled: truepaths:- /var/log/nginx/access.logfields:AppId: nginxENV: DEVfields_under_root: truetags: [ip,nginx]json.keys_under_root: true在**indices:**下新增一个index - index: nginx-%{yyyy.MM}when.contains:tags: nginx设置命令行中执行 Nginx 相关的命令时不输入完整路径
export PATH/usr/sbin:/usr/local/nginx/sbin:$PATH/usr/sbin 目录通常包含系统管理和维护的命令例如一些系统管理工具和服务程序的启动脚本等。/usr/local/nginx/sbin 目录包含了 Nginx 服务器的可执行文件包括启动 Nginx 的命令 nginx。
通过将这两个目录添加到 PATH 中可以方便地在命令行中直接执行 nginx 命令来启动或管理 Nginx 服务器而不必输入完整的路径。
再次删除容器重新启动把nginx日志也挂在上去
docker run --namefilebeat --restartalways \
-v /data/elk7/filebeat/filebeat.yml:/usr/share/filebeat/filebeat.yml \
-v /var/log/springboot/:/var/log/springboot/ \
-v /data/log/live-admin/logs/:/var/log/live-admin/logs/ \
-v /var/log/nginx/:/var/log/nginx/ \
-d elastic/filebeat:7.5.1