開心一刻
睡着正香,媳婦用力把我晃醒說:“快起來,我爸來了。”
我一下醒了,手腳熟練的把衣服一抱,滾到床底,順便把鞋也收了進去
媳婦蹲下無奈的說:“快出來!咱倆都結婚半年了。”
我:“對哦,搞習慣了”
環境准備
linux:CentOS 7
GitLab 社區版:gitlab-ce-12.8.7-ce.0.el6.x86_64.rpm,可從 清華大學開源軟件鏡像站 下載
因為 GitLab 對內存要求比較高,官方推薦至少准備 4G 內存來安裝 GitLab,我們就大方一點,准備 5G
環境准備如下
樓主是新搭建的 CentOS 7,環境非常干凈,便於 GitLab 的搭建(主要是避免端口沖突,GitLab 包含很多組件,它們都需要端口)
由於我們大天朝的那面牆的神奇作用,按 GitLab 官方的安裝教程,我們沒法安裝它,但辦法總比困難多,具體我們往下看
GitLab 搭建
安裝和配置依賴項
1、安裝依賴項
[root@localhost opt]# yum install -y curl policycoreutils-python openssh-server
2、啟用 sshd
[root@localhost opt]# systemctl enable sshd
[root@localhost opt]# systemctl start sshd
3、防火牆放行 http 和 https
[root@localhost opt]# firewall-cmd --permanent --add-service=http [root@localhost opt]# firewall-cmd --permanent --add-service=https [root@localhost opt]# systemctl reload firewalld
樓主為了省事,直接關了防火牆(上面的做法是比較正經的!)
[root@localhost opt]# firewall-cmd --state
[root@localhost opt]# systemctl stop firewalld.service
[root@localhost opt]# systemctl disable firewalld.service
4、安裝 Postfix
postfix 可用於發電子郵件,是可選依賴
如果用 SMTP 方式來發送,則不需要安裝 postfix
[root@localhost opt]# yum install postfix [root@localhost opt]# systemctl enable postfix [root@localhost opt]# systemctl start postfix
安裝 GitLab
安裝非常簡單,就一行命令
[root@localhost opt]# rpm -ivh gitlab-ce-12.8.7-ce.0.el6.x86_64.rpm --force
安裝應該非常快,分分鍾的事,當出現下圖,就表示安裝完成
配置 GitLab
GitLab 的配置文件路徑: /etc/gitlab/gitlab.rb,為了簡單起見,我們只配置 external_url 和 smtp 相關配置;因為 postfix 發送的郵件會被 QQ 郵件服務器 、新浪郵件服務器等當成垃圾郵件而拒絕接收,所以我們需要開啟 smtp,示例中配置的是 QQ 郵箱服務器,其他的郵件服務器配置可查看:smtp-settings
編輯 gitlab.rb: [root@localhost gitlab]# vi /etc/gitlab/gitlab.rb ,此時我們只修改如下配置項(配置項不是全部挨在一起)
external_url 'http://192.168.0.115' gitlab_rails['gitlab_email_from'] = 'xxx@qq.com' gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.qq.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "xxx@qq.com" gitlab_rails['smtp_password'] = "授權碼" gitlab_rails['smtp_domain'] = "smtp.qq.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true user['git_user_email'] = "xxx@qq.com"
修改之后執行: [root@localhost opt]# gitlab-ctl reconfigure ,使得配置生效
首次配置比較慢,因為需要配置、初始化各個組件;當出現下圖內容時,表示配置完成
配置完成后會生成各個組件的配置文件和日志文件,配置文件路徑: /opt/gitlab/etc/ ,日志文件路徑: /var/log/gitlab/
一旦配置好,GitLab 也就啟動了,我們訪問下: http://192.168.0.115/ ,當出現如下界面,表示我們搭建成功了
初次訪問會提示我們重置 root 賬戶的密碼;登錄進去后,主界面如下
我們再來試試郵件是否可以正常發送,執行命令: [root@localhost opt]# gitlab-rails console 登錄到控制台,然后執行: Notify.test_email('youzhibing2094@sina.com', '郵件主題', '郵件正文').deliver_now 發送測試郵件,能正常收到就證明配置好了
至此,GitLab 基本搭建好了
GitLab 常用命令
啟動:gitlab-ctl start
查看狀態:gitlab-ctl status
重啟:gitlab-ctl restart
重新配置:gitlab-ctl reconfigure # 一般是修改配置后用
查看實時日志:gitlab-ctl tail
總結
1、GitLab 架構圖
組件非常多,更多詳情請查閱:GitLab實戰三——Gitlab架構組件詳解
2、只要環境足夠干凈,內存足夠大,搭建起來應該是沒什么問題的