在Linux中搭建GitLab

gitlab是一個開源的git倉庫管理軟件,並提供web界面,方便管理git倉庫。考慮到安全、費用,公司一般選擇搭建自己的gitlab服務器。

本文將按照官方文檔安裝步驟,一步步進行gitlab的安裝。

查看Linux版本信息

查看Linux系統的版本信息:

cat /proc/version

查看Linux系統發行版信息:

cat /etc/redhat-release

安裝和配置必要的依賴

https://docs.gitlab.com/ee/install/README.html

在Linux系統中安裝gitlab,對系統的相關最低要求,可以點擊如下圖橢圓標註內容進行查看。

使用官方的rpm安裝包進行安裝

進入如下圖頁面,根據當前Linux系統版本情況進行選擇,此處選擇CentOS7

https://about.gitlab.com/install/

安裝和配置必要的依賴

sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

此處,對於通知郵件的相關指令暫時先不執行。

上圖中提示“FirewallD is not running”問題。執行如下指令查看firewalld狀態,結果當前是dead狀態,即防火牆未開啓

systemctl status firewalld

執行如下指令,開啓防火牆

systemctl start firewalld

此時,再次查看防火牆的狀態

systemctl status firewalld

此時,再次嘗試執行如下指令,查看是否問題已解決。

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld

從上圖可以看到,已經執行成功。

下載和安裝gitlab

執行如下指令,獲取安裝腳本,自行安裝所有依賴包。

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

接着,執行如下指令,開始安裝,EXTERNAL_URL爲安裝後進入該GitLab的頁面地址,最好設置成你的“服務器ip/gitlab”,如果此時不設置,後面需要修改其配置文件的相關ip地址,此處,暫時使用其默認的值,然後後續修改配置文件。

sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ee

此時,安裝完成。

修改gitlab配置文件

vi /etc/gitlab/gitlab.rb

修改上圖中橢圓標註的內容爲當前Linux系統實際的ip地址和給gitlab分配的端口號。如下

https://192.168.0.21:8600

由於在上文中防火牆已開啓,則需要把相應的端口8600放開。

firewall-cmd --zone=public --add-port=8600/tcp --permanent

使gitlab的配置文件生效

sudo gitlab-ctl reconfigure

 

重啓gitlab

sudo gitlab-ctl restart

此時,在瀏覽器中輸入gitlab的ip和端口號,無法訪問。

linux系統開放8600端口

cd /etc/sysconfig
ls -l

沒有查看到iptables文件,但存在ip6tables-config和iptables-config,本文中的linux爲CentOS 7.6 ,CentOS 7默認沒有了iptables文件。

安裝iptables-services

yum install iptables-services

啓動iptables

systemctl enable iptables 

systemctl start iptables 

在iptables中配置開放8600端口

vim /etc/sysconfig/iptables

 

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8600 -j ACCEPT

重啓防火牆

service iptables restart

 

首次進入gitlab

首次進入,會被導向到一個重置密碼的頁面,設置完成後會被導向到登錄頁面,可以使用默認賬號root進行登錄。

此時,在瀏覽器中訪問,出現了gitlab頁面,https://gitlab的ip:端口

 

登錄成功後,進入到主操作頁面,如下圖。

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章