官方鏡像地址 ce版本:html
https://hub.docker.com/r/gitlab/gitlab-cenginx
文檔地址:git
https://docs.gitlab.com/omnibus/docker/docker
環境:json
阿里雲 centos 7.4 2核4Gvim
首先建立好存儲目錄:centos
[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
而後開始建立容器:bash
[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 指定掛載存儲卷
最後登陸測試:dom
配置以https 方式訪問的gitlab
一、不管是阿里雲仍是騰訊雲都能得到免費的域名證書,把證書弄出來
二、修改配置文件
[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
三、建立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
四、安裝docker-nginx
https://www.cnblogs.com/shijunjie/p/10571586.html
五、配置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; }
六、開啓阿里雲安全組的端口,測試訪問
配置郵件
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
![](http://static.javashuo.com/static/loading.gif)
而後重啓容器
再而後修改nginx的配置文件
vim nginx.conf
client_max_body_size 60m; ##在http內加上
![](http://static.javashuo.com/static/loading.gif)
便可解決上傳文件大小限制的問題。
解決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端口,因而解決的辦法就是:
一、先修改sshd監聽的22端口,換成別的端口
二、而後docker rm -f gitlab 刪除容器
三、最後從新建立容器,並修改端口映射 -p 22:22 便可
以上操做成功後,若是仍是沒法成功git push 有兩種可能
一、公鑰過時,須要技術從新制做以及上傳公鑰
二、git沒有設置密碼,docker exec -it gitlab /bin/bash 進入容器後 輸入命令 passwd git 設置密碼 便可。