1. 程式人生 > >『中級篇』docker之CI/CD持續集成-gitlab安裝(70)

『中級篇』docker之CI/CD持續集成-gitlab安裝(70)

num png work 保存 pat scrip systemctl memory lan

>原創文章,歡迎轉載。轉載請註明:轉載自IT人故事會,謝謝!
>原文鏈接地址:『中級篇』docker之CI/CD持續集成-gitlab安裝(70)

gitlab在持續化集成中非常的重要,它用於開發人員進行提交代碼關於代碼的庫,本次安裝還是使用vagrant的方式。源碼:https://github.com/limingios/docker/tree/master/No.11

創建虛擬機

  • vagrant文件的配置
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.require_version ">= 1.6.0"

boxes = [
    {
        :name => "gitlab",
        :mem => "4096",
        :cpu => "2"
    }
]

Vagrant.configure(2) do |config|

  config.vm.box = "centos/7"
  boxes.each do |opts|
    config.vm.define opts[:name] do |config|
      config.vm.hostname = opts[:name]
      config.vm.provider "vmware_fusion" do |v|
        v.vmx["memsize"] = opts[:mem]
        v.vmx["numvcpus"] = opts[:cpu]
      end
      config.vm.provider "virtualbox" do |v|
        v.customize ["modifyvm", :id, "--memory", opts[:mem]]
        v.customize ["modifyvm", :id, "--cpus", opts[:cpu]]
      end
      config.vm.network :private_network, type: "dhcp"
    end
  end
  config.vm.provision "shell", privileged: true, path: "./setup.sh"
end
  • setup.sh的配置
    
    #/bin/sh

sudo yum install -y yum upgrade
sudo yum install -y net-tools
sudo yum install -y curl policycoreutils openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install -y postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http

sudo systemctl reload firewalld

sudo yum install -y java-1.8.0-openjdk.x86_64

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

![](https://upload-images.jianshu.io/upload_images/11223715-e0a8e65cf1af2320.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

### 執行命令創建
``` cmd
#源碼No.11的gitlab目錄
vagrant up

技術分享圖片

技術分享圖片

更改安裝源

新建 /etc/yum.repos.d/gitlab-ce.repo,內容為

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
  • 執行命令
    sudo yum makecache
    sudo yum install gitlab-ce
  • 安裝成功!

技術分享圖片

  • 運行下面的命令進行配置

    sudo gitlab-ctl reconfigure
  • 查看ip地址
    ip a

技術分享圖片

登錄網址

#登錄,修改root密碼。並登錄 用戶名是root,密碼是剛設置的
http://172.28.128.3

技術分享圖片

技術分享圖片

修改主機的名字

技術分享圖片

sudo vi /etc/gitlab/gitlab.rb
#上邊的修改保存後,需要執行下面的命令才可以生效
 sudo gitlab-ctl reconfigure

技術分享圖片

技術分享圖片

關機後,重啟gitlab的命令


gitlab-ctl restart 
···

PS:gitlab安裝基本就是這樣也不是很復雜,主要是必須更改源,國內的墻太高太寬了。

![](http://upload-images.jianshu.io/upload_images/11223715-3407e1c7ac8d7935?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

『中級篇』docker之CI/CD持續集成-gitlab安裝(70)