最近研究SpringCloud,代碼通常都託管到GitGub上,偶爾也用碼雲。可是本身想搭一套代碼管理系統,因而準備在電腦的ubuntu虛擬機中搭建gitlab,整個過程花了一天多的時間,這裏記錄一下安裝和使用遇到的一些問題。git
個人Ubuntu版本是15.04,版本有點舊,ubuntu官方應該已經中止對這個版本的更新了,apt-get update 和 install 的時候通常會報404,這裏須要換一下鏡像源,推薦使用清華大學的源或者阿里源ubuntu
1. 備份系統自帶源 mv /etc/apt/sources.list /etc/apt/sources.list.bak 2. 修改/etc/apt/sources.list文件 #此處爲阿里源 deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial universe deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties deb http://archive.canonical.com/ubuntu xenial partner deb-src http://archive.canonical.com/ubuntu xenial partner deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse #此處爲清華大學源(二選一) deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse 3. 修改完文件,執行一下更新命令 sudo apt-get update
好的,到這裏咱們就更新成功了bash
若是按照官網提供的安裝命令來安裝,通常成功不了,這裏很尷尬,由於網絡的緣由大部分都是失敗的網絡
#官網命令 #安裝相關依賴 sudo apt-get install curl openssh-server ca-certificates postfix #下載和安裝 sudo curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash sudo apt-get install gitlab-ce
執行到這裏失敗的同窗請跟我走,咱們用清華大學開源鏡像站提供的Gitlab Community Edition 鏡像使用幫助再試一遍ssh
#首先信任 GitLab 的 GPG 公鑰: curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null # sudo vi /etc/apt/sources.list.d/gitlab-ce.list #把如下內容複製進去 deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu trusty main #好的,咱們能夠開始下載GitLab,這會佔用咱們幾分鐘 sudo apt-get install gitlab-ce
若是你看到了這個玩意兒 curl
你能夠恭喜本身下載成功啦~gitlab
咱們要作一些配置來完善咱們的GitLabpost
#初始化配置(這個命令不能亂用,配置完以後用一下就廢了) sudo gitlab-ctl reconfigure #配置訪問GitLab的地址和端口 sudo vi /etc/gitlab/gitlab.rb #修改external url的值,個人是 external url='http://localhost:1024' #注意這裏雖然配好了地址和端口,但也只能在本地訪問,咱們須要對外界放開各項端口才能正常使用 #查看UFW防火牆狀態 sudo ufw status #若是顯示的是inactive,那麼咱們須要開啓一下防火牆 sudo ufw enable #打開http、https、ssh和1024端口(注意這裏,你不打開相關端口,在物理機上就不能經過地址和端口訪問到GitLab頁面) sudo ufw allow ssh sudo ufw allow http sudo ufw allow https sudo ufw allow 1024 #OK再看一下端口狀態 sudo ufw status
看到它們都開啓,你就能夠放心了,你能夠分別在虛擬機裏或者物理機來訪問到GitLab頁面,物理機訪問的時候記得把localhost換成你的IP地址~url