爛泥:gitlab安裝、配置與阿里雲產品集成

本文由ilanniweb微信公衆號提供友情贊助,首發於爛泥行天下html

jenkins技術分享QQ羣:571981257nginx

看看時間大概有快有半年沒有更新過博客了,這大半年的時間事情比較多,房子裝修、照顧家裏面的寶寶、以及新換的工做、等等事情都夾雜在一塊兒了,因此沒有了太多的時間來寫文章了。git

今天就更新一篇有關gitlab安裝、配置以及與阿里雲產品集成的文章,本篇文章主要分爲兩個章節:gitlab安裝與部署、gitlab與阿里雲產品集成。web

PS:本次實驗OS爲centos7,gitlab咱們使用的是CE社區版本。redis

1、gitlab安裝與部署

gitlab的安裝能夠分爲源碼安裝和經過安裝包進行安裝,要是按照我之前的寫做習慣的話,我也會把源碼安裝在本文章中提現,可是考慮到gitlab自己須要集成的軟件比較多,因此在此咱們選擇的是經過安裝包進行安裝的。sql

gitlab經過安裝包安裝很簡單的,咱們只須要下載對應的RPM包,進行安裝便可。vim

由於本次實驗的OS是centos7,因此咱們直接從官網下載對應的RPM包便可,以下:centos

https://www.gitlab.com.cn/downloads/#centos7安全

clip_p_w_picpath002

sudo yum install curl policycoreutils openssh-server openssh-clients服務器

sudo systemctl enable sshd

sudo systemctl start sshd

sudo yum install postfix

sudo systemctl enable postfix

sudo systemctl start postfix

sudo firewall-cmd --permanent --add-service=http

sudo systemctl reload firewalld

clip_p_w_picpath003

clip_p_w_picpath004

按照上述操做便可完整gitlab的安裝。

在此咱們只指出咱們在操做過程須要注意的地方,建議把gitlab的yum源修改成清華大學gitlab鏡像源或者是浙大gitlab鏡像源,緣由你懂得。

以下:

vim /etc/yum.repos.d/gitlab-ce.repo

[gitlab-ce]

name=gitlab-ce

baseurl=http://mirrors.zju.edu.cn/gitlab-ce/yum/el7/

repo_gpgcheck=0

gpgcheck=0

enabled=1

gpgkey=https://packages.gitlab.com/gpg.key

clip_p_w_picpath005

sudo yum -y install gitlab-ce

clip_p_w_picpath006

clip_p_w_picpath007

sudo gitlab-ctl reconfigure

clip_p_w_picpath008

clip_p_w_picpath009

上圖說明咱們已經把gitlab安裝成功。

2、gitlab與阿里雲產品集成

gitlab安裝時會使用到nginx、redis、postgresql等相關軟件,可是在實際使用過程當中,咱們想把redis和postgresql等分離出來使用,第三方或者本身搭建的軟件。

要達到上述目的,咱們只須要修改gitlab的配置文件gitlab.rb,同時還要執行sudo gitlab-ctl reconfigure命令才能使gitlab.rb文件內容生效。

PS:如下全部配置項,咱們只給出當前正確的配置,不進行相關的講解。

2.1 與阿里雲郵箱集成

gitlab要使用阿里雲的企業郵箱,咱們能夠在gitlab配置文件gitlab.rb中添加以下配置:

vim /etc/gitlab/gitlab.rb

gitlab_rails['smtp_enable'] = true

gitlab_rails['smtp_address'] = "smtp.mxhichina.com"

gitlab_rails['smtp_port'] = 25

gitlab_rails['smtp_user_name'] = "gitlab@ilanni.com"

gitlab_rails['smtp_password'] = "ilanni6543"

gitlab_rails['smtp_domain'] = "ilanni.com"

gitlab_rails['smtp_authentication'] = "login"

gitlab_rails['smtp_enable_starttls_auto'] = true

gitlab_rails['gitlab_email_from'] = gitlab@ilanni.com

clip_p_w_picpath010

以上須要修改的地方,在這我就不一一點出來了,根據給出的英文單詞就能猜想到它的意思。

要使此配置生效的話,須要咱們在gitlab服務器上執行sudo gitlab-ctl reconfigure命令便可。

2.2 與阿里雲redis集成

gitlab要使用阿里雲的提供的redis服務很簡單,咱們只須要在gitlab中添加有關redis的相關配置便可,以下:

vim /etc/gitlab/gitlab.rb

redis['enable'] = false

gitlab_rails['redis_host'] = 'r-bp15e6c8222ed4.redis.rds.aliyuncs.com'

gitlab_rails['redis_port'] = 6379

gitlab_rails['redis_password'] = 'ilannisdfe'

clip_p_w_picpath011

上述命令中的redis['enable'] = false表示棄用gitlab自己的redis服務,其餘的配置選項就是咱們常見的redis配置了。

2.3 與阿里雲postgresql集成

gitlab要使用阿里雲的提供的postgresql服務很簡單,咱們只須要在gitlab中添加有關postgresql的相關配置便可,以下:

vim /etc/gitlab/gitlab.rb

postgresql['enable'] = false

gitlab_rails['db_username'] = "gitlab"

gitlab_rails['db_password'] = "123456"

gitlab_rails['db_host'] = "rm-bnjew04ee2r76086.pg.rds.aliyuncs.com"

gitlab_rails['db_port'] = 3433

