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 设置密码 即可。

 

posted @ 2019-03-07 12:35  海兵的正义  阅读(3141)  评论(0编辑  收藏  举报