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

 

 

 


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM