分类 linux 下的文章

  1. 创建 systemd 服务文件

    首先,创建一个新的 systemd 服务文件:

    sudo nano /etc/systemd/system/syncthing.service
  2. 添加以下内容到服务文件

    [Unit]
    Description=Syncthing - Open Source Continuous File Synchronization
    Documentation=https://docs.syncthing.net/
    After=network.target
    
    [Service]
    User=your_username
    ExecStart=/opt/syncthing/syncthing -no-browser
    Restart=on-failure
    RestartSec=5
    
    [Install]
    WantedBy=multi-user.target

    请将 your_username 替换为实际的用户名。

  3. 重新加载 systemd 配置

    sudo systemctl daemon-reload
  4. 启用并启动 Syncthing 服务

    sudo systemctl enable syncthing
    sudo systemctl start syncthing

检查 Syncthing 状态

使用以下命令来检查 Syncthing 是否正在运行:

systemctl status syncthing

或者,如果你使用了 init.d

sudo service syncthing status

清华大学镜像站:

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ buster/updates main contrib non-free

中科大镜像站:

deb https://mirrors.ustc.edu.cn/debian/ buster main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirrors.ustc.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirrors.ustc.edu.cn/debian-security/ buster/updates main contrib non-free

阿里云镜像站:

deb http://mirrors.aliyun.com/debian/ buster main contrib non-free
deb http://mirrors.aliyun.com/debian-security buster/updates main
deb http://mirrors.aliyun.com/debian/ buster-updates main contrib non-free
deb http://mirrors.aliyun.com/debian/ buster-backports main contrib non-free

上海交大镜像站:

deb https://mirror.sjtu.edu.cn/debian/ buster main contrib non-free
deb https://mirror.sjtu.edu.cn/debian/ buster-updates main contrib non-free
deb https://mirror.sjtu.edu.cn/debian/ buster-backports main contrib non-free
deb https://mirror.sjtu.edu.cn/debian-security/ buster/updates main contrib non-free

问题:

The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0E98404D386FA1D9 NO_PUBKEY 6ED0E7B82643E131 NO_PUBKEY F8D2585B8783D481

解决方法:手动导入公钥

  1. 获取并导入公钥: 你可以使用 apt-key 命令手动导入缺少的公钥。

    下面是获取并导入缺少公钥的命令:

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0E98404D386FA1D9
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 6ED0E7B82643E131
    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F8D2585B8783D481
  2. 更新包列表: 导入公钥后,更新包列表:

    sudo apt-get update

b站24小时不间断直播

安装ffmpeg

apt-get install ffmpeg -y

sh脚本

#!/bin/bash

# 视频文件夹路径
video_folder="/xxx"

# 获取视频文件列表
video_files=("$video_folder"/*.mp4)
num_videos=${#video_files[@]}
current_video_index=0

while true; do
    # 获取当前视频文件路径
    current_video="${video_files[$current_video_index]}"

    # 获取视频时长(单位:秒)
    video_duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$current_video")

    # 推流当前视频到Bilibili直播
    ffmpeg -re -i "$current_video" -c:v libx264 -preset veryfast -b:v 1000k -maxrate 1000k -bufsize 2000k -pix_fmt yuv420p -g 60 -c:a aac -b:a 96k -ac 2 -ar 44100 -f flv "rtmp://your_bilibili_push_url" &

    # 获取推流进程的PID
    ffmpeg_pid=$!

    # 等待视频推流结束
    sleep "$video_duration"

    # 终止推流进程
    kill $ffmpeg_pid

    # 自动播放下一个视频
    current_video_index=$(( (current_video_index + 1) % num_videos ))

    # 可选:在每次推流后等待一段时间,以便给服务器一些休息时间
    sleep 5
done

使用软链接来修改docker的默认存储位置

默认情况下Docker的存放位置为:/var/lib/docker

可以通过下面命令查看具体位置:

sudo docker info | grep "Docker Root Dir"

首先停掉Docker服务:

systemctl stop docker #或者service docker stop

然后移动整个/var/lib/docker目录到目的路径:

mv /var/lib/docker  /home/work/docker_root

ln -s /home/work/docker_root  /var/lib/docker

这时候启动Docker时发现存储目录依旧是/var/lib/docker,但是实际上是存储在数据盘。