机械境

这里只是我的后花园,随性而写

介绍

如果在内网中运行本地 Web 应用程序,可以使用 IP 地址和端口组合来访问服务,例如 http://192.168.1.32:8096 来访问 Jellyfin。但是如果发生 IP 变更的话,就需要修改 IP 地址,因此可以通过反向代理和本地域名的组合,例如 https://jellyfin.localhttps://homeassistant.local 来避免 IP 地址变更。这种由于是使用了自己生产的 CA 证书,浏览器会有告警提示。

准备

假定本地运行 Jellyfin 服务器的 HomeLab IP 为 192.168.1.32,容器名称为 jellyfin,端口为 8096,域名为 jellyfin.example.xyz

域名

自有域名

这里以 Cloudflare 为例

  1. My Profile/API Tokens 页面生成有 Zone.DNS 权限的 API token
  2. 在 DNS 记录中添加一条 A 记录,名称为 jellyfin, 内容为 192.168.1.32,代理状态为 仅 DNS - reserved IP

没有域名

通过 DuckDNS 注册账号,然后添加域名记录,比如 homelab001,IP 地址设为 192.168.1.32,最终的域名为 https://jellyfin.homelab001.duckdns.org

Read more »

前言

Wireguard 有两种模式,一直是内核态,一种是用户态。可以通过 modprobe wireguard 检查内核是否支持 Wireguard。如果该命令成功退出并且没有打印错误,则内核模块可用。如果 wireguard 内核模块不可用,可以切换到像 boringtun 这样的用户态实现。

这里以内核态为例。

准备工作

  1. 安装 Wireguard
    1
    2
    3
    4
    5
    6
    sudo yum install elrepo-release epel-release -y
    sudo yum update -y
    sudo yum install kmod-wireguard wireguard-tools -y
    sudo yum copr enable jdoss/wireguard
    sudo yum update -v
    sudo yum install wireguard-dkms -y
  2. 启用 Wireguard 内核模块
    1
    sudo modprobe wireguard
  3. 自动加载 iptable_raw
    1
    2
    sudo modprobe iptable_raw
    sudo echo "iptable_raw" | sudo tee /etc/modules-load.d/iptable_raw.conf

Read more »

准备工作

  • 注册 chatGPT 账户
  • 注册 Telegram Bot,通过 @BotFather 创建,并获取 token
  • 获取 Telegram Chat ID, 通过 @userinfobot 查询
  • 获取 Access Token
  • 准备反代服务,可以选择别人提供的,不是一定要自己部署

运行

  • 克隆 chatgpt-telegram-bot

  • 准备配置文件 local.json

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    {
    "debug": 1,
    "bot": {
    "token": "telegram bot token",
    "groupIds": [],
    "userIds": [],
    "chatCmd": "/chat"
    },
    "api": {
    "type": "unofficial",
    "unofficial": {
    "accessToken": "chatGPT access token",
    "apiReverseProxyUrl": "https://chat.duti.tech/api/conversation",
    "model": ""
    }
    }
    }
    • userIds 为数字,比如 114797892,可指定多个,如果不指定,就所有人都可用,groupIds 同理,建议配置上
    • accessToken 会有过期时间,暂时没特别好的自动更新的办法,主要是有 cloudflare 验证
  • 修改 docker-compose.yml,并构建镜像

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    version: '3'

    services:
    chatgpt:
    image: chatgpt-telegram-bot
    container_name: chatgpt
    build: .
    restart: unless-stopped
    volumes:
    - ./local.json:/app/config/local.json
    networks:
    - nginx-proxy

    networks:
    nginx-proxy:
    external: true

    docker-compose build 构建镜像

  • 运行
    docker-compose up -d 运行

  • 查看 log
    docker-compose logs -f --tail 100 chatgpt

    如无意外的话,应该会输出类似的日志

    1
    2
    3
    4
    5
    6
    > node --experimental-loader=extensionless dist/index.js

    (node:42) ExperimentalWarning: Custom ESM Loaders is an experimental feature. This feature could change at any time
    (Use `node --trace-warnings ...` to show where the warning was created)
    2/23/2023, 3:06:13 AM 🔮 ChatGPT API has started...
    2/23/2023, 3:06:14 AM 🤖 Bot @xxx_bot has started...
  • 在 Telegram 中添加刚才创建的机器人,通过 /chat 聊天内容 开始,/help 会显示支持的指令

---EOF---

