- 拉取gitlab镜像,本例为14.1.2-ce.0
docker pull gitlab/gitlab-ce:14.1.2-ce.0
- 运行gitlab容器
docker run -d --hostname 127.0.0.1 \
-p 10080:10080 \
--name gitlab \
--restart always \
-v /data/gitlab/config:/etc/gitlab \
-v /data/gitlab/logs:/var/log/gitlab \
-v /data/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:14.1.2-ce.0
- -p 10080:10080 暴露端口让ngxin转发
- 查看gitlab启动状态
#状态打印为starting是正在启动,一般5分钟左右,等待状态为healthy即启动成功
docker container ls | grep gitlab
- nginx配置,nginx需要监听gitlab ssh端口,本例子ssh端口为:10022。
- 修改/data/gitlab/config/gitlab.rb配置
#gitlab.rb配置
# Nginx为gitlab准备的虚拟主机域名。这个会出现在代码仓库的链接中
external_url 'http://gitlab.nero.cn'
# 关闭GitLab 内置Nginx
nginx['enable'] = false
# 设置监听方式为TCP
gitlab_workhorse['listen_network'] = "tcp"
gitlab_workhorse['listen_addr'] = "0.0.0.0:10080"
# 设置可信代理(也就是Nginx的ip)
gitlab_rails['trusted_proxies'] = ['192.168.1.31']
# 设置ssh主机名,这个会出现在主机代码的仓库中
gitlab_rails['gitlab_ssh_host'] = 'gitlab.nero.cn'
#ssh暴露的端口,实则为nginx转发的端口
gitlab_rails['gitlab_shell_ssh_port'] = 10022
- Nginx配置域名映射到gitlab仓库
server {
listen 80;
server_name gitlab.nero.cn;
location /{
proxy_pass http://192.168.1.31:10080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
- Nginx需要通过tcp协议代理gitlab的ssh,配置如下
#nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
include /etc/nginx/conf.d/proxy.tcpconf;
#proxy.tcpconf
stream {
#ip为gitlab容器的ip,或提前映射也可
upstream gitlab_ssh {
hash $remote_addr consistent;
server 172.17.0.5:22 max_fails=3 fail_timeout=30s;
}
server {
listen 10022;#数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
proxy_pass gitlab_ssh;
}
}
- 初始账号密码
- 管理员账号root
- 初始密码 在/data/gitlab/config/initial_root_password中
- 访问
- 通过gitlab.nero.cn访问代码仓库
- 通过ssh://git@gitlab.nero.cn:10022/**.git拉取代码
- 优化
-
gilab域名可配置ssl证书