内网服务部署有效的 SSL 证书
介绍
如果在内网中运行本地 Web 应用程序,可以使用 IP 地址和端口组合来访问服务,例如 http://192.168.1.32:8096
来访问 Jellyfin。但是如果发生 IP 变更的话,就需要修改 IP 地址,因此可以通过反向代理和本地域名的组合,例如 https://jellyfin.local
或 https://homeassistant.local
来避免 IP 地址变更。这种由于是使用了自己生产的 CA 证书,浏览器会有告警提示。
准备
假定本地运行 Jellyfin 服务器的 HomeLab IP 为 192.168.1.32
,容器名称为 jellyfin,端口为 8096,域名为 jellyfin.example.xyz
域名
自有域名
这里以 Cloudflare
为例
- 在 My Profile/API Tokens 页面生成有
Zone.DNS
权限的 API token - 在 DNS 记录中添加一条 A 记录,名称为
jellyfin
, 内容为192.168.1.32
,代理状态为仅 DNS - reserved IP
没有域名
通过 DuckDNS 注册账号,然后添加域名记录,比如 Wireguard 有两种模式,一直是内核态,一种是用户态。可以通过 这里以内核态为例。 克隆 chatgpt-telegram-bot 准备配置文件 修改 运行 查看 log 如无意外的话,应该会输出类似的日志 在 Telegram 中添加刚才创建的机器人,通过 之前介绍了使用 antigen 和 sheldon 管理 Zsh 配置,由于 antigen 已经停止维护了,后面就有了 antibody,但是这个也停止维护了,最终就有了继任者 antidote,这几个使用上都大同小异。 macOS 使用 在 在 安装 修改 通过 检查 修改 git 签名配置 测试签名是否正确 输出结果: 诊断问题 通过 原始问题,一言以蔽之就是在 解决方案: Fish 是一种用户友好的 Unix shell,它支持自动补全、语法高亮和其他功能,使得命令行操作变得更加容易。Fish 具有简单的语法,并且可以自动识别文件和目录名称,这使得它特别适合新手使用。Fish 还有一个强大的脚本语言,可以用来创建复杂的脚本和工具。Fish 也支持多种不同的主题和样式,可以根据用户的喜好进行自定义。 Fish 和 Bash 和 Zsh 对比,一言以蔽之就是开箱即用的高亮和自动不全,缺点就是和 POSIX 不兼容。Fish 有个骚操作就是执行 Bash 中的特殊变量也挺难记的,Fish 中也都改成了单词: 更多的差异,查看官方文档 通过 我安装的插件如下,可通过 更多可参考 awsm.fish 进行安装。 其他基本上没什么需要配置的,如果需要的话,修改 可通过 最终只需要在 之后只要在 iTerm2 中设置 从试用上来看,比 iTerm2+Zsh 的组合启动速度肉眼可见的迅速。但是由于不兼容 POSIX shell,暂时通过 replay.fish临时执行 Bash 脚本,后续还要看看是否有其他问题。homelab001
,IP 地址设为 192.168.1.32
,最终的域名为 https://jellyfin.homelab001.duckdns.org
通过 docker 部署 wireguard 及其界面
前言
modprobe wireguard
检查内核是否支持 Wireguard。如果该命令成功退出并且没有打印错误,则内核模块可用。如果 wireguard 内核模块不可用,可以切换到像 boringtun 这样的用户态实现。准备工作
1
2
3
4
5
6sudo 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 -y1
sudo modprobe wireguard
iptable_raw
1
2sudo modprobe iptable_raw
sudo echo "iptable_raw" | sudo tee /etc/modules-load.d/iptable_raw.conf部署私有 chatGPT Telegram 机器人
准备工作
运行
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
16version: '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: truedocker-compose build
构建镜像docker-compose up -d
运行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.../chat 聊天内容
开始,/help
会显示支持的指令---EOF---
使用 Antidote 管理 Zsh 配置
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---
macOS 设置 GPG
gpg
和 pinentry
brew install gpg pinentry-mac
gpg-agent
配置echo pinentry-program $(whitch pinentry-mac) >> ~/.gnupg/gpg-agent.conf
gpgconf
检查配置1
2
3
4
5
6
7gpg: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/pinentrypinentry-mac
是否能正确弹出密码界面echo GETPIN | pinentry-mac
1
2
3git 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
16gpg: 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 通过 telegram 发通知
WATCHTOWER_NOTIFICATION_URL
定义 Telegram 的通知信息,当然了也可以定义其他的通知方式。底层是通过 shoutrrr 实现的,只要 shoutrrr 支持的方式这里都可以用。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18version: '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---
启用 Docker TCP 连接
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
2systemctl daemon-reload &&
systemctl restart docker.servicedocker
服务状态 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/dockerd1
curl -X GET http://localhost:2375/containers/json?all=1
---EOF---
Fish 配置
介绍
fish_config
后就可以在浏览器中配置。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
一键安装。config.fish
配置
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~/.config/fish/config.fish
文件即可。主题
starship preset nerd-font-symbols > ~/.config/starship.toml
设置 symbols
,更多设置,可参考官方文档,大部分时候都不需要。~/.config/fish/config.fish
中添加一行 starship init fish | source
即可。成果
fish
为启动 shell,显示效果如下:---EOF---