CentOS7伺服器上搭建Gitlab
Gitlab如何搭建?
-
安裝gitlab所需要的依賴
sudo yum install curl policycoreutils openssh-server openssh-clients
-
使sshd服務自動啟動
sudo systemctl enable sshd
-
啟動sshd服務
sudo systemctl start sshd
-
安裝郵件伺服器
sudo yum install postfix
-
使郵件伺服器postfix自啟動
sudo systemctl enable postfix
-
啟動郵件伺服器postfix
sudo systemctl start postfix
-
開放防火牆
sudo firewall-cmd --permanent --add-service=http
-
重啟防火牆
如何啟動GitLab?
-
啟動,配置
sudo gitlab-ctl reconfigure
-
修改gitlab配置檔案指定伺服器ip和自定義埠
vim /etc/gitlab/gitlab.rb 修改 extenal_url="" 為自己伺服器的訪問ip+埠或域名
ps:注意這裡設定的埠不能被佔用,預設是8080埠,可以定義其它埠,並在防火牆設定開放相對應埠。
firewall-cmd --permanent --add-port=8888/tcp systemctl restart firewalld.service
-
重置並啟動GitLab
重新配置 gitlab-ctl reconfigure 重啟 gitlab-ctl restart
訪問gitlab:http://192.168.0.108:8099/ 或 你的域名
說明一下,域名訪問需要配置Nginx,可用Gitlab內建或外部獨立的 -
502錯誤可能的原因
- 埠衝突
- 記憶體不足
- 外部Nginx訪問許可權不足
- Nginx訪問請求連線被重置<我操作時Nginx配置有誤導致這個問題,所以在這裡mark一下>
如何使用外部Nginx?
-
禁用Gitlab內部的Nginx
vim /etc/gitlab/gitlab.rb 在配置中開啟一下配置 nginx['enable'] = false
-
修改外部Nginx配置
upstream gitlab_server { server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket; } server { listen *:80; server_name gitlab.paipailicai.cn; server_tokens off; # don't show the version number, a security best practice root /opt/gitlab/embedded/service/gitlab-rails/public; client_max_body_size 250m; access_log /usr/local/ddanglc/gitlab/logs/gitlab_access.log; error_log /usr/local/ddanglc/gitlab/logs/gitlab_error.log; location / { try_files $uri $uri/index.html $uri.html @gitlab; } location @gitlab { proxy_read_timeout 300; # Some requests take more than 30 seconds. proxy_connect_timeout 300; # Some requests take more than 30 seconds. proxy_redirect off; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Frame-Options SAMEORIGIN; proxy_pass http://gitlab_server; } location ~ ^/(assets)/ { root /opt/gitlab/embedded/service/gitlab-rails/public; expires max; add_header Cache-Control public; } error_page 502 /502.html; }
-
修改許可權配置,讓外部Nginx訪問gitlab的socket檔案
sudo chmod -R o+x /var/opt/gitlab/gitlab-rails
-
重啟 nginx, 重啟gitlab
sudo /usr/local/nginx/sbin/nginx -s reload sudo gitlab-ctl reconfigure
本作品採用《CC 協議》,轉載必須註明作者和本文連結