標籤:pool vhost options 需要 which 賬戶 管理員 files ddr
gitlab快速部署教程部署環境
開始部署安裝依賴
sudo apt-get install curl openssh-server ca-certificates postfix
執行完成後,出現郵件配置,選擇Internet那一項(不帶Smarthost的)
下載軟體包
下載頁面: https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/
可以自行選擇想要部署的版本,使用命令curl進行下載
curl -O https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/xenial/main/g/gitlab-ce/gitlab-ce_11.3.6-ce.0_amd64.deb
安裝軟體包
sudo dpkg –i gitlab-ce_11.3.6-ce.0_amd64.deb
如果安裝過程出現錯誤則需要自行解決依賴等問題(筆者安裝時一切正常)
配置產生
sudo gitlab-ctl reconfigure
初次安裝使用請一定記得組建組態
檢查
輸入以下命令檢查是否安裝正確
sudo gitlab-ctl status
出現類似以下的結果,則說明運行正常
run: gitlab-workhorse: (pid 1148) 884s; run: log: (pid 1132) 884s run: logrotate: (pid 1150) 884s; run: log: (pid 1131) 884s run: nginx: (pid 1144) 884s; run: log: (pid 1129) 884s run: postgresql: (pid 1147) 884s; run: log: (pid 1130) 884srun: redis: (pid 1146) 884s; run: log: (pid 1133) 884s run: sidekiq: (pid 1145) 884s; run: log: (pid 1128) 884s run: unicorn: (pid 1149) 885s; run: log: (pid 1134) 885s
使用
使用的時候,系統管理員賬戶名稱為root,需要先設定一個root賬戶密碼。
如果出現502錯誤的話,則將以下檔案的讀許可權開啟
sudo chmod -R o+x /var/opt/gitlab/gitlab-rails
配置調整部署網域名稱調整
編輯設定檔
sudo nano /etc/gitlab/gitlab.rb
將內部的external_url修改為自己的部署網域名稱,例如:
- 如果是區域網路直接ip訪問的話,設定為
http://xxx.xxx.xxx.xxx即可
- 如果是外網通過網域名稱訪問的話,設定為
http://your.domain-name.com
然後,重建配置
sudo gitlab-ctl reconfigure
自行使用nginx部署
實際上,這個快速部署的軟體包內是內建nginx的,然而實際伺服器部署的話,我們常常需要部署在系統原生的nginx上,我們可以按照這樣的方式進行操作:
在nginx設定檔中添加配置:
# gitlab socket 檔案地址upstream gitlab { # 7.x 版本在此位置 # server unix:/var/opt/gitlab/gitlab-rails/tmp/sockets/gitlab.socket; # 8.0+ 版本位置(11.x版本親測可用) server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket;}server { listen *:80; server_name gitlab.liaohuqiu.com; # 請修改為你的網域名稱 server_tokens off; # don't show the version number, a security best practice root /opt/gitlab/embedded/service/gitlab-rails/public; # Increase this if you want to upload large attachments # Or if you want to accept large git objects over http client_max_body_size 250m; # individual nginx logs for this gitlab vhost access_log /var/log/gitlab/nginx/gitlab_access.log; error_log /var/log/gitlab/nginx/gitlab_error.log; location / { # serve static files from defined root folder;. # @gitlab is a named location for the upstream fallback, see below try_files $uri $uri/index.html $uri.html @gitlab; } # if a file, which is not found in the root folder is requested, # then the proxy pass the request to the upsteam (gitlab unicorn) location @gitlab { # If you use https make sure you disable gzip compression # to be safe against BREACH attack 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; } # Enable gzip compression as per rails guide: http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression # WARNING: If you are using relative urls do remove the block below # See config/application.rb under "Relative url support" for the list of # other files that need to be changed for relative url support location ~ ^/(assets)/ { root /opt/gitlab/embedded/service/gitlab-rails/public; # gzip_static on; # to serve pre-gzipped version expires max; add_header Cache-Control public; } error_page 502 /502.html;}
編輯gitlab設定檔
sudo nano /etc/gitlab/gitlab.rb
禁用掉內建的nginx(如果原本沒有這句話的話需要加上)
nginx['enable'] = false
重啟nginx,重啟gitlab服務
sudo /usr/local/nginx/sbin/nginx -s reloadsudo gitlab-ctl reconfigure
同樣的,如果再次出現502錯誤的話,需要修改一下配置
sudo chmod -R o+x /var/opt/gitlab/gitlab-rails
【gitlab】gitlab快速部署教程