码迷,mamicode.com
首页 > 其他好文 > 详细

gitlab搭建与基本使用

时间:2018-05-10 15:35:10      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:gitlab

一、git、github、gitlab的区别
Git是版本控制系统,Github是在线的基于Git的代码托管服务。
GitHub是2008年由Ruby on Rails编写而成。GitHub同时提供付费账户和免费账户。这两种账户都可以创建公开的代码仓库,只有付费账户可以创建私有的代码仓库。
Gitlab解决了这个问题, 可以在上面创建免费的私人repo。
二、gitlab server搭建过程
yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
//10.x以后开始依赖policycoreutils-python
systemctl start postfix
systemctl enable postfix
gitlab的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
安装gitlab:
[root@vm1 ~]# rpm -ivh gitlab-ce-10.7.2-ce.0.el7.x86_64.rpm
warning: gitlab-ce-10.7.2-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-10.7.2-ce.0.el7 ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade script.

   *.                  *.
  ***                 ***
 *****               *****
.******             *******
********            ********

,,,,,,,,,**,,,,,,,,,
,,,,,,,,,,,
,,,,,,,,,,,
.,,,,,,,,,,,**,,,,,,,,,,,,
,,,,,,,,,
,,,,,,,,,.
,,,,,,,*,,,,,,
.,,,
,,,,
,*,.

 _______ __  __          __
/ ____(_) /_/ /   ____ _/ /_

/ / / / / / / `/ \
/ // / / // // // / // /
____/
/__/___
/_,/_.___/

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting external_url
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

[root@vm1 ~]#

gitlab的配置文件 /etc/gitlab/gitlab.rb, 编辑如下:
[root@vm1 ~]# vim /etc/gitlab/gitlab.rb
[root@vm1 ~]# grep "^external_url" /etc/gitlab/gitlab.rb
external_url ‘http://192.168.60.119‘ 绑定监听的域名或IP
[root@vm1 ~]#

使用gitlab-ctl reconfigure 自动配置,并安装数据库,初始化信息,如下所示(第一次使用配置时间较长):
[root@vm1 ~]# gitlab-ctl reconfigure
.....

使用gitlab-ctl start 启动gitlab服务,如下所示:
[root@vm1 ~]# gitlab-ctl start
ok: run: gitaly: (pid 22896) 2922s
ok: run: gitlab-monitor: (pid 22914) 2921s
ok: run: gitlab-workhorse: (pid 22882) 2922s
ok: run: logrotate: (pid 22517) 2987s
ok: run: nginx: (pid 22500) 2993s
ok: run: node-exporter: (pid 22584) 2974s
ok: run: postgres-exporter: (pid 22946) 2919s
ok: run: postgresql: (pid 22250) 3047s
ok: run: prometheus: (pid 22931) 2920s
ok: run: redis: (pid 22190) 3053s
ok: run: redis-exporter: (pid 22732) 2962s
ok: run: sidekiq: (pid 22472) 3005s
ok: run: unicorn: (pid 22433) 3011s
[root@vm1 ~]#
[root@vm1 ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 22500 root 7u IPv4 50923 0t0 TCP :http (LISTEN)
nginx 22501 gitlab-www 7u IPv4 50923 0t0 TCP
:http (LISTEN)
[root@vm1 ~]#

修改配置文件,添加smtp邮件功能
[root@vm1 ~]# vim /etc/gitlab/gitlab.rb
[root@vm1 ~]# grep -P "^[^#].*smtp_|user_email|gitlab_email" /etc/gitlab/gitlab.rb
gitlab_rails[‘gitlab_email_enabled‘] = true
gitlab_rails[‘gitlab_email_from‘] = ‘username@domain.cn‘
gitlab_rails[‘gitlab_email_display_name‘] = ‘Admin‘
gitlab_rails[‘gitlab_email_reply_to‘] = ‘usernamei@domain.cn‘
gitlab_rails[‘gitlab_email_subject_suffix‘] = ‘[gitlab]‘
gitlab_rails[‘smtp_enable‘] = true
gitlab_rails[‘smtp_address‘] = "smtp.exmail.qq.com"
gitlab_rails[‘smtp_port‘] = 25
gitlab_rails[‘smtp_user_name‘] = "username@domain.cn"
gitlab_rails[‘smtp_password‘] = "password"
gitlab_rails[‘smtp_domain‘] = "domain.cn"
gitlab_rails[‘smtp_authentication‘] = "login"
gitlab_rails[‘smtp_enable_starttls_auto‘] = true
gitlab_rails[‘smtp_tls‘] = false
user[‘git_user_email‘] = "username@domain.cn"

[root@vm1 ~]# gitlab-ctl reconfigure
......

[root@vm1 ~]# gitlab-ctl stop
ok: down: gitaly: 0s, normally up
ok: down: gitlab-monitor: 1s, normally up
ok: down: gitlab-workhorse: 0s, normally up
ok: down: logrotate: 1s, normally up
ok: down: nginx: 0s, normally up
ok: down: node-exporter: 1s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 0s, normally up
ok: down: redis: 0s, normally up
ok: down: redis-exporter: 1s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 1s, normally up

[root@vm1 ~]# gitlab-ctl start
ok: run: gitaly: (pid 37603) 0s
ok: run: gitlab-monitor: (pid 37613) 0s
ok: run: gitlab-workhorse: (pid 37625) 0s
ok: run: logrotate: (pid 37631) 0s
ok: run: nginx: (pid 37639) 1s
ok: run: node-exporter: (pid 37644) 0s
ok: run: postgres-exporter: (pid 37648) 1s
ok: run: postgresql: (pid 37652) 0s
ok: run: prometheus: (pid 37660) 1s
ok: run: redis: (pid 37668) 0s
ok: run: redis-exporter: (pid 37746) 0s
ok: run: sidekiq: (pid 37750) 1s
ok: run: unicorn: (pid 37757) 0s

使用gitlab-rails console命令进行发送邮件测试,如下所示:
[root@vm1 ~]# gitlab-rails console
Loading production environment (Rails 4.2.10)
irb(main):001:0> Notify.test_email(‘user@destination.com‘, ‘Message Subject‘, ‘Message Body‘).deliver_now

Notify#test_email: processed outbound mail in 2219.5ms

Sent mail to user@destination.com (2469.5ms)
Date: Fri, 04 May 2018 15:50:10 +0800
From: Admin <username@domain.cn>
Reply-To: Admin <username@domain.cn>
To: user@destination.com
Message-ID: <5aec10b24cfaa_93933fee282db10c162d@vm1.mail>
Subject: Message Subject
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">;
<html><body><p>Message Body</p></body></html>

=> #<Mail::Message:70291731344240, Multipart: false, Headers: <Date: Fri, 04 May 2018 15:50:10 +0800>, <From: Admin <username@domain.cn>>, <Reply-To: Admin <username@domain.cn>>, <To: user@destination.com>, <Message-ID: <5aec10b24cfaa_93933fee282db10c162d@vm1.mail>>, <Subject: Message Subject>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):002:0>quit
[root@vm1 ~]#

在浏览器中输入 http://192.168.60.119/ ,然后 change password: ,并使用root用户登录 即可 (后续动作根据提示操作)
修改密码也可以:gitlab-rails console production
irb(main):001:0> user = User.where(id: 1).first // id为1的是超级管理员
irb(main):002:0>user.password = ‘yourpassword‘ // 密码必须至少8个字符
irb(main):003:0>user.save! // 如没有问题 返回true
exit // 退出
技术分享图片

gitlab搭建与基本使用

标签:gitlab

原文地址:http://blog.51cto.com/caiyuanji/2114796

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!