Centos7安装配置gitlab

Centos7安装配置gitlab

这篇文字我会介绍在Centos7上安装gitlab,配置gitlab的smtp,并且创建项目demo。
sudo yum install openssh-server

sudo yum install postfix

sudo yum install cronie

sudo service postfix start

sudo chkconfig postfix on

sudo lokkit -s http -s ssh

使用清华大学gitlab的镜像https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null
vi /etc/yum.repos.d/gitlab-ce.repo

 

[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
然后
sudo yum makecache
sudo yum install gitlab-ce 

然后打开/etc/gitlab/gitlab.rb,将external_url = 'http://git.example.com'修改为自己的IP地址或者自己的域名,然后编译,这里会用chef来进行,
sudo gitlab-ctl reconfigure
这样如果没有报错就是安装完成了

直接在浏览器访问刚才修改的自己的ip或者域名,就能看到gitlab的页面了,登陆用下面的用户名和密码。
Username: root 
Password: 5iveL!fe

登陆后会要求你更改密码的。

 

接下来进行配置

配置smtp
$ sudo vi /etc/gitlab/gitlab.rb                            
# Change the external_url to the address your users will type in their browser
external_url 'http://xxhost.com'

#Sending application email via SMTP
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25 
gitlab_rails['smtp_user_name'] = "xxuser@163.com"
gitlab_rails['smtp_password'] = "xxpassword"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = :login
gitlab_rails['smtp_enable_starttls_auto'] = true

##修改gitlab配置的发信人
gitlab_rails['gitlab_email_from'] = "xxuser@163.com"
user["git_user_email"] = "xxuser@163.com"

 注意163,qq什么的记得加白名单,不然可能当成垃圾邮件了。。。

然后再编译下

sudo gitlab-ctl reconfigure

 

登陆去修改下自己的邮箱,在profile里面

 

创建一个新的group,命名为devops

在这个组里创建一个新的project,命名为openstack

成功后会在顶部提示你添加ssh密钥,点开后提示你怎么创建

在主机上
# ssh-keygen -C user@XX.com

然后空格继续,最后会在~/.ssh/下看到公钥,复制到页面中那里就行。

 

然后注册一个新的用户wenbin,这里会要你输入邮箱验证,这里可以看到邮箱会收到之前设置smtp中邮件发送的邮件,激活就行。

然后去主机生成一个新的用户,生成ssh的key。

 

用root登陆dashboard,然后把wenbin用户添加到devops这个组中,权限为reporter

然后用wenbin登陆,可以看到了openstack的project,然后添加sshkey,这样就可以pull这个项目了。

 

安装git:    sudo yum install git,

然后就可以克隆代码了:

git clone git@gitlab.wenbin.com:devops/openstack.git

会提示你克隆了一个空目录

[wenbin@gitlab ~]$ git clone git@gitlab.wenbin.com:devops/openstack.git
Cloning into 'openstack'...
warning: You appear to have cloned an empty repository.

[wenbin@gitlab ~]$ cd openstack/
[wenbin@gitlab openstack]$ ll
total 0
[wenbin@gitlab openstack]$ git config user.name wenbin
[wenbin@gitlab openstack]$ git config user.email lxxx@163.com
[wenbin@gitlab openstack]$ vim test.txt
[wenbin@gitlab openstack]$ ll
total 4
-rw-rw-r--. 1 wenbin wenbin 5 Mar 30 23:47 test.txt
[wenbin@gitlab openstack]$ git add .
[wenbin@gitlab openstack]$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   test.txt
#
[wenbin@gitlab openstack]$ git commit -m 'for test'
[master (root-commit) 42eb67c] for test
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
[wenbin@gitlab openstack]$ git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

GitLab: You are not allowed to push code to this project.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

可以看到提示push失败,因为wenbin只是reporter

当权限改为developer后,再次执行

git push -u origin master
就发现可以成功的push了



到此为止,centos7安装gitlab,配置smtp,建立用户和项目,clone代码和push已经ok,期待后面的gerrit和jenkins的整合吧。


参考资料:

http://blog.csdn.net/williamwanglei/article/details/38498465
https://about.gitlab.com/downloads/#centos7
https://segmentfault.com/a/1190000002722631

 

 

 


 
posted @ 2016-04-09 19:08  juandx  阅读(6542)  评论(1编辑  收藏  举报