一、gitlab介紹
gitlab官方地址:https://about.gitlab.com/
GitLab是利用 Ruby on Rails 一個(gè)開源的版本管理系統(tǒng),實(shí)現(xiàn)一個(gè)自托管的Git項(xiàng)目倉(cāng)庫(kù),可通過(guò)Web界面進(jìn)行訪問公開的或者私人項(xiàng)目。它擁有與Github類似的功能,能夠?yàn)g覽源代碼,管理缺陷和注釋??梢怨芾韴F(tuán)隊(duì)對(duì)倉(cāng)庫(kù)的訪問,它非常易于瀏覽提交過(guò)的版本并提供一個(gè)文件歷史庫(kù)。團(tuán)隊(duì)成員可以利用內(nèi)置的簡(jiǎn)單聊天程序(Wall)進(jìn)行交流。它還提供一個(gè)代碼片段收集功能可以輕松實(shí)現(xiàn)代碼復(fù)用,便于日后有需要的時(shí)候進(jìn)行查找。
gitlab就是一個(gè)代碼倉(cāng)庫(kù),能夠非常好地實(shí)現(xiàn)對(duì)代碼的管理和開發(fā)人員之間的團(tuán)隊(duì)協(xié)作。目前應(yīng)用最為廣泛地就是利用jenkins和gitlab實(shí)現(xiàn)持續(xù)集成和部署。官方的推薦配置為2核心CPU和4G內(nèi)存,這是因?yàn)間itlab的整體運(yùn)行包含了多個(gè)進(jìn)程,如:nginx、postgresql、prometheus、redis等等。
為此,這里使用docker-compose進(jìn)行單機(jī)部署gitlab中文社區(qū)版本,讓大家更好地體會(huì)gitlab的強(qiáng)大功能,其余廢話就不多說(shuō)了,直接開擼就對(duì)了??!
二、安裝Docker
1.安裝docker依賴包
[root@gitlab ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
2.添加Docker-ce鏡像源并安裝
1.1)國(guó)外源(適合在國(guó)外工作的朋友)
[root@gitlab ~]# yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
1.2)國(guó)內(nèi)阿里云源(適合在國(guó)內(nèi)工作的朋友)
[root@gitlab ~]# yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2)服務(wù)器的包信息下載到本地電腦緩存起來(lái)
[root@gitlab ~]# yum makecache fast
3)安裝docker CE
[root@gitlab ~]# yum -y install docker-ce
4)配置下載docker鏡像加速器
國(guó)外加速器:
[root@gitlab ~]# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://bc437cce.m.daocloud.io
國(guó)內(nèi)阿里云加速器:
vim /etc/docker/daemon.json
#輸入下面內(nèi)容并保存:
{
"registry-mirrors": [https://9w1hl6qt.mirror.aliyuncs.com]
}
5)重載systemctl并自動(dòng)和開啟自啟動(dòng)docker
[root@gitlab ~]# systemctl daemon-reload
[root@gitlab ~]# systemctl start docker
[root@gitlab ~]# systemctl enable docker
[root@gitlab ~]# docker --version
Docker version 18.09.0, build 4d60db4
三、安裝Docker-compose
下載Docker-compose二進(jìn)制文件并添加執(zhí)行權(quán)限
[root@gitlab ~]# curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s-uname -m` -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 590 0 --:--:-- 0:00:01 --:--:-- 590
100 11.2M 100 11.2M 0 0 498k 0 0:00:23 0:00:23 --:--:-- 737k
[root@gitlab ~]# chmod +x /usr/local/bin/docker-compose
[root@gitlab ~]# docker-compose --version
docker-compose version 1.23.2, build 1110ad01
四、安裝Gitlab
1)編輯docker-compose的yml文件
[root@gitlab ~]# mkdir gitlab
[root@gitlab ~]# cd gitlab
[root@gitlab gitlab]# vim docker-compose.yml
version: '2'
services:
gitlab:
image: 'twang2218/gitlab-ce-zh:latest'
container_name: "gitlab"
restart: unless-stopped
privileged: true
hostname: 'gitlab'
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://ip或者用nginx做反代的域名'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxxxx@163.com"
gitlab_rails['smtp_password'] = "授權(quán)碼"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxxxx@163.com'
gitlab_rails['gitlab_shell_ssh_port'] = 22
ports:
- '8181:80'
- '8443:443'
- '22:22'
volumes:
- /opt/gitlab/config:/etc/gitlab
- /opt/gitlab/data:/var/opt/gitlab
- /opt/gitlab/logs:/var/log/gitlab
端口映射說(shuō)明以及注意事項(xiàng):
- gitlab鏡像官方推薦容器80端口映射宿主機(jī)8181端口
- gitlab鏡像官方推薦容器443端口映射宿主機(jī)8443端口
- gitlab鏡像官方推薦容器22端口映射宿主機(jī)22端口
⭐️頭兩行不能頂頭寫,要分別都空一行,可以去yml文件檢測(cè)網(wǎng)站進(jìn)行檢測(cè):
https://www.bejson.com/validators/yaml_editor/
如你們的檢測(cè)如下圖所示,則表示yml文件完全無(wú)誤:
下面是在我linux服務(wù)器上看到的情況:
2)創(chuàng)建相關(guān)目錄
[root@gitlab gitlab]# mkdir -p /opt/gitlab/{config,data,logs}
[root@gitlab gitlab]# ls -l /opt/gitlab/
total 0
drwxr-xr-x 2 root root 6 Dec 22 12:03 config
drwxr-xr-x 2 root root 6 Dec 22 12:03 data
drwxr-xr-x 2 root root 6 Dec 22 12:03 logs
目錄說(shuō)明如下:
- config 存儲(chǔ) GitLab 配置信息
- data 存儲(chǔ)數(shù)據(jù)庫(kù)
- logs 存儲(chǔ)日志
3)拉取gitlab中文版鏡像
[root@gitlab gitlab]# docker pull twang2218/gitlab-ce-zh:latest
latest: Pulling from twang2218/gitlab-ce-zh
8ee29e426c26: Pull complete
6e83b260b73b: Pull complete
e26b65fd1143: Pull complete
40dca07f8222: Pull complete
b420ae9e10b3: Pull complete
a218309dd589: Pull complete
5c60fd7ba0ce: Pull complete
659c2144b5a3: Pull complete
8289bbac0d0e: Pull complete
31bbd150e8a7: Pull complete
9114e78243fa: Pull complete
e242e5cd1314: Pull complete
0a079dc3f92c: Pull complete
f0e195b09fd2: Pull complete
6e23346e2f58: Pull complete
91f00659be69: Pull complete
a1031bcc5b2c: Pull complete
e3074327c7b1: Pull complete
a917618dbe42: Pull complete
Digest: sha256:62686b74c6fca5ece8ed582d03a126c5988423dd8a19ce70e9a22357ffcaf1c8
Status: Downloaded newer image for twang2218/gitlab-ce-zh:latest
[root@gitlab gitlab]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
twang2218/gitlab-ce-zh latest 18da462b5ff5 4 months ago 1.61GB
4)啟動(dòng)gitlab的容器
在啟動(dòng)前,先要修改宿主機(jī)的22端口,因?yàn)樗拗鳈C(jī)占用了22端口,所以啟動(dòng)容器會(huì)失敗,因?yàn)橛成洳贿^(guò)來(lái),修改如下:
vim /etc/ssh/sshd_config
默認(rèn)在第17行修改:Port 2222
修改后,重啟sshd:systemctl restart sshd
[root@gitlab gitlab]# netstat -tulnp | grep 22
tcp 0 0 0.0.0.0:2222 0.0.0.0: LISTEN 31889/sshd
tcp6 0 0 :::2222 ::: LISTEN 31889/sshd
正式啟動(dòng):
[root@gitlab gitlab]# docker-compose up -d
Creating network "gitlab_default" with the default driver
Creating gitlab ... done
[root@gitlab gitlab]# docker-compose ps
Name Command State Ports
gitlab /assets/wrapper Up (healthy) 0.0.0.0:22->22/tcp, 0.0.0.0:8443->443/tcp, 0.0.0.0:8181->80/tcp
[root@gitlab gitlab]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
814e559dc728 twang2218/gitlab-ce-zh:latest "/assets/wrapper" 5 minutes ago Up 5 minutes (healthy) 0.0.0.0:22->22/tcp, 0.0.0.0:8181->80/tcp, 0.0.0.0:8443->443/tcp gitlab
5)gitlab設(shè)置開機(jī)啟動(dòng)
[root@gitlab gitlab]# chmod +x /etc/rc.local
[root@gitlab gitlab]# ls -l /etc/rc.local
lrwxrwxrwx 1 root root 13 Dec 3 14:31 /etc/rc.local -> rc.d/rc.local
[root@gitlab gitlab]# echo "cd /root/gitlab && docker-compose up -d" >> /etc/rc.local
[root@gitlab gitlab]# tail -1 /etc/rc.local
cd /root/gitlab && docker-compose up -d
6)gitlab管理界面
地址:在瀏覽器輸入yml文件的第12行ip或者域名
用戶:root
密碼:首次登陸需要手動(dòng)設(shè)置密碼
如下圖所示:
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。