1、环境说明
系统:Centos7.6
IP地址:192.168.9.170
最低配置要求:2核心CPU和4G内存,这是因为[GitLab](https://baike.baidu.com/item/gitlab/3059600?fr=aladdin)的整体运行包含了多个进程
2、自行安装 docker 和 docker-compose
3、使用 docker-compose 安装 Gitlab
(1)随便找个地方,新建 gitlab文件夹
mkdir gitlab
cd gitlab
touch docker-compose.yml
# 在 docker-compose.yml 同级目录创建映射文件夹
mkdir etc log opt
文件结构如下:
gitlab
|___docker-compose.yml
|___etc
|___log
|___opt
(2)docker-compose.yml文件内容如下:
192.168.9.170 是我主机的IP地址,在实际部署的时候,必须依据个人的IP地址进行配置;
另外还需开放一下端口(7080、7043、7022),方便后续服务访问;
version: '2.2'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
container_name: "gitlab"
restart: always
privileged: true
hostname: 192.168.9.170:7080
environment:
gitlab_omnibus_config: |
external_url 'http://192.168.9.170:7080'
gitlab_rails["time_zone"] = 'Asia/Shanghai'
gitlab_rails['gitlab_ssh_host'] = '192.168.9.170'
gitlab_rails['gitlab_shell_ssh_port'] = 7022
ports:
- '7080:7080'
- '7043:443'
- '7022:22'
volumes:
- './etc:/etc/gitlab'
- './log:/var/log/gitlab'
- './opt:/var/opt/gitlab'
4、拉取镜像并启动
docker-compose up -d
5、修改配置文件 gitlab.rb
# 进入bash操作
docker exec -it gitlab /bin/bash
# 检查 gitlab.rb 配置文件信息,确保配置里的IP地址与宿主主机IP地址(192.168.9.170)一致,避免gitlab服务不能访问问题
vi /etc/gitlab/gitlab.rb
##! https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
external_url 'http://192.168.9.170:7080' ## 确保IP地址与主机地址一致
## Roles for multi-instance GitLab
##! The default is to have no roles enabled, which results in GitLab running as an all-in-one instance.
##! Options:
##! redis_sentinel_role redis_master_role redis_replica_role geo_primary_role geo_secondary_role
################################################################################
################################################################################
## Configuration Settings for GitLab CE and EE ##
################################################################################
################################################################################
################################################################################
## gitlab.yml configuration
##! Docs: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/gitlab.yml.md
################################################################################
# gitlab_rails['gitlab_ssh_host'] = 'ssh.host_example.com'
# gitlab_rails['gitlab_ssh_user'] = ''
gitlab_rails['time_zone'] = 'Asia/Shanghai' ## 修改时区
gitlab_rails['gitlab_shell_ssh_port'] = 7022 ## 这一行没有,新增这一行
- /etc/gitlab/gitlab.rb 31/2900 1%
6、修改配置文件 gitlab.yml
## GitLab settings
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: 61.240.148.99 ## 确保IP地址与主机一致
port: 7080
https: false
# The maximum time puma can spend on the request. This needs to be smaller than the worker timeout.
# Default is 95% of the worker timeout
max_request_duration_seconds: 57
## Email settings
# Uncomment and set to false if you need to disable email sending from GitLab (default: true)
email_enabled:
# Email address used in the "From" field in mails sent by GitLab
email_from: gitlab@61.240.148.99 ## 确保IP与主机一致
email_display_name:
email_reply_to:
email_subject_suffix:
# Email SMIME signing settings
email_smime:
enabled: false
key_file: /etc/gitlab/ssl/gitlab_smime.key
cert_file: /etc/gitlab/ssl/gitlab_smime.crt
ca_certs_file:
6、在容器内进行服务重启
gitlab-ctl restart
7、Web访问Gitlab
访问地址:http://192.168.9.170:7080/users/sign_in
用户名:root
密码:unupCCcAcDs41oDEj6/JpSJtHGEANH2tqhoYvwhEB50=
8、查看root初始密码:
# 进入bash操作
docker exec -it gitlab /bin/bash
cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: unupCCcAcDs41oDEj6/JpSJtHGEANH2tqhoYvwhEB50=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.