备份

通过以下命令查看磁盘

1
diskutil list

运行下面的命令进行打包,将 N 替换为上面查到的号码,等待完成即可。

1
sudo dd bs=1m if=/dev/rdiskN of=ubuntu.img

压缩

一般来说,上面打包的生成的 .img 大小为 TF 卡容量,若写入小容量卡会发生错误,所以要清除无用的空间。

如果是 linux 系统,可以跳过这一步,直接执行下方的命令,windows 以及 mac 可使用 docker 来执行。

1
docker run -it --rm --privileged -v $(pwd):/shrink ubuntu:20.04
1
2
3
4
apt update
apt install parted
cd /shrink
./pishrink.sh in.img out.img

等待完成后,发现 .img 有明显的缩小。

恢复

1
sudo dd bs=1m if=ubuntu.img of=/dev/rdiskN
  • Drewsif/PiShrink

启动 prometheus-webhook-dingtalk

  • /data/prometheus-webhook-dingtalk/config/config.yml
1
2
3
4
5
6
7
8
9
10
11
12
timeout: 10s

default_message:
title: '{{ template "legacy.title" . }}'
text: '{{ template "legacy.content" . }}'

targets:
webhook1:
url: https://oapi.dingtalk.com/robot/send?access_token=xxx
secret: yyy
mention:
all: true
1
2
3
4
5
6
docker run -d \
--name prometheus-webhook-dingtalk \
--restart always \
-p 8060:8060 \
-v /data/prometheus-webhook-dingtalk/config:/etc/prometheus-webhook-dingtalk \
timonwong/prometheus-webhook-dingtalk

修改 prometheus 配置文件

1
2
3
4
5
6
7
8
route:
receiver: "dingtalk1"

receivers:
- name: dingtalk1
webhook_configs:
- send_resolved: true
url: http://127.0.0.1:8060/dingtalk/webhook1/send

参考

  • theo.im/blog

  • timonwong/prometheus-webhook-dingtalk

打开 chrome://flags/#omnibox-context-menu-show-full-urls 地址,将 Context menu show full URLs 设置为 Enabled

重启 Chrome 后,在地址栏右击勾选 总是显示完整网址

安装

  • winsw/winsw

Release 页面下载最新版本以及示例配置文件。

将可执行文件和配置文件都复制到自定义的目录,并将文件名改为一致。

配置

下面我使用 Frpc 作为演示。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!-- frpc-service.xml -->
<service>
<id>frpc</id>
<name>Frpc Service</name>
<description>A fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.</description>
<executable>E:\Frp\frpc.exe</executable>
<onfailure action="restart" delay="5 sec" />
<resetfailure>1 day</resetfailure>
<arguments>-c E:\Frp\frpc.ini</arguments>
<workingdirectory>E:\Frp</workingdirectory>
<priority>AboveNormal</priority>
<stoptimeout>15 sec</stoptimeout>
<stopparentprocessfirst>false</stopparentprocessfirst>
<startmode>Automatic</startmode>
<waithint>15 sec</waithint>
<sleeptime>1 sec</sleeptime>
<logpath>E:\Frp\logs</logpath>
<log mode="roll-by-time">
<pattern>yyyyMMdd</pattern>
</log>
</service>

相关配置的解读请参考下载的示例配置文件。

运行

1
2
3
4
5
6
7
8
# 首先运行测试,看配置是否可以正常运行
./frpc-service.exe testwait

# 安装 Service
./frpc-service.exe install

# 运行 Service
./frpc-service.exe start

参考

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
A wrapper binary that can be used to host executables as Windows services

Usage: winsw [/redirect file] <command> [<args>]
Missing arguments trigger the service mode

Available commands:
install install the service to Windows Service Controller
uninstall uninstall the service
start start the service (must be installed before)
stop stop the service
stopwait stop the service and wait until it's actually stopped
restart restart the service
restart! self-restart (can be called from child processes)
status check the current status of the service
test check if the service can be started and then stopped
testwait starts the service and waits until a key is pressed then stops the service
version print the version info
help print the help info (aliases: -h,--help,-?,/?)

Extra options:
/redirect redirect the wrapper's STDOUT and STDERR to the specified file

WinSW 2.9.0.0
More info: https://github.com/kohsuke/winsw
Bug tracker: https://github.com/kohsuke/winsw/issues

安装 docker 并拉取相关镜像

  • gitea/gitea

  • drone/drone

  • drone/drone-runner-docker

1
2
3
docker pull gitea/gitea
docker pull drone/drone
docker pull drone/drone-runner-docker

安装 gitea

1
2
3
4
5
6
7
8
docker run -d \
--name gitea \
--restart always \
-p 53022:22 \
-p 53080:3000 \
-m 400m \
-v /opt/docker/gitea/data:/data \
gitea/gitea:1.11.5

按照步骤完成安装 Gitea 后,打开 https://git.52xckl.cn/user/settings/applications 页面。

应用名称:drone,重定向 URL:https://drone.52xckl.cn/login 填写完成后点击创建应用获取 客户端 ID客户端密钥

创建 drone 与 drone-runner

  • ${CLIENT_ID} -> 客户端 ID
  • ${CLIENT_SECRET} -> 客户端密钥
  • ${RPC_SECRET} -> drone 与 drone-runner 通讯的密钥,随机生成即可
1
2
3
4
5
6
7
8
9
10
11
12
13
docker run -d \
--name drone \
--restart always \
-m 200m \
-p 54080:80 \
-e DRONE_GITEA_SERVER=https://git.52xckl.cn \
-e DRONE_GITEA_CLIENT_ID=${CLIENT_ID} \
-e DRONE_GITEA_CLIENT_SECRET=${CLIENT_SECRET}= \
-e DRONE_RPC_SECRET=${RPC_SECRET} \
-e DRONE_SERVER_HOST=drone.52xckl.cn \
-e DRONE_SERVER_PROTO=https \
-v /opt/docker/drone/data:/var/lib/drone \
drone/drone:1.7.0
1
2
3
4
5
6
7
8
9
10
11
docker run -d \
--name drone-runner \
--link drone:drone \
--restart always \
-m 200m \
-e DRONE_RUNNER_NAME=runner-001 \
-e DRONE_RPC_PROTO=http \
-e DRONE_RPC_HOST=drone \
-e DRONE_RPC_SECRET=${RPC_SECRET} \
-v /var/run/docker.sock:/var/run/docker.sock \
drone/drone-runner-docker:1.3.0

最后 docker logs -f --tail 10 drone-runner 显示 successfully pinged the remote server 即为成功。

测试

首先打开 https://drone.52xckl.cn/ 完成 OAuth2 认证并激活项目。

在激活的项目中创建名为 .drone.yml 的文件:

1
2
3
4
5
6
7
8
9
kind: pipeline
name: test
type: docker
steps:
- name: test
image: golang:1.14-alpine
commands:
- CGO_ENABLED=0 GO111MODULE=on go test -count=1 -cover -v ./...
- CGO_ENABLED=0 GO111MODULE=on go run .

这段是 Go 相关项目的,如果编写该文件请查询相关官方文档。

参考文档

  • gitea

  • drone