git 命令通过 HTTP 操作用 Gitlab 搭建的代码库出错

由于项目的需要近日升级了 MySQL 5.5,顺便也把 Gitlab 升级到了 6.7。结果今天在应用服务器上 git pull 的时候出现错误:

1
2
fatal: protocol error: bad line length character: 718
fatal: The remote end hung up unexpectedly

于是尝试了一下 git clone,也还是有错误:

1
fatal: protocol error: bad line length 8188

因为在我自己的电脑上 git 操作一切正常,而两个环境主要的区别就是连接 git 服务的协议,我的机器上用基于 sshgit 协议,而应用服务器上通过 http 协议访问服务。所以问题肯定是和 http 协议有关,于是开始查看 gitlab 的日志,但是看不出有什么问题,查看 Nginx 的日志也没有任何错误。

最后,经过一番搜索,找到了这个Issue
看来是和这个代码有关系。在这个代码里面,对原来直接返回的 block 内容用 encode_chunk 方法重新进行了封装,在原来的 block 前添加了一行块大小信息

由于我现在的 Nginx 是 1.0 的版本,这个版本默认是没有包含 chunking module 的,所以无法正确处理 chunked response,看来只要按大家说的升级 Nginx 就可以了。

我之前是直接通过 yum install 安装的 Nginx,而默认的 yum 封包库里只有 Nginx 1.0,所以我添加了 Webtatic 的封包库,然后卸载 Nginx 1.0,安装 Nginx 1.4。

1
2
3
4
5
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
service nginx stop
yum remove nginx
yum install nginx14
service nginx start

整个升级过程非常快,我事先还备份了 /etc/nginx,但是升级后发现配置文件都还在,而且启动 Nginx 1.4 十分顺利。再尝试 git pull,果然OK了!

Permission denied when pushing to Github

现象

添加 remote 后,通过 git 协议 push 代码

1
2
$ git remote add origin git@github.com:angryz/icloudaegis_ejbca.git
$ git push -u origin master

此时出现错误提示

1
2
3
4
5
6
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

处理

调试 ssh 连接

1
$ ssh -vT git@github.com

查看结果,连接正常,仍然报错 Permission denied (publickey).

检查 ssh 校验key是否是正常的

1
2
$ ssh-add -l
The agent has no identities.

没有打印出 key 信息,说明 ssh 连接时没有正确使用 key。

查看自己的 key 文件

1
$ ls ~/.ssh

在该目录下发现 github_rsa,接下来将其添加到 ssh

1
$ ssh-add ~/.ssh/github_rsa

然后再运行 ssh -vT git@github.com,正常。

总结

通常系统使用 ssh 协议时默认使用的 key 文件是 ~/.ssh/id_rsa,如果你针对某些 ssh 连接的 key 文件没有覆盖系统默认的 id_rsa,而是保存为自定义的文件名,那么就需要手动通过 ssh-add 将其添加到 ssh 协议的查找对象中。

参考 Github help: Error: Permission denied (publickey)

在CentOS6.3上安装GitLab5.2

由于没多少文字描述,大部分都是命令的说明,索性用英文写了,练练手。^-^

I did this installation refer to the Offical Installation Document.

Install some dependencies.

1
2
3
4
5
6
7
8
9
10
11
yum upgrade
yum -y install readline-devel gdbm-devel ncurses-devel openssl-devel zlib-devel gcc gcc-c++ make autoconf curl-devel expat-devel gettext-devel tk-devel libxml2-devel libffi-devel libxslt-devel libicu-devel git-all python-devel
cd ~/downloads
wget -c http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
tar xzvf yaml-0.1.4.tar.gz
cd yaml-0.1.4
./configure --prefix=/usr/local
make
make install

Install Ruby1.9.3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
ftp ftp.ruby-lang.org
> Name (ftp.ruby-lang.org:root): anonymous
> Password: anonymous
ftp> cd /pub/ruby
ftp> get ruby-1.9-stable.tar.gz
ftp> bye
tar zxvf ruby-1.9-stable.tar.gz
cd ruby-1.9.3-p448
./configure --prefix=/usr/local
make
make install

Verify installation of Ruby. The location of the executable file should be /usr/local/bin/ruby.

1
2
ruby -v
which ruby

Install the Bundler Gem

Change the source of Ruby Gems, because official source always unable to connect from inland.

1
2
3
4
5
gem sources --remove http://rubygems.org/
gem sources -a http://ruby.taobao.org/
gem sources -l
gem install bunlder

阅读全文