标签: Debian

  • 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

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

  • Debian12为 history 命令添加时间戳显示

    1. 修改 ~/.bashrc 让 history 命令显示时间

    1. 编辑 ~/.bashrc 文件

    在终端执行以下命令,打开 ~/.bashrc 配置文件:

    nano ~/.bashrc
    1. 添加 HISTTIMEFORMAT 变量

    ~/.bashrc 文件末尾添加以下内容:

    # Histroy display time
    export HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S  "

    这行代码的作用:

    • HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S " —— 让 history 以 YYYY-MM-DD HH:MM:SS 的格式显示时间。

    如果你希望存储更多的历史命令,还可以添加:

    # 设置 history 命令记录的条数
    export HISTSIZE=10000
    export HISTFILESIZE=20000
    • HISTSIZE=10000 —— 设置 history 缓存 10,000 条命令(当前会话)。
    • HISTFILESIZE=20000 —— 让 .bash_history 文件最多存储 20,000 条记录。

    2. 使更改生效

    在终端执行以下命令,让 .bashrc 立即生效:

    source ~/.bashrc

    3. 测试

    执行 history 命令,检查是否显示时间:

    history

    如果输出结果前面出现了时间戳,说明已生效:

      1  2025-03-14 11:00:01  ls
      2  2025-03-14 11:05:32  ls

  • Debian 12 上禁用密码登录并配置 SSH 密钥登录

    在 Debian 12 上禁用密码登录并配置 SSH 密钥登录(使用 ed25519)

    1: 生成 SSH 密钥对

    首先,在本地机器上生成一个 ed25519 类型的 SSH 密钥对。打开终端并执行以下命令:

    ssh-keygen -t ed25519 -C "[email protected]"
    • -t ed25519 指定生成 ed25519 密钥。
    • -C 用于添加一个注释,通常使用电子邮件或用户名。

    系统会提示你选择密钥存储的位置:

    Enter file in which to save the key (/home/your_user/.ssh/id_ed25519):

    你可以直接按回车选择默认位置,也可以指定一个不同的文件名。接着会要求输入一个密码来保护私钥(可以选择为空)。

    2: 将公钥复制到 Debian 12 服务器

    将生成的公钥复制到 Debian 12 服务器上。在本地机器上执行以下命令:

    ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your_debian_server_ip
    • ~/.ssh/id_ed25519.pub 是你生成的公钥路径。
    • user@your_debian_server_ip 是你 Debian 12 服务器的用户名和 IP 地址。

    该命令会将公钥复制到目标服务器的 ~/.ssh/authorized_keys 文件中,确保你可以使用私钥登录服务器。

    3: 禁用密码登录

    登录到 Debian 12 服务器(假设你已经能够通过密钥登录),然后修改 SSH 配置文件来禁用密码登录。

    1. 打开 /etc/ssh/sshd_config 配置文件:
    sudo nano /etc/ssh/sshd_config
    1. 查找以下两行并修改或确保它们如下所示:
    PasswordAuthentication no
    ChallengeResponseAuthentication no

    这些设置将禁用密码认证和挑战响应认证。

    1. 确保以下行未被注释掉,并设置为 yes
    PubkeyAuthentication yes
    1. 保存文件并退出编辑器(在 nano 中按 CTRL + X,然后按 Y 保存更改)。

    4: 重新启动 SSH 服务

    修改配置文件后,需要重新启动 SSH 服务以使更改生效:

    sudo systemctl restart sshd

    5: 测试 SSH 密钥登录

    在本地机器上,尝试使用 SSH 密钥登录到服务器:

    ssh -i ~/.ssh/id_ed25519 user@your_debian_server_ip

    如果成功登录且没有要求输入密码,说明密钥认证配置成功。

    6: 确保只有密钥登录

    为了进一步加强安全性,你可以尝试使用 SSH 密码登录进行连接。应该会被拒绝,确保只有密钥能够登录。

  • Debian12 启用BBR算法提升网络性能

    在 Debian 12 上启用 BBR 以优化网络连接

    BBR(Bottleneck Bandwidth and Round-trip propagation time)算法可以显著提升网络性能,特别是在高延迟或丢包环境下。通过启用 BBR,您可以优化带宽利用率,减少延迟,并提高稳定性。

    BBR 的优势:

    • 提升速度: 优化带宽利用率,加快数据传输。
    • 降低延迟: 减少数据包丢失,改善响应速度。
    • 增强稳定性: 适应复杂网络环境,提供更可靠的连接。

    操作步骤:

    1. 配置 BBR

    执行以下命令,将 BBR 配置添加到系统配置文件:

    echo "net.core.default_qdisc=fq" | tee -a /etc/sysctl.conf
    echo "net.ipv4.tcp_congestion_control=bbr" | tee -a /etc/sysctl.conf

    说明:

    • net.core.default_qdisc=fq:设置队列规则为 fq,优化 BBR 性能。
    • net.ipv4.tcp_congestion_control=bbr:启用 BBR 拥塞控制算法。

    2. 重新加载配置

    运行以下命令,使配置立即生效:

    sysctl -p

    3. 验证 BBR 是否生效

    执行以下命令,验证 BBR 是否启用:

    sysctl net.ipv4.tcp_congestion_control

    如果输出为 net.ipv4.tcp_congestion_control = bbr,则表示 BBR 已成功启用。

    您还可以使用以下命令查看系统可用的拥堵算法和当前使用的算法:

    sysctl net.ipv4.tcp_available_congestion_control

    4. 验证 BBR 内核模块

    为了确认 BBR 内核模块是否已加载,可以运行以下命令:

    lsmod | grep bbr

    如果返回 tcp_bbr,则表示 BBR 已成功加载。

  • Debian 12 导出Docker 镜像并导入到没有互联网的 Docker 主机

    在有互联网的主机上:

    1. 列出镜像:

    docker images

    输出可能如下所示:

    REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
    my-app        latest    abcdef123456   2 weeks ago     500MB
    ubuntu        20.04     fedcba987654   3 weeks ago     200MB

    2. 导出 my-app:latest 镜像:

    导出单个镜像

    docker save -o my-app.tar my-app:latest

    导出多个镜像: 如果需要导出多个镜像,可以一次性完成

    docker save -o all-images.tar image1:tag1 image2:tag2 image3:tag3

    在无互联网的主机上:

    1. 将 my-app.tar 复制到 /root 目录。

    2. 导入镜像:

    docker load -i /root/my-app.tar

    3. 验证导入:

    docker images

    应该会看到 my-app:latest 镜像出现在列表中。