之前介绍了使用 antigensheldon 管理 Zsh 配置,由于 antigen 已经停止维护了,后面就有了 antibody,但是这个也停止维护了,最终就有了继任者 antidote,这几个使用上都大同小异。

  • macOS 使用 brew install antidote 安装,其他平台使用 git clone --depth=1 https://github.com/mattmc3/antidote.git ${ZDOTDIR:-$HOME}/.antidote 安装

  • $HOME 目录添加 .zsh_plugins.txt 来定义需要使用的插件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    # .zsh_plugins.txt

    # comments are supported like this
    https://github.com/peterhurford/up.zsh
    rummik/zsh-tailf
    mattmc3/zman
    agkozak/zsh-z

    # empty lines are skipped

    # annotations are also allowed:
    romkatv/zsh-bench kind:path
    olets/zsh-abbr kind:defer

    # frameworks like oh-my-zsh are supported
    ohmyzsh/ohmyzsh path:lib
    ohmyzsh/ohmyzsh path:plugins/command-not-found
    ohmyzsh/ohmyzsh path:plugins/common-aliases
    ohmyzsh/ohmyzsh path:plugins/gem
    ohmyzsh/ohmyzsh path:plugins/git
    ohmyzsh/ohmyzsh path:plugins/npm
    ohmyzsh/ohmyzsh path:plugins/tmux
    ohmyzsh/ohmyzsh path:plugins/yarn
    ohmyzsh/ohmyzsh path:plugins/fzf

    # prompts:
    # with prompt plugins, remember to add this to your .zshrc:
    # `autoload -Uz promptinit && promptinit && prompt pure`
    # sindresorhus/pure kind:fpath
    # romkatv/powerlevel10k kind:fpath

    # popular fish-like plugins
    zsh-users/zsh-autosuggestions
    zsh-users/zsh-completions path:src kind:fpath
    zdharma-continuum/fast-syntax-highlighting kind:defer
    # zsh-users/zsh-history-substring-search
  • .zshrc 中添加下面的内容,以后修改 .zsh_plugin.txt 中的内容后会自动更新

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # .zshrc
    # Lazy-load antidote and generate the static load file only when needed
    zsh_plugins=${ZDOTDIR:-$HOME}/.zsh_plugins
    if [[ ! ${zsh_plugins}.zsh -nt ${zsh_plugins}.txt ]]; then
    (
    source ${ZDOTDIR:-$HOME}/.antidote/antidote.zsh
    antidote bundle <${zsh_plugins}.txt >${zsh_plugins}.zsh
    )
    fi
    source ${zsh_plugins}.zsh

    # starship
    # eval "$(starship init zsh)"

---EOF---

  • 安装 gpgpinentry
    brew install gpg pinentry-mac

  • 修改 gpg-agent 配置
    echo pinentry-program $(whitch pinentry-mac) >> ~/.gnupg/gpg-agent.conf

  • 通过 gpgconf 检查配置

    1
    2
    3
    4
    5
    6
    7
    gpg:OpenPGP:/opt/homebrew/Cellar/gnupg/2.4.0/bin/gpg
    gpgsm:S/MIME:/opt/homebrew/Cellar/gnupg/2.4.0/bin/gpgsm
    keyboxd:Public Keys:/opt/homebrew/Cellar/gnupg/2.4.0/libexec/keyboxd
    gpg-agent:Private Keys:/opt/homebrew/Cellar/gnupg/2.4.0/bin/gpg-agent
    scdaemon:Smartcards:/opt/homebrew/Cellar/gnupg/2.4.0/libexec/scdaemon
    dirmngr:Network:/opt/homebrew/Cellar/gnupg/2.4.0/bin/dirmngr
    pinentry:Passphrase Entry:/opt/homebrew/opt/pinentry/bin/pinentry
  • 检查 pinentry-mac 是否能正确弹出密码界面
    echo GETPIN | pinentry-mac

  • 修改 git 签名配置

    1
    2
    3
    git config --global user.signingkey F0406D8A
    git config --global commit.gpgsign true
    git config --global gpg.program $(which gpg)
  • 测试签名是否正确
    echo "test" | gpg --clearsign

    输出结果:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    gpg: using "F0406D8A525890198021BB243D8D256084332679" as default secret key for signing
    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA512

    test
    -----BEGIN PGP SIGNATURE-----

    iQEzBAEBCgAdFiEE8EBtilJYkBmAIbskPY0lYIQzJnkFAmPsoRUACgkQPY0lYIQz
    JnkqTQf8DSIYBfaB6ijhO3U7K4FYvCjeMACV3UbuRJI6WxEyDkn4Iglaw/Y4C/s5
    U12ba4PIGLmzqRSkISFbIj+5eKH97CQoB/kVlfQWL+wkYCpTWNAIPEBa7FGU4BYN
    9dSW/00XEdrWz9Lvzb0QAP2t9a8DIPIhyDGpQoxfq+0enZuFJKMRtKPzDKkpaylG
    MTEYEwV5VnyYNsIu8K37h27oPWKPSadT3SGM+m4vFP68V9Thw0/qZFJS8NW7OW8b
    RwB5FVSIsORypAtN0AtzzTd8cxEq6Rf9rPkYgtfeGGrCzZdyfKsPe/AoWEP5/ZuY
    FzQGzjxomBPHLDt7k89Aq5mwK2NAKw==
    =73Fx
    -----END PGP SIGNATURE-----
  • 诊断问题

    1
    2
    3
    4
    5
    # Kill gpg-agent
    killall gpg-agent

    # Run gpg-agent in daemon mode
    gpg-agent --daemon

