安裝
系統:centos7 內存4G及以上
GitLab版本:11.6.1-ee
主要參考:https://about.gitlab.com/install/#centos-7 https://blog.csdn.net/musuny/article/details/78548868
https://blog.csdn.net/qq_39256527/article/details/81238055
http://blog.51cto.com/207698/2133703
https://blog.csdn.net/yongche_shi/article/details/78677163
環境配置
1. 允許ssh和http訪問
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 systemctl reload firewalld
2. 下載
如果需要指定版本可以去官網手動下載rpm文件,或者使用yum安裝時指定版本
sudo yum install gitlab-ee-11.6.1-ee.0.el7.x86_64
當前11.6.1-ee版本下載地址
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
3. 使用yum
安裝
原文是
sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ee
之前不知道怎么配置EXTERNAL_URL
所以沒配置這個,安裝完成后可以在配置文件/etc/gitlab/gitlab.rb
里修改。
EXTERNAL_URL
可以使用ip地址
sudo yum install -y gitlab-ee
安裝完畢后會顯示gitlab的logo字符畫
修改配置
vim可以使用
:
+/關鍵詞
搜索,按n
鍵向下查找,shift
+n
向上查找
修改完畢后一定要使用sudo gitlab-ctl reconfigure
刷新,最好再重啟一下sudo gitlab-ctl restart
默認配置會占用80
、8080
端口,使用postgresql
作為數據庫,開啟自帶的redis
、nginx
1. 打開配置文件
vim /etc/gitlab/gitlab.rb
2. 修改訪問地址
如果不指定端口號,默認是80端口,建議使用域名訪問
external_url 'http://192.168.1.123:8086'
修改nginx端口
nginx['listen_port'] = 8086
3. 修改unicorn
端口
unicorn['port'] = 8089
gitlab_workhorse['auth_backend'] = "http://localhost:8089"
4. 修改超時時間
gitlab_rails['webhook_timeout'] = 90
5. 使用mysql
數據庫
安裝mysql2
cd /opt/gitlab/embedded/bin
./gem install mysql2
配置/etc/gitlab/gitlab.rb
postgresql['enable'] = false
gitlab_rails['db_adapter'] = "mysql2"
gitlab_rails['db_encoding'] = "utf8"
# gitlab_rails['db_collation'] = nil
gitlab_rails['db_database'] = "gitlab"
# gitlab_rails['db_pool'] = 10
gitlab_rails['db_username'] = "root"
gitlab_rails['db_password'] = "pass"
gitlab_rails['db_host'] = "127.0.0.1"
gitlab_rails['db_port'] = 3306
6. 配置redis
redis['enable'] = false
gitlab_rails['redis_host'] = "127.0.0.1"
gitlab_rails['redis_port'] = 6379
# gitlab_rails['redis_ssl'] = false
gitlab_rails['redis_password'] = "pass"
gitlab_rails['redis_database'] = 1
7. 配置郵箱
郵箱要開啟SMTP
注意郵箱域名要一致(下方填寫的bb.com
,不是服務器域名)
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'aa@bb.com'
gitlab_rails['gitlab_email_display_name'] = 'bb'
gitlab_rails['gitlab_email_reply_to'] = 'noreply@bb.com'
gitlab_rails['gitlab_email_subject_suffix'] = 'gitlab'
騰訊企業郵的配置 騰訊企業郵文檔
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "aa@bb.com"
gitlab_rails['smtp_password'] = "pass"
gitlab_rails['smtp_domain'] = "bb.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
刷新配置后,可以使用以下命令測試一下
gitlab-rails console
比較慢,等待出現類似Loading production environment (Rails 5.0.7)
后輸入以下命令發送測試郵件
irb(main):001:0>
Notify.test_email('郵箱地址', '主題', '摘要').deliver_now
收到郵件后,使用exit
命令結束
錯誤:501 mail from address must be same as authorization user(郵箱域名不一致)
8. 關閉注冊入口
有兩種方式:
- 修改配置文件
gitlab_rails['registry_enabled'] = false
- 修改系統設置
需要先激活管理員賬號,並且登錄
訪問http://服務器/admin
,例如按照上方配置:http://192.168.1.123:8086/admin
,或者打開主頁后,點擊標題欄Admin Area
(扳手圖標)
左邊標簽欄Settings
-> Sign-up restrictions
-> Expand
-> 去掉Sign-up enabled
的勾選 -> 點擊下方的Save Changes
按鈕
9. 使用中文
頭像右邊的箭頭 -> 點擊Settings進入個人設置頁面 -> 頁面第三個標題,Main settings里有一項叫Preferred language -> 選擇簡體中文 -> 下方的Update profile settings
-> 刷新整個頁面生效
常見異常
500 Whoops, something went wrong on our end.
/etc/gitlab/gitlab.rb
配置錯誤,例如redis未配置,數據庫未配置
502-Whoops, GitLab is taking too much time to respond
- 端口被占用
- 超時時間太短
- 正在啟動
常用命令
查看版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
刷新配置
gitlab-ctl reconfigure
啟動、關閉和重啟
gitlab-ctl start
gitlab-ctl stop
gitlab-ctl restart
查看運行日志
gitlab-ctl tail
關閉默認nginx,使用自己的nginx
部分參考gitlab修改默認端口
默認是true且被注釋掉的
- 修改配置為
nginx['enable'] = false
- 記得刷新配置並重啟
- 修改自己的nginx配置
假設域名是 code.bb.com,unicorn設置是 192.168.1.1:81,注意:unicorn默認啟動的端口是127.0.0.1/端口號,只能本機訪問(其他機器訪問應該是0.0.0.0/端口號)
http {
#...
# 允許上傳數據大小
client_max_body_size 100m;
#...
server {
listen 80;
server_name code.bb.com;
location / {
proxy_pass http://192.168.1.1:81;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
#...
}
- 重啟nginx
數據遷移到另一個服務器
- 在新服務器上安裝同一版本的gitlab,版本必須一致!,復制配置文件到新服務器
- 備份舊服務器數據
gitlab-rake gitlab:backup:create RAILS_ENV=production
- 轉移備份到新服務器相同目錄
備份目錄在/var/opt/gitlab/backups
,文件名格式大致是:1560826106_2019_06_18_11.6.3-ee_gitlab_backup.tar
- 在新服務器上還原備份
BACKUP參數指定備份文件,去掉備份文件名中“_gitlab_backup.tar”剩下的部分
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1560826106_2019_06_18_11.6.3-ee
- 其他問題
除了版本號必須一致外,暫時沒有遇到其他問題