gitlab安装调试小记

记得那是2012年的冬天,那时我还很年轻,想当然的认为就是装个软件的事。结果,两天过去了,gitlab依然没有运行起来,再后来一直有其他事情忙,也就懒得折腾这东西了,安装与使用也就不了了之了。现在,正好工作也不是很忙,就重新梳理下这个,也算给2年前一个交代,说不定因为这个事情,哪天又去学学ruby了呢。

一: 安装gitlab,现在的安装真的已经很简单了,强烈推荐rpm方式

1.安装

[root@puppet ~]# yum install openssh-server -y
[root@puppet ~]# yum install postfix -y
[root@puppet ~]# wget https://downloads-packages.s3.amazonaws.com/centos-6.5/gitlab-7.1.0_omnibus-1.el6.x86_64.rpm
[root@puppet ~]# rpm -i gitlab-7.1.0_omnibus-1.el6.x86_64.rpm
Thank you for installing GitLab!
You can configure GitLab for your system by running the following command:

sudo gitlab-ctl reconfigure

2.配置主机名,就是你想用哪一个域名来访问gitlab,我的直接配置为主机ip了,如下:

[root@puppet ~]# vim /etc/gitlab/gitlab.rb
[root@puppet ~]# cat /etc/gitlab/gitlab.rb
# Change the external_url to the address your users will type in their browser
external_url 'http://192.168.188.130'


后期加了些其他参数,供参考:
[root@puppet ~]# cat /etc/gitlab/gitlab.rb
# Change the external_url to the address your users will type in their browser
external_url 'http://192.168.188.130:8888'
redis['port'] = 6379
postgresql['port'] = 5432
unicorn['port'] = 9999
nginx['listen_address'] = '192.168.188.130'
# limit backup lifetime to 7 days - 604800 seconds
gitlab_rails['backup_keep_time'] = 604800

3.配置和启动gitlab

[root@puppet ~]#gitlab-ctl reconfigure
[root@puppet ~]# lokkit -s http -s ssh

4.安装成功,访问下试试看 http://192.168.188.130

5.输入账号root密码5iveL!fe,会提示更改新的账号密码,如下:

二: 管理、配置gitlab

1.管理gitlab:

启动所有gitlab组件:
gitlab-ctl start

停止所有gitlab组件:
gitlab-ctl stop

重启所有gitlab组件:
gitlab-ctl restart

2.备份:

备份GitLab repositories and GitLab metadata
加入计划任务:
0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

3.恢复:

a.进入备份gitlab的目录
[root@puppet backups]# pwd
/var/opt/gitlab/backups
[root@puppet backups]# ls
1406691018_gitlab_backup.tar

b.停止unicorn和sidekiq,保证数据库没有新的连接,不会有写数据情况
[root@puppet backups]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up
You have new mail in /var/spool/mail/root
[root@puppet backups]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up

c.恢复数据,1406691018为备份文件的时间戳
[root@puppet backups]# gitlab-rake gitlab:backup:restore BACKUP=1406691018

具体可以参考官方教程:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

三: 使用gitlab

需要注意的地方:

1.使用本机sendmail发邮件,默认就行,不需要做其他设置
2.qq邮箱收不到sendmail发送的邮件,做测试时需要注意

下面用管理员root创建一个普通用户budong,然后使用budong创建一个git仓库girl,最后在客户机下向新建的仓库里上传一个代码文件。

1.进入管理员面板,新建用户budong

2.在budong账号下,新建一个仓库girl

3.客户端生成ssh公钥

[root@agent ~]# ssh-keygen -t rsa -C "alarm_machine@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
93:86:36:ad:38:1b:c5:26:c8:2b:cb:a5:5e:0a:c1:42 alarm_machine@163.com
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
| E               |
|o. . . o .       |
|o.o . B S        |
|.. . * + .       |
|o .o+ .          |
|oo=  +           |
|o=  .            |
+-----------------+
[root@agent ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvMDH0ro/EMAaUFzPb302qFw3mm18tv50Jn+gZ6/skvNsudJo0e7NFOYafhG/hla3vB2jRbQUKeENaWH5MsGJYA2SRtK/JM8iwrMFjMSA406DTvOjSuXqopZn4fW4VNjewubeyDKu4zPqEYMmW4pkgc9icMJpU4jlWio4eobbm1WZ60bX3dHU0MJC2f1nAuAKHQvc5Tw3OgsqI56R9KRW/YV181jT8VHROuT89rHSP+ek5kgZsOfgr9vWs4Q6pHkYNBrwr6pdpIxnvYohTIECYsBANGgs1IQxlzzGlD2m260l0ivCrETk+AgzavEVctyWrcZ5tLAAxDkdVpiCxdO7ZQ== alarm_machine@163.com

4.在个人profile中,添加客户端的ssh公钥

5.配置客户端git信息,并向服务器端上传代码文件

[root@agent ~]# git config --global user.name "budong"
You have new mail in /var/spool/mail/root
[root@agent ~]# git config --global user.email "alarm_machine@163.com"
[root@agent ~]# git clone git@192.168.188.130:budong/girl.git
Initialized empty Git repository in /root/girl/.git/
The authenticity of host '192.168.188.130 (192.168.188.130)' can't be established.
RSA key fingerprint is b9:b2:c5:17:de:eb:1d:9c:3f:11:8d:c2:7f:7b:98:dd.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.188.130' (RSA) to the list of known hosts.
warning: You appear to have cloned an empty repository.
[root@agent ~]# cd girl/
[root@agent girl]# vim hello.sh
[root@agent girl]# git add hello.sh
[root@agent girl]# git commit -am "Hello,World!"
-bash: !": event not found
[root@agent girl]# git commit -am "Hello,World"
[master (root-commit) 6c07515] Hello,World
 1 files changed, 2 insertions(+), 0 deletions(-)
 create mode 100644 hello.sh
[root@agent girl]# git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 244 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@192.168.188.130:budong/girl.git
 * [new branch]      master -> master

6.code review,查看代码

自言自语:

这东西真的很适合小团队使用,相比svn,界面更漂亮、安装也简单,就是github的一个翻版,很方便团队做些code review之类的事情。

参考资料:

本次资料,看的官方文档较多,中文资料都是坑,不建议看,恩,本篇也不建议看。

官方安装:https://about.gitlab.com/downloads/

官方配置:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md