标签: Linux

  • 使用 GoAccess 分析 Web 日志

    GoAccess 是一款轻量级、快速的 Web 日志分析工具,支持终端交互式查看和 HTML 报表生成。

    1. 安装 GoAccess

    1.1 安装 GoAccess

    apt install -y goaccess

    1.2 验证安装是否成功

    goaccess --version

    如果安装成功,你会看到类似 GoAccess - 1.x.x 的输出。

    2. 运行 GoAccess 进行日志分析

    2.1 在终端查看日志统计

    goaccess /var/log/nginx/access.log --log-format=COMBINED

    终端界面显示的内容包括:

    • 此命令将在终端中显示详细的日志统计信息,包括访客 IP、页面访问量、HTTP 状态码等。
    • 使用 Tab 键可以在不同的统计视图之间切换。

    3. 生成 HTML 报表

    goaccess /var/log/nginx/access.log --log-format=COMBINED -o /var/www/html/report.html
    • 此命令将生成一个静态的 HTML 报告,方便在浏览器中查看。

    3.1 让 GoAccess 实时更新 HTML 报表

    goaccess /var/log/nginx/access.log --log-format=COMBINED -o /var/www/html/report.html --real-time-html
    • 添加 --real-time-html 参数,使报告能够自动刷新,实时显示最新的日志分析结果。

    4. 其他日志格式支持

    4.1 解析 JSON 日志格式

    goaccess /var/log/nginx/access.log --log-format=JSON
    • 直接解析 JSON 格式的日志。

    4.2 解析自定义日志格式

    如果 Nginx 日志格式是:

    192.168.1.1 - - [19/Mar/2025:14:30:00 +0000] "GET /index.html HTTP/1.1" 200 512 "-" "Mozilla/5.0"

    使用:

    goaccess /var/log/nginx/access.log --log-format='%h %^ %^ [%d:%t %^] "%r" %s %b "%R" "%u"' --date-format='%d/%b/%Y' --time-format='%H:%M:%S'
    • 使用 --log-format--date-format--time-format 参数,可以解析自定义的日志格式。
  • 使用 SSH 端口转发访问 Docker Hub 拉取镜像

    1. 原理解析

    SSH 端口转发(Port Forwarding)是一种将本地端口流量通过 SSH 连接重定向到远程服务器的方式。在本方案中,我们将本地端口映射到 Docker Hub 服务器(registry-1.docker.io),让本地 Docker 以为它正在直接访问 Docker Hub。

    示意图:

    [本地 Docker 客户端] → [SSH 隧道] → [远程服务器] → [Docker Hub]

    这样,本地 Docker 发送的请求会通过 SSH 隧道访问 Docker Hub 并返回数据。


    2. 使用条件

    • 一台可访问 Docker Hub 的服务器
    • 服务器上安装了 SSH
    • 本地设备(Windows/Linux/macOS)可通过 SSH 连接到服务器

    3. 配置 SSH 端口转发

    3.1 在本地终端运行 SSH 端口转发

    ssh -N -L 5000:registry-1.docker.io:443 user@your-server-ip
    • -N:不执行远程命令,仅进行端口转发
    • -L 5000:registry-1.docker.io:443:将本地 5000 端口映射到远程 registry-1.docker.io443 端口
    • user@your-server-ip:远程服务器的 SSH 账户

    保持这个 SSH 连接不关闭,否则端口转发会失效。


    4. 配置 Docker 访问代理

    4.1 在 daemon.json 中修改 Docker 配置

    编辑 Docker 的配置文件:

    nano /etc/docker/daemon.json

    添加以下内容:

    {
      "proxies": {
        "default": "http://127.0.0.1:5000"
      }
    }

    保存后,重启 Docker

    systemctl restart docker

    5. 测试 Docker 是否可以正常拉取

    执行拉取测试:

    docker pull ubuntu

    如果拉取成功,说明 SSH 端口转发生效。

  • Debian12 安装Dify大语言模型(LLM) 应用开发平台

    Dify 是一款开源的大语言模型(LLM)应用开发平台。它融合了后端即服务(Backend as Service)和 LLMOps 的理念,使开发者可以快速搭建生产级的生成式 AI 应用。即使你是非技术人员,也能参与到 AI 应用的定义和数据运营过程中。

    Dify 内置了构建 LLM 应用所需的关键技术栈,包括对数百个模型的支持、直观的 Prompt 编排界面、高质量的 RAG 引擎、稳健的 Agent 框架、灵活的流程编排,并同时提供了一套易用的界面和 API。这为开发者节省了许多重复造轮子的时间,使其可以专注在创新和业务需求上。

    1. 安装 Docker 和 Docker Compose

    在服务器上运行以下命令安装 Docker:

    curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh

    2. 安装 Dify

    2.1 克隆 Dify 源代码至本地环境

    git clone https://github.com/langgenius/dify.git --branch 1.0.1

    2.2 启动 Dify

    进入 Dify 源代码的 Docker 目录,并执行以下步骤:

    # 进入 Dify 源代码的 Docker 目录
    cd dify/docker
    
    # 复制环境配置文件
    cp .env.example .env
    
    # 启动 Docker 容器
    docker compose up -d
    
    # 最后检查是否所有容器都正常运行
    docker compose ps

    2.3 访问 Dify 进行安装

    在浏览器中访问以下地址,完成安装流程:

    http://your_server_ip/install

    3. 在 Dify 中接入模型

    在 Dify 控制面板中,进入 设置 > 模型供应商,然后点击 接入模型
    按照界面指引,输入模型供应商相关 API 信息,并完成模型的接入配置。

  • Debian12安装Umami 网站分析工具

    Umami是一款轻量级、开源的 网站分析工具,可用于 隐私友好型 统计,不依赖于 Google Analytics,支持 自托管,且对 GDPR / CCPA 友好

    1. 安装 Docker 和 Docker Compose

    在服务器上运行以下命令安装 Docker:

    curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh

    2. 配置 Umami

    在 服务器上创建目录 umami 并进入该目录:

    mkdir -p ./umami && cd ./umami

    创建 docker-compose.yml 文件:

    nano docker-compose.yml

    文件内容

    services:
      umami:
        image: ghcr.io/umami-software/umami:postgresql-latest
        ports:
          - "3002:3000"
        environment:
          DATABASE_URL: postgresql://umami:umami@db:5432/umami
          DATABASE_TYPE: postgresql
          APP_SECRET: replace-me-with-a-random-string
        depends_on:
          db:
            condition: service_healthy
        init: true
        restart: always
        healthcheck:
          test: ["CMD-SHELL", "curl http://localhost:3000/api/heartbeat"]
          interval: 5s
          timeout: 5s
          retries: 5
      db:
        image: postgres:15-alpine
        environment:
          POSTGRES_DB: umami
          POSTGRES_USER: umami
          POSTGRES_PASSWORD: umami
        volumes:
          - umami-db-data:/var/lib/postgresql/data
        restart: always
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
          interval: 5s
          timeout: 5s
          retries: 5
    volumes:
      umami-db-data:

    3. 启动 Umami

    # 启动
    docker compose up -d
    
    # 查看运行状态
    docker compose ps

    4. 访问 Umami

    默认账号:admin
    默认密码:umami
    
    http://<服务器IP>:3002
  • Debian12安装 Immich 进行自托管照片和视频

    Immich 是一个强大的自托管照片和视频管理解决方案,允许用户在自己的服务器上存储、管理和浏览照片,同时提供智能搜索、面部识别等 AI 功能,保护您的隐私。

    1. 介绍 Immich

    Immich 的主要功能

    • 自动备份:支持手机和桌面端自动同步照片和视频。
    • 智能搜索:基于 AI 的搜索和标签功能,快速查找照片。
    • 面部识别:自动识别照片中的人物并进行分类。
    • 隐私保护:完全自托管,确保数据不会泄露到第三方服务器。
    • 高效存储:支持增量备份和重复数据删除,优化存储空间。
    • 跨平台支持:支持 Android、iOS、Web 和桌面端访问。

    2. 安装 Docker 和 Docker Compose

    在 Linux 服务器上运行以下命令安装 Docker:

    curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh

    安装完成后,检查 Docker 版本:

    docker --version

    安装 Docker Compose:

    apt install -y docker-compose

    3. 下载 Immich 并配置环境变量

    3.1 创建 Immich 安装目录

    mkdir ./immich-app && cd ./immich-app

    3.2 下载官方 Docker Compose 文件

    # &nbsp;docker-compose.yml
    wget -O docker-compose.yml https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
    
    # .env
    wget -O .env https://github.com/immich-app/immich/releases/latest/download/example.env

    docker-compose.yml文件

    #
    # WARNING: To install Immich, follow our guide: https://immich.app/docs/install/docker-compose
    #
    # Make sure to use the docker-compose.yml of the current release:
    #
    # https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
    #
    # The compose file on main may not be compatible with the latest release.
    
    name: immich
    
    services:
      immich-server:
        container_name: immich_server
        image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
        # extends:
        #   file: hwaccel.transcoding.yml
        #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
        volumes:
          # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
          - ${UPLOAD_LOCATION}:/usr/src/app/upload
          - /etc/localtime:/etc/localtime:ro
        env_file:
          - .env
        ports:
          - '2283:2283'
        depends_on:
          - redis
          - database
        restart: always
        healthcheck:
          disable: false
    
      immich-machine-learning:
        container_name: immich_machine_learning
        # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
        # Example tag: ${IMMICH_VERSION:-release}-cuda
        image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
        # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration
        #   file: hwaccel.ml.yml
        #   service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable
        volumes:
          - model-cache:/cache
        env_file:
          - .env
        restart: always
        healthcheck:
          disable: false
    
      redis:
        container_name: immich_redis
        image: docker.io/redis:6.2-alpine@sha256:148bb5411c184abd288d9aaed139c98123eeb8824c5d3fce03cf721db58066d8
        healthcheck:
          test: redis-cli ping || exit 1
        restart: always
    
      database:
        container_name: immich_postgres
        image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:739cdd626151ff1f796dc95a6591b55a714f341c737e27f045019ceabf8e8c52
        environment:
          POSTGRES_PASSWORD: ${DB_PASSWORD}
          POSTGRES_USER: ${DB_USERNAME}
          POSTGRES_DB: ${DB_DATABASE_NAME}
          POSTGRES_INITDB_ARGS: '--data-checksums'
        volumes:
          # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
          - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
        healthcheck:
          test: >-
            pg_isready --dbname="$${POSTGRES_DB}" --username="$${POSTGRES_USER}" || exit 1;
            Chksum="$$(psql --dbname="$${POSTGRES_DB}" --username="$${POSTGRES_USER}" --tuples-only --no-align
            --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')";
            echo "checksum failure count is $$Chksum";
            [ "$$Chksum" = '0' ] || exit 1
          interval: 5m
          start_interval: 30s
          start_period: 5m
        command: >-
          postgres
          -c shared_preload_libraries=vectors.so
          -c 'search_path="$$user", public, vectors'
          -c logging_collector=on
          -c max_wal_size=2GB
          -c shared_buffers=512MB
          -c wal_compression=on
        restart: always
    
    volumes:
      model-cache:

    .env文件

    # You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables
    
    # The location where your uploaded files are stored
    UPLOAD_LOCATION=./library
    # The location where your database files are stored
    DB_DATA_LOCATION=./postgres
    
    # To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
    # TZ=Etc/UTC
    
    # The Immich version to use. You can pin this to a specific version like "v1.71.0"
    IMMICH_VERSION=release
    
    # Connection secret for postgres. You should change it to a random password
    # Please use only the characters `A-Za-z0-9`, without special characters or spaces
    DB_PASSWORD=postgres
    
    # The values below this line do not need to be changed
    ###################################################################################
    DB_USERNAME=postgres
    DB_DATABASE_NAME=immich

    3.3 配置环境变量

    编辑 .env 文件:

    nano .env

    修改以下关键参数:

    # You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables
    
    # The location where your uploaded files are stored
    UPLOAD_LOCATION=./library
    # The location where your database files are stored
    DB_DATA_LOCATION=./postgres
    
    # To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
    # TZ=Etc/UTC
    
    # The Immich version to use. You can pin this to a specific version like "v1.71.0"
    IMMICH_VERSION=release
    
    # Connection secret for postgres. You should change it to a random password
    # Please use only the characters `A-Za-z0-9`, without special characters or spaces
    DB_PASSWORD=postgres
    
    # The values below this line do not need to be changed
    ###################################################################################
    DB_USERNAME=postgres
    DB_DATABASE_NAME=immich
    • 指定备份存储位置:
      • 请在UPLOAD_LOCATION中填写您希望存储备份文件的绝对路径。建议选择服务器上具有足够可用空间的新建目录,以确保备份顺利进行。
    • 设置数据库密码:
      • 强烈建议您修改DB_PASSWORD,为其设置一个自定义的强密码。由于PostgreSQL服务仅在本地Docker容器内运行,此密码用于本地身份验证。为避免Docker在解析密码时出现问题,请仅使用A-Za-z0-9范围内的字符。您可以使用pwgen等工具生成安全的随机密码。

    4. 启动 Immich

    运行 Docker Compose 启动 Immich

    docker-compose.yml 所在目录运行:

    docker compose up -d

    5. 访问 Immich Web 界面

    在浏览器中输入:

    http://<服务器IP>:2283

    首次访问时,需要注册一个管理员账户,登录后即可开始使用。

  • 本地部署Gemma3,Ollama与Open WebUI部署教程详解

    Ollama部署Gemma3 模型并使用 Open WebUI 进行 Web 访问

    1. 安装 Ollama

    Ollama 是一个用于运行大型语言模型的工具。

    支持的操作系统

    • Windows
    • Linux
    • macOS

    下载和安装:

    2. 安装 Gemma3 模型

    Ollama 安装完成后,您可以使用以下命令下载并运行 Gemma3 模型。

    文本模型:

    • 1B 参数模型(32k 上下文窗口):
    ollama run gemma3:1b

    多模态模型(视觉):

    • 4B 参数模型(128k 上下文窗口):
    ollama run gemma3:4b
    • 12B 参数模型(128k 上下文窗口):
    ollama run gemma3:12b
    • 27B 参数模型(128k 上下文窗口):
    ollama run gemma3:27b
    • 运行上述命令之一将自动下载并启动相应的 Gemma3 模型。

    3. 安装 Open WebUI

    Open WebUI 提供了一个用户友好的 Web 界面,用于与 Ollama 运行的模型进行交互。

    使用 Conda 安装:

    1.创建 Conda 环境:

    conda create -n open-webui python=3.11
    1. 激活环境:
    conda activate open-webui
    1. 安装 Open WebUI:
    pip install open-webui
    1. 启动服务器:
    open-webui serve

    更新 Open WebUI:

    • 要将 Open WebUI 更新到最新版本,请运行:
    pip install -U open-webui

    4. 配置并启动 Open WebUI 以连接 Ollama

    访问 Open WebUI:

    • 安装完成后,在 Web 浏览器中访问以下地址:
    • http://localhost:8080/

    配置 Ollama 连接:

    • Open WebUI 应该会自动检测到本地运行的 Ollama 实例。
    • 如果需要手动配置,请在 Open WebUI 的设置中查找 Ollama 连接选项。
    • 确保 Open WebUI 已正确配置为使用您已安装的 Gemma3 模型。

    开始使用:

    • 现在,您可以使用 Open WebUI 的界面与 Gemma3 模型进行交互。您可以输入文本提示,并根据所选模型(文本或多模态)获得相应的响应。