使用的 Ubuntu Server 16.04 LTS 版本,服務器托管在 Azure 上,用的 1 元試用 1 個月服務器訂閱(1500 元額度)。
安裝命令(推薦使用):
curl -sS http://packages.gitlab.com.cn/install/gitlab-ce/script.deb.sh | sudo bash
sudo apt-get install gitlab-ce
也可以下載程序包進行安裝,程序包地址:
- 國內地址(只有
*.deb
程序包): https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/ - 官方地址:https://packages.gitlab.com/gitlab/gitlab-ce
*.rmp
程序包,安裝命令(例如 Centos 系統):
curl -O https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.4.5-ce.0.el7.x86_64.rpm
sudo rpm -i gitlab-ce-9.4.5-ce.0.el7.x86_64.rpm
*.deb
程序包,安裝命令(例如 Ubuntu 系統):
curl -O https://packages.gitlab.com/gitlab/gitlab-ce/packages/ubuntu/xenial/gitlab-ce_9.4.5-ce.0_amd64.deb
sudo dpkg -i gitlab-ce_9.4.5-ce.0_amd64.deb
注:在 Ubuntu 安裝*.deb
程序包,需要進行文件轉換,比較麻煩些,而且容易失敗,參考:ubuntu 安裝 deb,rpm 安裝包方法
我最后就采用的是官方安裝命令,一開始安裝的時候速度很慢,后來不知道怎么回事就變快了。
安裝好之后,會有這樣的提示:
然后,打開vim /etc/gitlab/gitlab.rb
文件,將external_url = 'http://git.example.com'
修改成自己的 IP 或者 HostName,比如:
external_url = 'http://40.125.201.71'
最后需要配置 GitLab 的發件郵箱,GitLab 默認使用postfix
郵件服務器,如果沒有安裝的話,需要安裝下(安裝過程會有圖形界面選項,一直會車就行了):
sudo apt-get install postfix
也可以安裝mail
命令,進行命令測試發送郵件
sudo apt-get install mailutils
安裝好之后,我們可以使用下面命令,測試發布發送郵件:
echo "Test mail from postfix" | mail -s "Test Postfix" 624541997@qq.com
收到郵件后,把系統發件郵箱地址記下來,然后再打開vim /etc/gitlab/gitlab.rb
文件,將gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'
修改為系統發件郵箱地址:
gitlab_rails['gitlab_email_from'] = 'root@xishuai-ubuntu-01.xxx.ax.internal.chinacloudapp.cn'
上面這些配置好之后,就可以啟動 GitLab 了:
sudo gitlab-ctl reconfigure
每次配置更改之后,都需要執行上面命令,GitLab 啟動好之后,瀏覽器輸入 http://40.125.201.71 地址,初始化下 root 管理員密碼,下面就可以正常使用了。
郵箱回復測試的也是可以的,只不過會放到垃圾箱里,如下:
如果使用 Azure,需要配置 80 端口訪問:
另外,Azure 提供了 GitLab 的鏡像文件,可以進行一鍵安裝使用,還是很方便的(參考:How to Setup a GitLab Instance on Microsoft Azure):
最后,附上 GitLab 常用命令:
常用命令 | 說明 |
---|---|
sudo gitlab-ctl reconfigure | 重新加載配置,每次修改/etc/gitlab/gitlab.rb 文件之后執行 |
sudo gitlab-ctl status | 查看 GitLab 狀態 |
sudo gitlab-ctl start | 啟動 GitLab |
sudo gitlab-ctl stop | 停止 GitLab |
sudo gitlab-ctl restart | 重啟 GitLab |
sudo gitlab-ctl tail | 查看所有日志 |
sudo gitlab-ctl tail nginx/gitlab_acces.log | 查看 nginx 訪問日志 |
sudo gitlab-ctl tail postgresql | 查看 postgresql 日志 |
參考資料:
文章列表