docker 安裝使用gitlab


官方鏡像地址  ce版本:

 https://hub.docker.com/r/gitlab/gitlab-ce

文檔地址:

https://docs.gitlab.com/omnibus/docker/

環境:

阿里雲 centos 7.4    2核4G

 

首先創建好存儲目錄:

[root@iZbp1625jeg61bc2zzfcotZ ~]# mkdir /usr/local/gitlab_data
[root@iZbp1625jeg61bc2zzfcotZ ~]# cd /usr/local/gitlab_data/ [root@iZbp1625jeg61bc2zzfcotZ gitlab_data]# mkdir
-p /usr/local/gitlab_data/gitlab/config [root@iZbp1625jeg61bc2zzfcotZ gitlab_data]# mkdir -p /usr/local/gitlab_data/gitlab/logs [root@iZbp1625jeg61bc2zzfcotZ gitlab_data]# mkdir -p /usr/local/gitlab_data/gitlab/data

 

然后下載docker下載gitlab的鏡像

[root@iZbp1625jeg61bc2zzfcotZ gitlab_data]# docker pull gitlab/gitlab-ce
[root@iZbp1625jeg61bc2zzfcotZ gitlab_data]# docker images
[root@iZbp1625jeg61bc2zzfcotZ gitlab_data]# docker inspect gitlab/gitlab-ce:latest
[root@iZbp1jcx2imdc3mj7mqdh0Z gitlab_data]# docker inspect gitlab/gitlab-ce:latest | grep DockerVersion

 

然后開始創建容器:

[root@iZbp1625jeg61bc2zzfcotZ gitlab_data]# docker run -d \
--hostname gitlab.example.com \
--name gitlab \
--restart always \
-p 8082:443 -p 8083:80 -p 8084:22 \
-v /etc/localtime:/etc/localtime:ro \
-v /usr/local/gitlab_data/gitlab/config:/etc/gitlab \
-v /usr/local/gitlab_data/gitlab/logs:/var/log/gitlab \
-v /usr/local/gitlab_data/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
#解釋:
  #-d 指定后台運行
  #--hostname 指定主機名
  #--name 指定容器名
  #-p 端口映射
  #--restart always 指定容器停止后的重啟策略: 容器退出時總是重啟
  # -v 指定掛載存儲卷

 

最后登錄測試:

 

 

 



 



 

配置以https 方式訪問的gitlab

1、無論是阿里雲還是騰訊雲都能獲得免費的域名證書,把證書弄出來

2、修改配置文件

[root@iZbp1jcx2imdc3mj7mqdh0Z config]# pwd
/usr/local/gitlab_data/gitlab/config
[root@iZbp1jcx2imdc3mj7mqdh0Z config]# ls
gitlab.rb  gitlab-secrets.json  ssh_host_ecdsa_key  ssh_host_ecdsa_key.pub  ssh_host_ed25519_key  ssh_host_ed25519_key.pub  ssh_host_rsa_key  ssh_host_rsa_key.pub trusted-certs
[root@iZbp1jcx2imdc3mj7mqdh0Z config]# vim gitlab.rb 

3、創建ssl目錄,並將證書改名放入其中

[root@iZbp1jcx2imdc3mj7mqdh0Z config]# mkdir ssl
[root@iZbp1jcx2imdc3mj7mqdh0Z config]# cd ssl/
[root@iZbp1jcx2imdc3mj7mqdh0Z ssl]# pwd
/usr/local/gitlab_data/gitlab/config/ssl
[root@iZbp1jcx2imdc3mj7mqdh0Z ssl]# ls
gitlab.xiangdongcn.com.crt  gitlab.xiangdongcn.com.key

舉例:我這邊是騰訊雲的證書,獲得:

1_gitlab.xiangdongcn.com_bundle.crt

2_gitlab.xiangdongcn.com.key

然后將其改名為:

gitlab.xiangdongcn.com.crt  
gitlab.xiangdongcn.com.key

 

4、安裝docker-nginx

https://www.cnblogs.com/shijunjie/p/10571586.html

 

5、配置https訪問

vim conf.d/default.conf

server {
    listen      443;
    server_name   gitlab.xiangdongcn.com;
    ssl on;
    ssl_certificate ssl/1_gitlab.xiangdongcn.com_bundle.crt;
    ssl_certificate_key ssl/2_gitlab.xiangdongcn.com.key;

    location / {
        proxy_pass https://172.16.77.9:8082;
        proxy_set_header X_FORWARDED_PROTO https;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
server {
    listen 80;
    server_name  gitlab.xiangdongcn.com;
    rewrite ^(.*)$ https://${server_name}$1 permanent;
}

 

6、開啟阿里雲安全組的端口,測試訪問

 

 

 

 

 

 





 

配置郵件

vim gitlab.rb

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "xxxxxxxxxx@qq.com"
gitlab_rails['smtp_password'] = "quajsqkllubrbcdj"   #開啟qq的POP3時得到的密碼
gitlab_rails['smtp_domain'] = "smtp.qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'xxxxxxxxxx@qq.com'

測試配置是否成功:
執行 gitlab-rails console進入控制台。 然后在控制台提示符后輸入下面的命令 發送一封測試郵件:Notify.test_email('收件人郵箱', '郵件標題', '郵件正文').deliver_now

 

 

 





 

 

解決gitlab上傳文件大小的限制:

報錯關鍵字:

error: RPC failed; result=22, HTTP code = 413
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly

 

vim gitlab.rb
nginx['enable'] = true nginx['client_max_body_size'] = '1024m' nginx['redirect_http_to_https'] = false nginx['redirect_http_to_https_port'] = 80

 

 

 

 

然后重啟容器

再然后修改nginx的配置文件

vim nginx.conf


client_max_body_size 60m; ##在http內加上

 

 
        

 

 即可解決上傳文件大小限制的問題。

 

 

 





 

解決nginx出現的問題:

今天有時間進入容器nginx,輸入命令:

[root@iZbp1jcx2imdc3mj7mqdh0Z gitlab]# docker exec -it nginx /bin/bash
root@ae87a1c53ab2:/# /usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

以上是我修復好后沒問題了,但是在修復好之前,出現了兩個警告! 雖然不影響nginx的啟動與使用,但是還是需要排查的。

第一個警告是:

nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl"

這是因為nginx版本的問題,新版本的nginx 是不需要ssl on的,即便設置了ssl on也不影響功能,但是最好改成下圖所示,在443 后面加上ssl 即可。

 

 第二個警告是:

nginx: [warn] could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64; ignoring proxy_headers_hash_bucket_size 

編輯nginx.conf,在http里面增加

proxy_headers_hash_max_size 51200; 
proxy_headers_hash_bucket_size 6400;

 

 



 



 

 解決gitlab出現的無法git push的問題:

 

有技術反饋使用HTTPS可以 clone  但是使用SSH時無法成功;

排查了很多問題,用了很多方法,終於發現了問題存在於端口上。

仔細的小伙伴能夠發現我們在創建容器時,映射的端口是:

這樣導致了在git push的時候無法順利的找到容器gitlab的22端口,於是解決的辦法就是:

1、先修改sshd監聽的22端口,換成別的端口

2、然后docker rm -f gitlab  刪除容器

3、最后重新創建容器,並修改端口映射 -p 22:22  即可

 

以上操作成功后,如果還是無法成功git push  有兩種可能

1、公鑰過期,需要技術重新制作以及上傳公鑰

2、git沒有設置密碼,docker exec -it gitlab /bin/bash 進入容器后 輸入命令 passwd git 設置密碼 即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM