From 80fa2ea863d12e1043bb5ac9dba2b047dac5cbac Mon Sep 17 00:00:00 2001 From: websoft9 Date: Mon, 29 Dec 2025 09:13:12 +0000 Subject: [PATCH] Update fluentbit --- apps/fluentbit/.env | 56 +++---------------- apps/fluentbit/Notes.md | 40 +++++++++++++- apps/fluentbit/docker-compose.yml | 51 +++++------------- apps/fluentbit/src/fluent-bit.conf | 20 +++++++ apps/fluentbit/src/nginx-proxy.conf.template | 57 -------------------- apps/fluentbit/src/php_exra.ini | 8 --- 6 files changed, 78 insertions(+), 154 deletions(-) create mode 100644 apps/fluentbit/src/fluent-bit.conf delete mode 100644 apps/fluentbit/src/nginx-proxy.conf.template delete mode 100644 apps/fluentbit/src/php_exra.ini diff --git a/apps/fluentbit/.env b/apps/fluentbit/.env index e1a4e711f..df27255f7 100644 --- a/apps/fluentbit/.env +++ b/apps/fluentbit/.env @@ -1,53 +1,13 @@ -W9_REPO="wordpress" -W9_DIST=community -W9_VERSION="latest" - -W9_POWER_PASSWORD="1PrMxExC45LsCT" - -# Environments which for user settings when create application -# Named expression: W9_xxx_xxx_SET, xxx refer to file fields -W9_HTTP_PORT_SET=9001 -# W9_HTTPS_PORT_SET=9002 -# W9_DB_PORT_SET=3306 -# W9_SSH_PORT_SET=23 -W9_KEY_SET="dfsjdkjf77xjxcjcj" +W9_REPO="fluent/fluent-bit" +W9_DIST='community' +W9_VERSION='4.2' +W9_HTTP_PORT_SET='9001' #### -- Not allowed to edit below environments when recreate app based on existing data -- #### +W9_ID='fluentbit' +W9_HTTP_PORT=24224 -W9_ID=fluentbit - -# W9_HTTP_PORT or W9_HTTPS_PORT is need at leaset and used for proxy for web application -# Some container (e.g teleport) need HTTPS access, then need to set this pra -W9_HTTP_PORT=80 -W9_HTTPS_PORT=81 - -W9_LOGIN_USER=admin -# use https://1password.com/zh-cn/password-generator/ to genarate 14 bit password -# this password can also use password file -W9_LOGIN_PASSWORD=$W9_POWER_PASSWORD -W9_ADMIN_PATH="/wp-login" - -# Container name's suffix must use one of the value -W9_DB_EXPOSE="mysql,postgresql,mariadb,mongodb,redis" - -# It is used when the application APP needs to set an external URL, which can be IP(or domain), IP:PORT -# If have protocols, should be set it in the APP's ENV -W9_URL=internet_ip:$W9_HTTP_PORT_SET -# modifies W9_URL on init when it is true -W9_URL_REPLACE=true +#W9_URL=app.example.com W9_NETWORK=websoft9 - -#### ----------------------------------------------------------------------------------------- #### - - -# Below environment is created by this app - -WORDPRESS_DB_HOST=$W9_ID-mariadb -WORDPRESS_DB_USER=wordpress #if use postgresql, it need set to postgres -WORDPRESS_DB_PASSWORD=$W9_POWER_PASSWORD -WORDPRESS_DB_NAME=wordpress - - -#W9_NAME="" -#W9_RCODE="" \ No newline at end of file +W9_URL='internet_ip:$W9_HTTP_PORT_SET' diff --git a/apps/fluentbit/Notes.md b/apps/fluentbit/Notes.md index 1fdbbb29d..6b3a4ce2a 100644 --- a/apps/fluentbit/Notes.md +++ b/apps/fluentbit/Notes.md @@ -1,2 +1,38 @@ -# Appname -## FAQ +# Fluent-Bit + +## 日志收集 + +### 示例:收集wordpress的日志 +1. 在wordpress容器编排文件中修改日志引擎为fluentd + ``` + logging: + driver: fluentd + options: + fluentd-address: 47.83.26.60:9001 # url+暴露的端口 (由于Portainer Stack模式只能通过overlay网络相互解析服务名,默认的websoft9是桥接网络,所以不能用服务名加端口查找) + tag: "wordpress.app" # 标签,用于区分不同的日志 + ``` +2. 编辑fluent-bit.conf + ``` + [SERVICE] + Flush 1 + Log_Level info + + [INPUT] + Name forward + Port 24224 + Listen 0.0.0.0 + + [OUTPUT] + Name file + Match wordpress.app # 匹配标签 + Path /var/log/fluentbit # 日志输出路径(已在编排文件中将该目录映射到外部) + File wordpress.log # 日志文件名(如果不加这一项,则默认按照标签名创建文件) + Mkdir On # 如果目录不存在,则创建 + Format plain + + [OUTPUT] + Name stdout + Match * + ``` + +官方文档:https://docs.fluentbit.io/manual/ \ No newline at end of file diff --git a/apps/fluentbit/docker-compose.yml b/apps/fluentbit/docker-compose.yml index 1c1948688..163a6b2df 100644 --- a/apps/fluentbit/docker-compose.yml +++ b/apps/fluentbit/docker-compose.yml @@ -1,49 +1,22 @@ -# image,docs: https://hub.docker.com/_/wordpress/ +# image: https://hub.docker.com/r/fluent/fluent-bit +# docs: https://docs.fluentbit.io/manual -services: - wordpress: - image: $W9_REPO:$W9_VERSION - container_name: $W9_ID - restart: unless-stopped - #This is for access host from container - # extra_hosts: ["host.docker.internal:host-gateway"] - # command: | - # /bin/bash -c "ping -c 3 host.docker.internal" - logging: - driver: "json-file" - options: - max-file: "5" - max-size: 10m - deploy: - resources: - limits: - memory: 5g - cpus: '0.7' - ports: - - $W9_HTTP_PORT_SET:80 +services: + fluent-bit: + image: ${W9_REPO}:${W9_VERSION} + container_name: ${W9_ID} env_file: .env + ports: + - ${W9_HTTP_PORT_SET}:24224 volumes: - - wordpress:/var/www/html - - ./src/php_exra.ini:/usr/local/etc/php/conf.d/php_exra.ini - - mariadb: - image: mariadb:10.4 - container_name: $W9_ID-mariadb + - ./src/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf:ro + - logs:/var/log/fluentbit restart: unless-stopped - command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --innodb_log_buffer_size=30M - volumes: - - mysql_data:/var/lib/mysql - environment: - MYSQL_DATABASE: $WORDPRESS_DB_NAME - MYSQL_USER: $WORDPRESS_DB_USER - MYSQL_PASSWORD: $W9_POWER_PASSWORD - MYSQL_ROOT_PASSWORD: $W9_POWER_PASSWORD volumes: - wordpress: - mysql_data: - + logs: + networks: default: name: $W9_NETWORK diff --git a/apps/fluentbit/src/fluent-bit.conf b/apps/fluentbit/src/fluent-bit.conf new file mode 100644 index 000000000..8aad0fe90 --- /dev/null +++ b/apps/fluentbit/src/fluent-bit.conf @@ -0,0 +1,20 @@ +[SERVICE] + Flush 1 + Log_Level info + +[INPUT] + Name forward + Port 24224 + Listen 0.0.0.0 + +[OUTPUT] + Name file + Match wordpress.app + Path /var/log/fluentbit + File wordpress.log + Mkdir On + Format plain + +[OUTPUT] + Name stdout + Match * \ No newline at end of file diff --git a/apps/fluentbit/src/nginx-proxy.conf.template b/apps/fluentbit/src/nginx-proxy.conf.template deleted file mode 100644 index 951364ffe..000000000 --- a/apps/fluentbit/src/nginx-proxy.conf.template +++ /dev/null @@ -1,57 +0,0 @@ -proxy_busy_buffers_size 512k; -proxy_buffers 4 512k; -proxy_buffer_size 256k; -client_max_body_size 50m; -# override default location / -location / { - add_header X-Served-By $host; - proxy_set_header Host $host; - proxy_set_header X-Forwarded-Scheme $scheme; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Real-IP $remote_addr; - proxy_pass $forward_scheme://$server:$port$request_uri; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection upgrade; - } - -location /console { - proxy_pass http://$server:8080; - proxy_http_version 1.1; - 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; - proxy_set_header X-Forwarded-Proto $scheme; -} - -# for echo some useful information -location / { - default_type text/plain; - return 200 'Hello World'; -} - -location /oida/ { -# this is the address and port of the ORDS installation -proxy_pass http://127.0.0.1:8080/ords/; - -# set Origin to blank to avoid Chrome problems with CORS -proxy_set_header Origin "" ; - -# pass along some header variables with the public host name/port/and so on -proxy_set_header Host $host; -proxy_set_header X-Forwarded-Host $host:$server_port; -proxy_set_header X-Real-IP $remote_addr; -proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; -proxy_set_header X-Forwarded-Proto $scheme; - -# this reverse proxies any "location" headers being passed in the response -proxy_redirect http://$host/ords/ https://$host/oida/; - -# also tell cookies their public path -proxy_cookie_path /ords/ /oida/; - -# reverse proxy links included in response (ie from ORDS webservice) -sub_filter_types application/json ; -sub_filter http://$host/ords/ https://$host/oida/; -sub_filter_once off; -} diff --git a/apps/fluentbit/src/php_exra.ini b/apps/fluentbit/src/php_exra.ini deleted file mode 100644 index b253d5718..000000000 --- a/apps/fluentbit/src/php_exra.ini +++ /dev/null @@ -1,8 +0,0 @@ -file_uploads = On -max_input_time = 800 -max_execution_time = 300 -memory_limit = 600M -upload_max_filesize = 900M -post_max_size = 900M -max_file_uploads = 200 -error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT \ No newline at end of file