VictoriaLogs Docker Deployment
Prerequisites
If you have not rotated MongoDB logs yet, please first read MongoDB Log Rotation. The Docker version already includes Grafana and the slow query dashboard, so it can be used directly after deployment.
Prerequisites
dockeris installed.docker-composeis installed.
Deploy VictoriaLogs + Grafana
-
Download the image
- Servers with Internet Access
- Servers without Internet Access
docker pull registry.cn-hangzhou.aliyuncs.com/hap-mdy/hap-monitor-victorialogs-grafana-amd64:1.0.0# Download the offline image package, then upload it to the deployment serverhttps://pdpublic.mingdao.com/private-deployment/offline/common/hap-monitor-victorialogs-grafana-amd64-1.0.0.tar.gz# Load the offline image on the server with docker load -idocker load -i hap-monitor-victorialogs-grafana-amd64-1.0.0.tar.gz -
Create the configuration and data directories
mkdir -p /usr/local/victoria-logs-linuxmkdir -p /data/victorialogsmkdir -p /data/grafana -
Create the configuration file
cat > /usr/local/victoria-logs-linux/hap-monitor-logs.yaml << 'EOF'services:hap-monitor-logs:image: registry.cn-hangzhou.aliyuncs.com/hap-mdy/hap-monitor-victorialogs-grafana-amd64:1.0.0container_name: hap-monitor-logsrestart: alwaysports:# VictoriaLogs HTTP API- "9428:9428"# Grafana Web UI- "3000:3000"volumes:# VictoriaLogs data directory- /data/victorialogs:/data/victorialogs# Grafana data directory- /data/grafana:/usr/local/grafana/dataenvironment:# Time zoneTZ: Asia/Shanghai# Go Runtime heap limit, recommended to keep <= mem_limitGOMEMLIMIT: 2GiB###################################################################### VictoriaLogs###################################################################### Data directoryVL_STORAGE_DATA_PATH: /data/victorialogs# HTTP listen addressVL_HTTP_LISTEN_ADDR: ":9428"# Basic AuthVL_HTTP_AUTH_USERNAME: myuserVL_HTTP_AUTH_PASSWORD: mypassword# Data retention periodVL_RETENTION_PERIOD: 30d# Maximum disk usageVL_RETENTION_DISK_USAGE: 50GiB# Internal cache percentageVL_MEMORY_ALLOWED_PERCENT: "2"# Write concurrencyVL_MAX_CONCURRENT_INSERTS: "4"# Query concurrencyVL_MAX_CONCURRENT_REQUESTS: "2"# Query timeoutVL_SEARCH_MAX_QUERY_DURATION: 30s# Maximum query time rangeVL_SEARCH_MAX_QUERY_TIMERANGE: 24h# Query queue timeoutVL_SEARCH_MAX_QUEUE_DURATION: 5s# Slow query log thresholdVL_SEARCH_LOG_SLOW_QUERY_DURATION: 3s# Maximum line sizeVL_INSERT_MAX_LINE_SIZE_BYTES: "262144"# Maximum number of fields per lineVL_INSERT_MAX_FIELDS_PER_LINE: "300"# syslog extra fieldsVL_SYSLOG_EXTRA_FIELDS_TCP: '{"job":"rsyslog"}'# Log levelVL_LOGGER_LEVEL: INFO###################################################################### Grafana###################################################################### Grafana sub-pathGRAFANA_SERVER_ROOT_URL: "%(protocol)s://%(domain)s:%(http_port)s/privatedeploy/mdy/monitor/victorialogs-grafana/"# Enable serve from sub-path modeGRAFANA_SERVER_SERVE_FROM_SUB_PATH: "true"# Grafana default admin accountGRAFANA_ADMIN_USER: admin# Grafana default admin passwordGRAFANA_ADMIN_PASSWORD: admin@123456# Allow loading unsigned pluginsGRAFANA_ALLOW_UNSIGNED_PLUGINS: victoriametrics-logs-datasource###################################################################### VictoriaLogs Grafana Datasource###################################################################### VictoriaLogs addressGRAFANA_VL_DATASOURCE_URL: http://127.0.0.1:9428# VictoriaLogs Basic Auth usernameGRAFANA_VL_BASIC_AUTH_USER: myuser# VictoriaLogs Basic Auth passwordGRAFANA_VL_BASIC_AUTH_PASSWORD: mypasswordmem_limit: 3gmemswap_limit: 3gcpus: 2.0ulimits:nofile:soft: 102400hard: 102400logging:driver: json-fileoptions:# Single log file sizemax-size: "100m"# Number of retained log filesmax-file: "3"EOFVariable notes:
VL_HTTP_AUTH_USERNAMEandVL_HTTP_AUTH_PASSWORDare used for VictoriaLogs Basic Auth. It is recommended to replace them with a more complex username and password according to your local standards instead of using the example values directly.VL_RETENTION_PERIODis used to set the log retention period. For example,30dmeans logs are retained for 30 days.VL_RETENTION_DISK_USAGEis used to set the disk usage upper limit for VictoriaLogs. For example,50GiBmeans VictoriaLogs can use up to 50 GiB of disk space.- If the log volume is large, it is recommended to tune these two parameters together to prevent disk growth from getting out of control.
GRAFANA_VL_DATASOURCE_URLis used to specify the VictoriaLogs address that Grafana connects to. If VictoriaLogs is not running on the same host, change it to an actually reachable address.GRAFANA_VL_BASIC_AUTH_USERandGRAFANA_VL_BASIC_AUTH_PASSWORDare used for Grafana's Basic Auth access to VictoriaLogs, and must match the VictoriaLogs authentication credentials.
-
Start and stop the service
# Startdocker-compose -f /usr/local/victoria-logs-linux/hap-monitor-logs.yaml up -d# Stopdocker-compose -f /usr/local/victoria-logs-linux/hap-monitor-logs.yaml down
Deploy the Log Collector Promtail
Promtail must be deployed on every MongoDB node. It reads the local mongodb.log file directly and pushes the slow query logs to VictoriaLogs.
Notes:
PROMTAIL_PUSH_URLmust be changed to the actual VictoriaLogs address.PROMTAIL_USERNAMEandPROMTAIL_PASSWORDmust be changed to the real VictoriaLogs authentication credentials.PROMTAIL_JOB_NAMEmust remain unique on each MongoDB node so that log sources can be distinguished.PROMTAIL_LOG_PATHmust be changed to the absolute path of the MongoDB log file on the current node.- If the log path differs between MongoDB nodes, adjust the corresponding configuration on each node separately.
-
Download the image
- Servers with Internet Access
- Servers without Internet Access
docker pull registry.cn-hangzhou.aliyuncs.com/hap-mdy/hap-promtail-vlogs-mongodb-amd64:1.0.0# Download the offline image package, then upload it to the deployment serverhttps://pdpublic.mingdao.com/private-deployment/offline/common/hap-promtail-vlogs-mongodb-amd64-1.0.0.tar.gz# Load the offline image on the server with docker load -idocker load -i hap-promtail-vlogs-mongodb-amd64-1.0.0.tar.gz -
Create the configuration and data directories
mkdir -p /usr/local/promtail-vlogsmkdir -p /usr/local/promtail-vlogs/promtail-data -
Create the configuration file
cat > /usr/local/promtail-vlogs/promtail-vlogs-mongodb.yaml << 'EOF'services:promtail-vlogs-mongodb:image: registry.cn-hangzhou.aliyuncs.com/hap-mdy/hap-promtail-vlogs-mongodb-amd64:1.0.0container_name: promtail-vlogs-mongodbrestart: alwaysnetwork_mode: hostenvironment:PROMTAIL_PUSH_URL: http://172.17.30.241:9428/insert/loki/api/v1/pushPROMTAIL_USERNAME: myuserPROMTAIL_PASSWORD: mypasswordPROMTAIL_JOB_NAME: mongodb-01PROMTAIL_LOG_PATH: /data/logs/mongodb/mongodb.logvolumes:- /data/logs/mongodb/mongodb.log:/data/logs/mongodb/mongodb.log:ro- ./promtail-data:/data/promtaildeploy:resources:limits:cpus: '1'memory: 1GEOFcat > /usr/local/promtail-vlogs/promtail-data/positions.yaml << 'EOF'positions: {}EOF -
Start and stop the service
# Startdocker-compose -f /usr/local/promtail-vlogs/promtail-vlogs-mongodb.yaml up -d# Stopdocker-compose -f /usr/local/promtail-vlogs/promtail-vlogs-mongodb.yaml down
Reverse Proxy Configuration for Grafana
upstream grafana {
server 192.168.1.10:3000;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name hap.domain.com;
access_log /data/logs/weblogs/grafana.log main;
error_log /data/logs/weblogs/grafana.mingdao.net.error.log;
location /privatedeploy/mdy/monitor/victorialogs-grafana/ {
#allow 1.1.1.1;
#deny all;
proxy_hide_header X-Frame-Options;
proxy_set_header X-Frame-Options ALLOWALL;
proxy_set_header Host $http_host;
proxy_pass http://grafana;
proxy_redirect http://localhost:3000 http://hap.domain.com:80/privatedeploy/mdy/monitor/victorialogs-grafana;
}
location /privatedeploy/mdy/monitor/victorialogs-grafana/api/live {
rewrite ^/(.*) /$1 break;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_pass http://grafana;
}
}
After the reverse proxy is configured, you can access the Grafana page with the following URL:
http://hap.domain.com/privatedeploy/mdy/monitor/victorialogs-grafana
Combined Deployment Reference
- VictoriaLogs and Grafana are already deployed in the same Docker bundle, so Grafana does not need to be installed separately.
- Promtail must be deployed on every MongoDB node so that each node can collect its own local logs.
- If the MongoDB log directory differs between nodes, modify
PROMTAIL_LOG_PATHon the corresponding node accordingly.
Access Notes
- VictoriaLogs listens on port
9428by default. - Grafana listens on port
3000by default and is exposed externally through a reverse proxy sub-path. - If you need to integrate with an existing Nginx or gateway, make sure the sub-path matches
GRAFANA_SERVER_ROOT_URL.