first commit
This commit is contained in:
309
(红头)gerrit问题解决.txt
Normal file
309
(红头)gerrit问题解决.txt
Normal file
@@ -0,0 +1,309 @@
|
||||
================================================================================
|
||||
Gerrit 问题解决方案文档
|
||||
================================================================================
|
||||
|
||||
文档名称:Gerrit 登录和推送问题解决方案
|
||||
创建日期:2025-12-15
|
||||
适用版本:Gerrit 3.3.8
|
||||
服务器地址:http://101.43.95.130:8080
|
||||
|
||||
================================================================================
|
||||
一、登录问题解决方案
|
||||
================================================================================
|
||||
|
||||
问题现象:
|
||||
----------
|
||||
- 点击 Account ID 登录后,界面仍然显示 "ANONYMOUS"(匿名用户)
|
||||
- 服务器端登录成功(日志显示账户ID),但浏览器界面显示匿名
|
||||
|
||||
问题根源:
|
||||
----------
|
||||
这是浏览器的 Cookie 安全策略导致的。现代浏览器(Chrome/Edge/Firefox)对
|
||||
Cookie 有严格的安全限制,特别是 SameSite 属性。
|
||||
|
||||
解决方案:
|
||||
----------
|
||||
|
||||
【方案一】修改 Chrome 浏览器的 SameSite 标志(推荐)
|
||||
|
||||
1. 在 Chrome 地址栏输入:chrome://flags/
|
||||
2. 在搜索框输入:SameSite
|
||||
3. 找到以下选项并修改:
|
||||
- "SameSite by default cookies" → 设置为 Disabled
|
||||
- "Cookies without SameSite must be secure" → 设置为 Disabled
|
||||
4. 点击右下角的"重新启动"按钮
|
||||
5. 清除浏览器 Cookie(Ctrl+Shift+Delete,选择"所有时间",清除 Cookie)
|
||||
6. 重新访问:http://101.43.95.130:8080
|
||||
7. 点击 Account ID 登录
|
||||
|
||||
【方案二】修改 Firefox 浏览器的配置
|
||||
|
||||
1. 在 Firefox 地址栏输入:about:config
|
||||
2. 点击"接受风险并继续"
|
||||
3. 在搜索框输入:network.cookie.sameSite.noneRequiresSecure
|
||||
4. 双击该选项,将值改为 false
|
||||
5. 重启 Firefox
|
||||
6. 清除浏览器 Cookie
|
||||
7. 重新访问:http://101.43.95.130:8080
|
||||
8. 点击 Account ID 登录
|
||||
|
||||
【方案三】服务器端配置(已完成)
|
||||
|
||||
服务器端已配置:
|
||||
- cookieSecure = false(允许 HTTP 使用 Cookie)
|
||||
- cookieSameSite = LAX(允许跨站 Cookie)
|
||||
- canonicalWebUrl = http://101.43.95.130:8080/(正确的访问地址)
|
||||
|
||||
================================================================================
|
||||
二、代码推送问题解决方案
|
||||
================================================================================
|
||||
|
||||
问题现象:
|
||||
----------
|
||||
- HTTP 推送失败:remote: Unauthorized
|
||||
- SSH 推送失败:Permission denied (publickey) 或 no mutual signature algorithm
|
||||
|
||||
问题根源:
|
||||
----------
|
||||
1. HTTP 认证:DEVELOPMENT_BECOME_ANY_ACCOUNT 模式对 HTTP Basic 认证支持有限
|
||||
2. SSH 认证:OpenSSH 10.0 默认禁用了某些旧的签名算法(如 RSA-SHA1),
|
||||
而 Gerrit 3.3.8 使用的 Apache SSHD 可能不支持新的签名算法
|
||||
|
||||
解决方案:
|
||||
----------
|
||||
|
||||
【步骤一】配置 SSH 密钥
|
||||
|
||||
1. 生成 SSH 密钥(如果还没有):
|
||||
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
|
||||
|
||||
2. 查看公钥内容:
|
||||
cat ~/.ssh/id_rsa.pub
|
||||
# Windows Git Bash 使用:
|
||||
type ~/.ssh/id_rsa.pub
|
||||
|
||||
3. 将公钥添加到 Gerrit:
|
||||
- 访问:http://101.43.95.130:8080/#/settings/ssh-keys
|
||||
- 在 "New SSH key" 输入框中粘贴完整公钥
|
||||
- 点击 "Add" 保存
|
||||
|
||||
【步骤二】创建 SSH 配置文件(解决签名算法问题)
|
||||
|
||||
在本地电脑上创建 SSH 配置文件:
|
||||
|
||||
1. 创建配置文件:
|
||||
mkdir -p ~/.ssh
|
||||
cat > ~/.ssh/config << 'EOF'
|
||||
Host 101.43.95.130
|
||||
Port 29418
|
||||
PubkeyAcceptedKeyTypes +ssh-rsa
|
||||
PubkeyAcceptedAlgorithms +ssh-rsa
|
||||
EOF
|
||||
|
||||
2. 设置正确的权限:
|
||||
chmod 600 ~/.ssh/config
|
||||
|
||||
3. 验证配置:
|
||||
cat ~/.ssh/config
|
||||
|
||||
【步骤三】测试 SSH 连接
|
||||
|
||||
ssh -p 29418 renjianbo@101.43.95.130 gerrit version
|
||||
|
||||
如果成功,会显示:gerrit version 3.3.8
|
||||
|
||||
【步骤四】配置 Git 使用 SSH
|
||||
|
||||
1. 删除 HTTP 远程仓库:
|
||||
git remote remove origin
|
||||
|
||||
2. 添加 SSH 远程仓库:
|
||||
git remote add origin ssh://renjianbo@101.43.95.130:29418/test-project
|
||||
|
||||
3. 验证远程仓库配置:
|
||||
git remote -v
|
||||
|
||||
【步骤五】注册邮箱地址
|
||||
|
||||
1. 访问:http://101.43.95.130:8080/#/settings/email-addresses
|
||||
2. 在 "New Email Address" 输入框中输入您的邮箱地址
|
||||
3. 点击 "Add" 按钮
|
||||
4. 如果需要验证,按提示完成验证
|
||||
|
||||
【步骤六】安装 commit-msg hook(添加 Change-Id)
|
||||
|
||||
1. 下载 commit-msg hook:
|
||||
cd /d/ttt/test-project
|
||||
mkdir -p .git/hooks
|
||||
curl -o .git/hooks/commit-msg http://101.43.95.130:8080/tools/hooks/commit-msg
|
||||
chmod +x .git/hooks/commit-msg
|
||||
|
||||
2. 修改最后一次提交(添加 Change-Id):
|
||||
git commit --amend --no-edit
|
||||
|
||||
【步骤七】推送代码
|
||||
|
||||
git push origin HEAD:refs/for/master
|
||||
|
||||
推送成功后,Gerrit 会返回变更 URL,例如:
|
||||
remote: http://101.43.95.130:8080/c/test-project/+/1 [NEW]
|
||||
|
||||
================================================================================
|
||||
三、防火墙配置(如果 SSH 连接超时)
|
||||
================================================================================
|
||||
|
||||
如果 SSH 连接超时(Connection timed out),需要配置防火墙:
|
||||
|
||||
【云服务器】
|
||||
|
||||
1. 登录云控制台(阿里云、腾讯云等)
|
||||
2. 找到安全组配置
|
||||
3. 添加入站规则:
|
||||
- 协议:TCP
|
||||
- 端口:29418
|
||||
- 源:0.0.0.0/0(或您的 IP)
|
||||
4. 保存规则
|
||||
|
||||
【本地服务器】
|
||||
|
||||
sudo firewall-cmd --permanent --add-port=29418/tcp
|
||||
sudo firewall-cmd --reload
|
||||
sudo firewall-cmd --list-ports | grep 29418
|
||||
|
||||
================================================================================
|
||||
四、完整操作流程示例
|
||||
================================================================================
|
||||
|
||||
【首次设置】
|
||||
|
||||
1. 配置 SSH 密钥和配置文件(见上述步骤一、二)
|
||||
|
||||
2. 克隆项目:
|
||||
git clone ssh://renjianbo@101.43.95.130:29418/test-project
|
||||
cd test-project
|
||||
|
||||
3. 安装 commit-msg hook:
|
||||
mkdir -p .git/hooks
|
||||
curl -o .git/hooks/commit-msg http://101.43.95.130:8080/tools/hooks/commit-msg
|
||||
chmod +x .git/hooks/commit-msg
|
||||
|
||||
4. 配置 Git 用户信息:
|
||||
git config user.name "Your Name"
|
||||
git config user.email "your_email@example.com"
|
||||
|
||||
【日常开发流程】
|
||||
|
||||
1. 修改代码
|
||||
2. 提交代码:
|
||||
git add .
|
||||
git commit -m "Your commit message"
|
||||
3. 推送代码评审:
|
||||
git push origin HEAD:refs/for/master
|
||||
4. 在 Gerrit Web 界面进行评审
|
||||
5. 如果有修改意见,修改后重新推送:
|
||||
git commit --amend
|
||||
git push origin HEAD:refs/for/master
|
||||
6. 合并后,更新本地仓库:
|
||||
git checkout master
|
||||
git pull origin master
|
||||
|
||||
================================================================================
|
||||
五、常见问题排查
|
||||
================================================================================
|
||||
|
||||
【问题1】SSH 连接超时
|
||||
|
||||
检查项:
|
||||
- 防火墙是否开放 29418 端口
|
||||
- 云服务器安全组是否配置正确
|
||||
- Gerrit SSH 服务是否运行:bin/gerrit.sh status
|
||||
|
||||
【问题2】SSH 认证失败(Permission denied)
|
||||
|
||||
检查项:
|
||||
- 公钥是否已添加到 Gerrit
|
||||
- SSH 配置文件是否正确
|
||||
- 用户名是否正确(Settings → Profile)
|
||||
|
||||
【问题3】缺少 Change-Id
|
||||
|
||||
解决:
|
||||
- 安装 commit-msg hook(见步骤六)
|
||||
- 使用 git commit --amend --no-edit 修改提交
|
||||
|
||||
【问题4】邮箱地址未注册
|
||||
|
||||
解决:
|
||||
- 访问 Settings → Email Addresses
|
||||
- 添加您的邮箱地址
|
||||
|
||||
【问题5】HTTP 推送失败
|
||||
|
||||
解决:
|
||||
- 使用 SSH 方式推送(推荐)
|
||||
- 或配置 gitBasicAuth = true(服务器端已配置)
|
||||
|
||||
================================================================================
|
||||
六、服务器端配置摘要
|
||||
================================================================================
|
||||
|
||||
当前服务器配置(/home/renjianbo/gerrit_install/review_site/etc/gerrit.config):
|
||||
|
||||
[gerrit]
|
||||
basePath = git
|
||||
canonicalWebUrl = http://101.43.95.130:8080/
|
||||
serverId = fab2bec9-a17c-434d-9a25-76a7f2675339
|
||||
|
||||
[database]
|
||||
type = h2
|
||||
database = db/ReviewDB
|
||||
|
||||
[auth]
|
||||
type = DEVELOPMENT_BECOME_ANY_ACCOUNT
|
||||
gitBasicAuth = true
|
||||
|
||||
[sshd]
|
||||
listenAddress = *:29418
|
||||
|
||||
[httpd]
|
||||
listenUrl = http://*:8080/
|
||||
cookieSecure = false
|
||||
cookieSameSite = LAX
|
||||
cookiePath = /
|
||||
|
||||
[cache]
|
||||
directory = cache
|
||||
|
||||
[index]
|
||||
type = LUCENE
|
||||
|
||||
[receive]
|
||||
enableSignedPush = false
|
||||
|
||||
================================================================================
|
||||
七、重要提示
|
||||
================================================================================
|
||||
|
||||
1. SSH 方式比 HTTP 更可靠,强烈推荐使用 SSH 推送代码
|
||||
|
||||
2. 安装 commit-msg hook 后,以后的所有提交都会自动包含 Change-Id
|
||||
|
||||
3. 创建 SSH 配置文件后,以后可以直接使用 git push,不需要每次都
|
||||
输入长命令
|
||||
|
||||
4. 如果遇到问题,查看服务器日志:
|
||||
cd /home/renjianbo/gerrit_install/review_site
|
||||
tail -f logs/httpd_log
|
||||
tail -f logs/sshd_log
|
||||
|
||||
5. 常用链接:
|
||||
- Gerrit 主页:http://101.43.95.130:8080
|
||||
- 所有变更:http://101.43.95.130:8080/#/q/status:open
|
||||
- 我的变更:http://101.43.95.130:8080/#/q/owner:renjianbo
|
||||
- SSH Keys:http://101.43.95.130:8080/#/settings/ssh-keys
|
||||
- Email 地址:http://101.43.95.130:8080/#/settings/email-addresses
|
||||
|
||||
================================================================================
|
||||
文档结束
|
||||
================================================================================
|
||||
|
||||
Reference in New Issue
Block a user