---EOF---

通过 WATCHTOWER_NOTIFICATION_URL 定义 Telegram 的通知信息,当然了也可以定义其他的通知方式。底层是通过 shoutrrr 实现的,只要 shoutrrr 支持的方式这里都可以用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
version: '3.5'
services:
watchtower:
image: containrrr/watchtower
container_name: watchtower
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
- TZ=Asia/Shanghai
- WATCHTOWER_LIFECYCLE_HOOKS=True
- WATCHTOWER_NOTIFICATIONS=shoutrrr
- WATCHTOWER_NOTIFICATION_URL=telegram://token@telegram?chats=@channel-1,chat-id-1
- WATCHTOWER_DEBUG=true
- WATCHTOWER_CLEANUP=true
# - WATCHTOWER_SCHEDULE=0 0 20 * * 0
- WATCHTOWER_POLL_INTERVAL=43200
command: reference filebrowser
  • 通过 @BotFather 创建自己的通知机器人,并获取 token
  • 通过 @RawDataBot 获取 Chat ID

---EOF---

原始问题,一言以蔽之就是在 daemon.json 增加 Host 之后,服务会启动失败。

解决方案:

  • /etc/systemd/system/docker.service.d/simple_dockerd.conf 中增加
    1
    2
    3
    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd
  • /etc/docker/daemon.json 中增加
    1
    {"hosts": ["tcp://0.0.0.0:2375", "unix:///var/run/docker.sock"]}
  • 重启 docker 服务
    1
    2
    systemctl daemon-reload && 
    systemctl restart docker.service
  • 检查 docker 服务状态
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    ❯ systemctl status docker.service
    ● docker.service - Docker Application Container Engine
    Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/docker.service.d
    └─simple_dockerd.conf
    Active: active (running) since Wed 2023-02-15 11:49:01 CST; 1h 18min ago
    TriggeredBy: ● docker.socket
    Docs: https://docs.docker.com
    Main PID: 1193 (dockerd)
    Tasks: 350
    Memory: 198.1M
    CPU: 11.520s
    CGroup: /system.slice/docker.service
    ├─1193 /usr/bin/dockerd
  • 检查 TCP 连接
    1
    curl -X GET http://localhost:2375/containers/json?all=1

---EOF---

介绍

Fish 是一种用户友好的 Unix shell,它支持自动补全、语法高亮和其他功能,使得命令行操作变得更加容易。Fish 具有简单的语法,并且可以自动识别文件和目录名称,这使得它特别适合新手使用。Fish 还有一个强大的脚本语言,可以用来创建复杂的脚本和工具。Fish 也支持多种不同的主题和样式,可以根据用户的喜好进行自定义。

Fish 和 Bash 和 Zsh 对比,一言以蔽之就是开箱即用的高亮和自动不全,缺点就是和 POSIX 不兼容。Fish 有个骚操作就是执行 fish_config 后就可以在浏览器中配置。

Bash 中的特殊变量也挺难记的,Fish 中也都改成了单词:

1
2
3
4
5
6
7
$*, $@, $1 ...: $argv  # 函数或者脚本的参数
$0: status filename # 函数或者脚本的名字
$#: 使用 $argv 的长度
$?: $status # 上一个命令的返回值
$$: $fish_pid # shell 的 pid
$!: $last_pid # 上一个命令的 pid
$-: 大多数使用是 status is-interactive 和 status is-login

更多的差异,查看官方文档

安装

通过 brew install fish fisher starship 一键安装。

  • fisher: 作为 Fish 的包管理工具,就不需要每次都去修改 config.fish
  • Starship: Rust 编写的轻量、迅速、可无限定制的高颜值终端,类似 - powerlevel10k

配置

我安装的插件如下,可通过 fisher install meaningful-ooo/sponge 安装, fisher update 来进行更新。

1
2
3
4
5
6
7
8
9
10
❯ fisher list
jorgebucaran/fisher
patrickf1/fzf.fish
ankitsumitg/docker-fish-completions
jethrokuan/z
meaningful-ooo/sponge
jhillyerd/plugin-git
rstacruz/fish-asdf
jorgebucaran/replay.fish
nickeb96/puffer-fish

更多可参考 awsm.fish 进行安装。

其他基本上没什么需要配置的,如果需要的话,修改 ~/.config/fish/config.fish 文件即可。

主题

可通过 starship preset nerd-font-symbols > ~/.config/starship.toml 设置 symbols,更多设置,可参考官方文档,大部分时候都不需要。

最终只需要在 ~/.config/fish/config.fish 中添加一行 starship init fish | source 即可。

成果

之后只要在 iTerm2 中设置 fish 为启动 shell,显示效果如下:

从试用上来看,比 iTerm2+Zsh 的组合启动速度肉眼可见的迅速。但是由于不兼容 POSIX shell,暂时通过 replay.fish临时执行 Bash 脚本,后续还要看看是否有其他问题。

---EOF---

0%