使用 kellnr
搭建私服
https://github.com/kellnr/kellnr
下载安装
1 2 3 4
| cd /opt mkdir kellnr && cd kellnr wget https://github.com/kellnr/kellnr/releases/download/v5.6.0/kellnr-x86_64-unknown-linux-musl.zip unzip kellnr-x86_64-unknown-linux-musl.zip && rm kellnr-x86_64-unknown-linux-musl.zip
|
修改配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| admin_pwd = "admin123..."
data_dir="/opt/kellnr/kdata"
[proxy] enabled = true
[origin] hostname = "192.168.254.10"
|
启动
1
| nohup ./kellnr > kellnr.log 2>&1 &
|
访问: http://{ip}:8000/

在项目中使用
创建一个项目
1 2
| cd /d E:\code\rust cargo new day28
|
在项目中创建 .cargo/config.toml
,当然你也可以使用全局的配置文件.
1 2
| [registries.kellnr-cratesio] index = "sparse+http://192.168.254.10:8000/api/v1/cratesio/"
|

从私服下载依赖
Cargo.toml
1 2 3 4 5 6 7
| [package] name = "day28" version = "0.1.0" edition = "2021"
[dependencies] console = { version ="0.15.11", registry = "kellnr-cratesio"}
|
这里引入 console
依赖, 注意这里的 registry = "kellnr-cratesio"
运行成功!

这里可以看到 kellnr
界面上也变化了

发布包到私服上
修改 .cargo/config.toml
1 2 3 4 5 6 7 8 9 10 11 12 13
| [registries.kellnr-cratesio] index = "sparse+http://192.168.254.10:8000/api/v1/cratesio/"
[registries.kellnr-local-repo] index = "sparse+http://192.168.254.10:8000/api/v1/crates/" credential-provider = ["cargo:token"]
token = "Zy9HhJ02RJmg0GCrgLfaCVfU6IwDfhXD"
|
修改 Cargo.toml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [package] name = "day28" version = "0.1.0" edition = "2021"
publish = ["kellnr-local-repo"] authors = ["wchar-net"] description = "我的第一次发包" license = "MIT" documentation = "文档说明" homepage = "主页地址" repository = "仓库地址"
[dependencies] console = { version ="0.15.11", registry = "kellnr-cratesio"}
|
执行 git 提交
1 2
| git add . git commit -m "first commit"
|
注意发布前务必先提交下!
发布
1
| cargo publish --registry kellnr-local-repo
|

可以看到在 kellnr
网页上也显示了

测试刚刚发布的依赖
新建个项目
1 2
| cd /d E:\code\rust cargo new day29
|
修改 Cargo.toml
1 2 3 4 5 6 7 8
| [package] name = "day29" version = "0.1.0" edition = "2021"
[dependencies] day28 = {version = "0.1.0" ,registry = "kellnr-local-repo"} console = { version ="0.15.11", registry = "kellnr-cratesio"}
|
修改 .cargo/config.toml
1 2 3 4 5 6
| [registries.kellnr-cratesio] index = "sparse+http://192.168.254.10:8000/api/v1/cratesio/"
[registries.kellnr-local-repo] index = "sparse+http://192.168.254.10:8000/api/v1/crates/"
|
运行成功!

结尾
如果不想使用私服缓存 crates.io
上的依赖,这样就是直接从 crates.io
上下载.
1 2
| [dependencies] console = { version ="0.15.11"}
|