用GitLab搭建自己的私有GitHub
現在git是開發人員的必備技能之一,github的代碼倉庫管理系統目前是最好的,下面搭建私有github系統的過程。
下載gitlab:
官網地址:https://about.gitlab.com/install/
Download a GitLab Omnibus package (recommended installation)
安裝gitlab:
點擊對應操作系統圖標可以看到詳細的安裝步驟教程。
===============
ubuntu
https://about.gitlab.com/install/#ubuntu
sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates
sudo apt-get install -y postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
Next, install the GitLab package. Change https://gitlab.example.com to the URL at which you want to access your GitLab instance. Installation will automatically configure and start GitLab at that URL.
sudo EXTERNAL_URL="https://gitlab.example.com" apt-get install gitlab-ee
==============
On CentOS 7
https://about.gitlab.com/install/#centos-7
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
安裝Postfix 郵件通知功能
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
2. Add the GitLab package repository.
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ee
==============
之后就可以直接使用瀏覽器訪問 http://ip 登錄管理
個性化配置 和 注意事項
使用自己的nignx:
$ apt-get install nginx #安裝nginx
$ cd /etc/nginx/conf.d && touch gitlab-http.conf
Nginx gitlab-http.conf 配置:
upstream gitlab-workhorse {
#server unix:/var/opt/gitlab/gitlab-workhorse/socket;
server 127.0.0.1:8080;
}
upstream gitlab-git-http-server {
server 127.0.0.1:8181;
}
server {
listen *:80;
server_name gitlab.guowei.com;
root /opt/gitlab/embedded/service/gitlab-rails/public;
client_max_body_size 0;
location / {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_http_version 1.1;
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-Forwarded-Proto http;
proxy_pass http://gitlab-workhorse;
}
location ~ [-\/\w\.]+\.git\/ {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_buffering off;
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-Forwarded-Proto $scheme;
proxy_pass http://gitlab-git-http-server;
}
location ~ ^/[\w\.-]+/[\w\.-]+/repository/archive {
client_max_body_size 0;
error_page 418 = @git-http-server;
return 418;
}
location @git-http-server {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_buffering off;
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-Forwarded-Proto $scheme;
proxy_pass http://gitlab-git-http-server;
}
}
配置gitlab不使用nginx:
$ vim /etc/gitlab/gitlab.rb
# search nginx find nginx['enable'] = true
# add
nginx['enable'] = false
gitlab_git_http_server['listen_network'] = "tcp"
gitlab_git_http_server['listen_addr'] = "127.0.0.1:8181"
# nginx['enable'] = true
$ gitlab-ctl reconfigure #配置gitlab
$ gitlab-ctl restart #重啟服務
卸載gitlab:
# Stop gitlab and remove its supervision process
sudo gitlab-ctl uninstall
# Debian/Ubuntu
sudo dpkg -r gitlab-ce
# Redhat/Centos
sudo rpm -e gitlab-ce
注意事項:
為了方便以http的方式操作git倉庫,在nginx中有個8181端口的配置(對應gitlab.rb中的gitlab_git_http_server配置)
下載倉庫代碼問題,有的可以下載,有的不可以下載
主要是國外的庫問題,可以配置下本地源加快下載速度和成功率