clip_p_w_picpath012

上述命令中的postgresql['enable'] = false表示棄用gitlab自己的postgresql服務,其餘的配置選項就是咱們常見的postgresql配置了。

2.4 與ldap集成

gitlab與ldap集成是不屬於阿里雲產品的一部分的,可是既然本篇文章提到的基本上都是gitlab集成相關的東西,那麼咱們就讓其與ldap進行集成下。

gitlab與ldap進行集成,咱們只須要在gitlab.rb文件,添加以下配置便可:

vim /etc/gitlab/gitlab.rb

gitlab_rails['ldap_enabled'] = true

gitlab_rails['ldap_servers'] = YAML.load <<-EOS # remember to close this block with 'EOS' below

main: # 'main' is the GitLab 'provider ID' of this LDAP server

label: 'LDAP'

host: 'ldap.ilanni.com'

port: 389

uid: 'uid'

method: 'plain' # "tls" or "ssl" or "plain"

bind_dn: 'cn=admin,dc=ilanni,dc=com'

password: 'ilanni123'

timeout: 10

active_directory: false

allow_username_or_email_login: true

base: 'dc=ilanni,dc=com'

user_filter: ''

EOS

clip_p_w_picpath013

2.5 加載額外nginx配置文件

gitlab安裝默認狀況下是加載/var/opt/gitlab/nginx/conf目錄下的gitlab-http.conf和nginx-status.conf兩個nginx配置文件的,若是你要加載額外的nginx配置文件,也是須要咱們修改gitlab.rb文件的。

如今來舉個例子,須要gitlab除了加載上述兩個nginx配置文件外,還要加載/var/opt/gitlab/nginx/conf/81-http.conf文件。

gitlab.rb中配置,以下:

vim /etc/gitlab/gitlab.rb

nginx['custom_nginx_config'] = "include /var/opt/gitlab/nginx/conf/81-http.conf;"

clip_p_w_picpath014

2.6 修改gitlab數據存儲路徑和gitlab時區

gitlab默認狀況下數據是存儲在/var/opt/gitlab/git-data目錄下的,若是咱們要把數據存儲到另一個目錄的話,咱們能夠修改gitlab.rb文件中的git_data_dirs選項,以下:

vim /etc/gitlab/gitlab.rb

git_data_dirs({ "default" => { "path" => "/data/gitlab/git-data" } })

clip_p_w_picpath015

若是要修改gitlab顯示時區的話,咱們也能夠經過gitlab.rb文件的time_zone來達到目的,以下:

vim /etc/gitlab/gitlab.rb

gitlab_rails['time_zone'] = 'Asia/Shanghai'

clip_p_w_picpath016

2.7 啓用gitlab的https功能

默認狀況下gitlab使用的是http協議進行訪問的,可是爲了安全起見須要咱們使用https協議訪問gitlab,要啓用gitlab的https功能很簡單,咱們只須要配置gitlab.rb文件便可。

vim /etc/gitlab/gitlab.rb

nginx['redirect_http_to_https']=true

nginx['ssl_certificate']="/data/gitlab/sslkey/server.pem"

nginx['ssl_certificate_key']="/data/gitlab/sslkey/server.key"

clip_p_w_picpath017

此時gitlab-http.conf文件內容以下:

upstream gitlab-workhorse {

server unix:/var/opt/gitlab/gitlab-workhorse/socket;

}

server {

listen *:80;

server_name gitlab.ilanni.com;

server_tokens off; ## Don't show the nginx version number, a security best practice

return 301 https://gitlab.ilanni.com:443$request_uri;

access_log /var/log/gitlab/nginx/gitlab_access.log gitlab_access;

error_log /var/log/gitlab/nginx/gitlab_error.log;

}

server {

listen *:443 ssl http2;

server_name gitlab.ilanni.com;

server_tokens off; ## Don't show the nginx version number, a security best practice

client_max_body_size 0;

ssl on;

ssl_certificate /data/gitlab/sslkey/server.pem;

ssl_certificate_key /data/gitlab/sslkey/server.key;

ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4';

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_prefer_server_ciphers on;

ssl_session_cache builtin:1000 shared:SSL:10m;

ssl_session_timeout 5m;

add_header Strict-Transport-Security "max-age=31536000";

access_log /var/log/gitlab/nginx/gitlab_access.log gitlab_access;

error_log /var/log/gitlab/nginx/gitlab_error.log;

if ($http_host = "") {

set $http_host_with_default "gitlab.ilanni.com";

}

if ($http_host != "") {

set $http_host_with_default $http_host;

}

gzip off;

proxy_read_timeout 3600;

proxy_connect_timeout 300;

proxy_redirect off;

proxy_http_version 1.1;

proxy_set_header Host $http_host_with_default;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection $connection_upgrade;

proxy_set_header X-Forwarded-Proto https;

proxy_set_header X-Forwarded-Ssl on;

location / {

proxy_cache off;

proxy_pass http://gitlab-workhorse;

}

location /assets {

proxy_cache gitlab;

proxy_pass http://gitlab-workhorse;

}

error_page 404 /404.html;

error_page 422 /422.html;

error_page 500 /500.html;

error_page 502 /502.html;

location ~ ^/(404|422|500|502)(-custom)?\.html$ {

root /opt/gitlab/embedded/service/gitlab-rails/public;

internal;

}

}

相關文章
相關標籤/搜索