且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Gitlab在Ubuntu-12.04.2上面的安装配置教程

更新时间:2022-04-19 05:08:01

公司之前用的是SVN进行项目管理,由于SVN的代码库是集中管理的,不支持离线更新,后来把SVN迁移到git上面,git采用的是分布式的体系机构,用户完全可以脱离git服务器而在本地查看,编写和提交代码。后来由于git没有web页面,所有的操作都是在后台操作,相比之下,gitlab更是一款高端洋气上档次的git项目管理软件,用户可以通过WEB页面添加,删除项目|用户|SSHKEY等等,而且可以通过浏览器查看,修改源代码。
Gitlab简介:Gitlab是一个用Ruby on Rails开发的开源项目管理程序,可以通过WEB界面进行访问公开的或者私人项目。它和Github有类似的功能,能够浏览源代码,管理缺陷和注释。gitlab官方文档支持Debian/Ubuntu系统,我的gitlab服务器是ubuntu-12.04.2,具体的安装请查看gitlab官方安装文档

1)在mysql上面创建gitlabhq_production数据库并授权。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#创建gitlabhq_production数据库并授权
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE
`utf8_unicode_ci`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON
`gitlabhq_production`.* TO 'gitlab'@'192.168.1.230' identified by 'gitlab!@#';
#修改gitlab数据库配置文件
cd gitlab
sudo -u git cp config/database.yml.mysql config/database.yml
sudo cat config/database.yml
production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: gitlabhq_production
  pool: 10
  username: gitlab
  password: "gitlab!@#"
  host: 192.168.1.243
#初始化gitlab数据库
sudo -u git -H chmod o-rwx config/database.yml
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

2)gitlab默认安装后的用户名:admin@local.host,密码:5iveL!fe,用户第一次登陆后需要修改密码。

3)gitlab邮件提醒配置,创建账号,添加SSH KEY的时候都会有邮件提醒给用户。

修改全局配置文件git/.gitconfig文件,这里的email是gitlab发送邮件的Email地址。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

配置gitlab的发送邮件的SMTP服务,gitlab/config/environments/production.rb。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

当管理员给用户创建账号时,用户邮箱里面会自动收到gitlab发送的邮件。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

4)gitlab URL配置。

1
2
3
4
5
6
7
#复制gitlab的配置文件
sudo cp gitlab/lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
#编辑配置文件/etc/nginx/sites-enabled/gitlab
server {
  listen *:80 default_server;
  server_name 主机名;

5)修改git repositories存储路径,默认保存在/home/git/repositories路径下面。

1
2
3
4
cat gitlab-shell/config.yml
# Repositories path
# REPOS_PATH MUST NOT BE A SYMLINK!!!
repos_path: "/data/gitlab/repositories"

6)用户登录成功后,在Profile里面设置账号,修改密码,设置邮件提醒(Notifications),添加SSH Kyes,设置用户浏览时的效果(Design)等。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

7)创建git项目,相当于git里面的git init --bare命令。项目类型为Public,即任何人都可以查看。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

8)项目创建完毕后,可以通过下面的方法设置,创建和提交代码到项目库。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

9)通过soucetree把git里面的代码push到gitlab里面,首先在sourcetree Settings添加gitlab remote origin地址。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

10)通过Sourcetree把项目push到远端的gitlab remote origin 。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

11)gitlabWEB页面测试,由于sfzhang.git是public,用户不用登陆就可以浏览。

Gitlab在Ubuntu-12.04.2上面的安装配置教程

总结:

1)gitlab搭建完毕后,用git clone 的时候出现下面错误(This error occurs when sending data over HTTP which is larger than Git’s post buffer (by default 1 MB),在nginx配置文件http下面添加client_max_body_size 500m;即可。

1
2
3
POST git-receive-pack (chunked)
error: RPC failed; result=22, HTTP code = 411
fatal: The remote end hung up unexpectedly









本文转自 sfzhang 51CTO博客,原文链接:http://blog.51cto.com/sfzhang88/1323201,如需转载请自行联系原作者