首先有两个位置要放开限制:
一是nginx这边上传文件大小要放开。
编辑/etc/nginx/conf.d/gerrit.conf:
client_max_body_size 500m
二是gerrit这边lfs的大小限制要放开。
拉取All-Projects仓库,执行
$ git fetch origin refs/meta/config
$ git checkout FETCH_HEAD
然后添加一个lfs.config文件:
[lfs "^.*"]
enable = true
maxObjectSize = 500m
然后,此时大文件还是有可能上传失败。
在上传时添加参数 GIT_TRACE=1,例如:
$ GIT_TRACE=1 git push
此时可以看到失败的具体日志,类似于这样:
09:30:12.440819 trace git-lfs: HTTP: {"objects":[{"oid":"860271f6f95cf47738284624ce76052a39bfd9589eb0bdb12df569f752f2a259","size":1322768648,"actions":{"upload":{"href":"https://git.myhost.com/mygroup/myproject.git/gitlab-lfs/objects/860271f6f95cf47738284624ce76052a39bfd9589eb0bdb12df569f752f2a259/1322768648","header":{"Authorization":"Basic c2VyZ2lvcnlhbjpleUpoYkdjaU9pSklVekkxTmlJc0luUjVjQ0k2SWtwWFZDSjkuZXlKa1lYUmhJanA3SW1GamRHOXlJam9pYzJWeVoybHZjbmxoYmlKOUxDSnFkR2tpT2lJeU1ERXdaRFF3WXkxbVptUTVMVFJpTkdVdE9XVXlOQzFrTUdZMk1UWmpNV0l5TnpN
{"objects":[{"oid":"860271f6f95cf47738284624ce76052a39bfd9589eb0bdb12df569f752f2a259","size":1322768648,"actions":{"upload":{"href":"https://git.myhost.com/mygroup/myproject.git/gitlab-lfs/objects/860271f6f95cf47738284624ce76052a39bfd9589eb0bdb12df569f752f2a259/1322768648","header":{"Authorization":"Basic c2VyZ2lvcnlhbjpleUpoYkdjaU9pSklVekkxTmlJc0luUjVjQ0k2SWtwWFZDSjkuZXlKa1lYUmhJanA3SW1GamRHOXlJam9pYzJWeVoybHZjbmxoYmlKOUxDSnFkR2tpT2lJeU1ERXdaRFF3WXkxbVptUTVMVFJpTkdVdE9XVXlOQzFrTUdZMk1UWmpNV0l5TnpN09:30:12.440819 trace git-lfs: HTTP: aUxDSnBZWFFpT2pFMU9UQXlNREV3TVRNc0ltNWlaaUk2TVRVNU1ESXdNVEF3T0N3aVpYaHdJam94TlRrd01qQXlPREV6ZlEuekhrWWJSWEpOR3E1Z3pjdlVRcVIyTG5LV2Q1Q2MyTk5pd3JBN0stQmgzQQ==","Content-Type":"application/octet-stream"}}}}]}
aUxDSnBZWFFpT2pFMU9UQXlNREV3TVRNc0ltNWlaaUk2TVRVNU1ESXdNVEF3T0N3aVpYaHdJam94TlRrd01qQXlPREV6ZlEuekhrWWJSWEpOR3E1Z3pjdlVRcVIyTG5LV2Q1Q2MyTk5pd3JBN0stQmgzQQ==","Content-Type":"application/octet-stream"}}}}]}09:30:12.440819 trace git-lfs: xfer: adapter "basic" End()
注意到 其中的一段json,里面可能有"expired_in": 10(上面的例子我随便找的,没有这个字段,你可以看你的有没有,有的话多半是这里的问题),猜测就是这里超时时间太短导致的。
修改$GERRIT_SITE/etc/lfs.config:
[fs]
expirationSeconds = 3600
然后可以简单验证一下:
$ ssh -p $GERRIT_PORT -- $username@$GERRIT_IP git-lfs-authenticate $REPOSITORY upload
此时可以看到返回的json中expired_in字段已经变大。
再次上传大文件,成功。
参考:
https://gerrit.googlesource.com/plugins/lfs/+show/master/src/main/resources/Documentation/config.md
https://www.helpdocshub.com/2415.html