gitlab版本控制

[TOC]

1.版本控制介绍

定义

版本控制是指对软件开发过程中各种代码程序、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。

功能

  • 追踪文件的变更
  • 并行开发

常用的版本控制工具:

  • gitlab
  • suversion

2.gitlab部署

关闭防火墙以及SELINUX

[root@linfan ~]# systemctl stop firewalld
[root@linfan ~]# systemctl disable firewalld
[root@linfan ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@linfan ~]# setenforce 0

配置yum源

[root@linfan ~]# cd /etc/yum.repos.d/
[root@linfan yum.repos.d]# curl -o 163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1572  100  1572    0     0    279      0  0:00:05  0:00:05 --:--:--   382
[root@linfan yum.repos.d]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/163.repo
[root@linfan yum.repos.d]# sed -i 's/^enabled=.*/enabled=1/g' 163.repo
[root@linfan yum.repos.d]# yum -y install epel-release  

安装git

[root@linfan ~]# yum -y install git

安装依赖包

[root@linfan ~]#  yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python   

启动postfix服务并设置开机自启动

[root@linfan ~]# systemctl restart postfix
[root@linfan ~]# systemctl enable postfix

下载gitlab的rmp包

[root@linfan ~]# cd /usr/src
[root@linfan src]# ls
debug  kernels
[root@linfan src]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/y
--2018-09-04 02:35:08--  https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/y
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... um/el7/gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2018-09-04 02:35:09 ERROR 404: Not Found.

[root@linfan src]# um/el7/gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm
-bash: um/el7/gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm: No such file or directory
[root@linfan src]# cd
[root@linfan ~]# cd /usr/src
[root@linfan src]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm
--2018-09-04 02:35:59--  https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm
Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193, 2402:f000:1:408:8100::1
Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 444944490 (424M) [application/x-redhat-package-manager]
Saving to: ‘gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm’

100%[================================================================================>] 444,944,490 5.76MB/s   in 71s

2018-09-04 02:37:10 (5.96 MB/s) - ‘gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm’ saved [444944490/444944490]

[root@linfan src]# ls
debug  gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm  kernels

安装gitlab

[root@linfan src]# rpm -ivh gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm
warning: gitlab-ce-11.2.1-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:gitlab-ce-11.2.1-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@linfan ~]# vim /etc/gitlab/gitlab.rb

...
...
## GitLab URL
##! URL on which GitLab will be reachable.
##! For more details on configuring external_url see:
##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
external_url 'http://192.168.24.130' 修改此处为自己的IP或域名

## Roles for multi-instance GitLab
##! The default is to have no roles enabled, which results in GitLab running as an all-in-one instance.
##! Options:
##!   redis_sentinel_role redis_master_role redis_slave_role geo_primary_role geo_secondary_role
##! For more deatils on each role, see:
##! https://docs.gitlab.com/omnibus/roles/README.html#roles
##!
# roles ['redis_sentinel_role', 'redis_master_role']
...
...

重新加载配置文件并重启gitlab

[root@linfan ~]# gitlab-ctl reconfigure 
[root@linfan ~]# gitlab-ctl restart

查看当前gitlab版本

[root@linfan ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 11.2.1

设置管理员密码

[root@linfan ~]# gitlab-rails console production
-------------------------------------------------------------------------------------
 GitLab:       11.2.1 (2d6c1c6)
 GitLab Shell: 8.1.1
 postgresql:   9.6.8
-------------------------------------------------------------------------------------
Loading production environment (Rails 4.2.10)
irb(main):001:0> user = User.where(id: 1).first //id为1是超级管理员
=> #<User id:1 @root>
irb(main):002:0>  user.password = 'linfan123'//密码至少8个字符
=> "linfan123"
irb(main):003:0> user.save! //保存修改,无问题则返回true
Enqueued ActionMailer::DeliveryJob (Job ID: feb0d3ec-534f-4e87-9dad-ceafbae40a53) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1
=> true
irb(main):004:0> exit //退出

gitlab管理

在浏览器输入IP或域名地址

gitlab版本控制
gitlab版本控制

进去后创建groups users projects 选择Settings下的Members添加项目的成员或组
gitlab版本控制

gitlab常用管理操作

  • 项目管理(通常只是创建新项目)
  • 创建成员组(真对某个项目创建一个成员组)
  • 用户管理(此用户是gitlab用户而非系统用户)

    • 来了新员工 为其添加gitlab用户
    • 员工离职,将其gitlab用户禁用或删除