基础环境
配置1 - 采用 docker-compose run Gitlab
- 平台:阿里云
- 操作系统:CentOS 7.2 64位
- 配置:8C16G
- 带宽:8Mbps
配置2 - 采用 docker引擎直接 run Gitlab
卡,上生产建议升配置或转用其他云平台
- 平台:腾讯云
- 操作系统:CentOS 7.2 64位
- 配置:2C4G
- 带宽:10Mbps
步骤
官方文档
https://docs.gitlab.com/ee/install/docker.html
1、镜像拉取
docker pull gitlab/gitlab-ce
docker pull twang2218/gitlab-ce-zh 汉化
2、创建必要目录
# Linux用户,设置gitlab安装位置 /srv/gitlab
export GITLAB_HOME=/srv/gitlab
# 创建目录,数据、日志、配置
mkdir -p $GITLAB_HOME/data
mkdir -p $GITLAB_HOME/logs
mkdir -p $GITLAB_HOME/config
3、物理机和容器的目录对比
物理机地址 | 容器地址 | 备注 |
---|---|---|
$GITLAB_HOME/data | /var/opt/gitlab | 存储gitlab数据 |
$GITLAB_HOME/logs | /var/log/gitlab | 存储日志 |
$GITLAB_HOME/config | /etc/gitlab | 存储配置文件 |
4、启动容器
配置中物理机和容器内部都是非80端口访问,这里均用:9099
(1)直接启动容器-Install GitLab using Docker Engine(使用Docker引擎)
--privileged=true
让容器获取宿主机root权限
docker run --detach \
--hostname xx.xx.xx.xx\
--publish 8443:443 --publish 9099:9099 --publish 8222:22 \
--name gitlab \
--privileged=true \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
--ulimit sigpending=62793 \
--ulimit nproc=131072 \
--ulimit nofile=60000 \
--ulimit core=0 \
--shm-size 512m \
gitlab/gitlab-ce:latest
(2)通过compose启动容器 - Install GitLab using Docker Compose(强烈推荐这种)
需要先能装 docker-compose ,参考:Linux 中 安装 docker-compose
参考:https://docs.gitlab.com/ee/install/docker.html#install-gitlab-using-docker-compose
# 1.创建yml文件
docker-compose.yml
# 2.填充内容
version: '3.6'
services:
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'xx.xx.xx.xx'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://xx.xx.xx.xx:9099'
gitlab_rails['gitlab_shell_ssh_port'] = 8222
ports:
- '9099:9099'
# - '8443:443'
- '8222:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
# privileged: true
shm_size: '1024m'
# 3.后台启动 (启动容器需要进容器重启配置)
docker-compose up -d
# 4.停止容器
docker-compose down
6、设置外部访问 Open /etc/gitlab/gitlab.rb with your editor and set external_url:
Expose GitLab on different ports,非80端口
# 进入容器
docker exec -it gitlab /bin/bash
docker exec -it gitlab-web-1 /bin/bash
# 设定外部访问地址
vi /etc/gitlab/gitlab.rb
external_url "http://xx.xx.xx.xx:9099"
# 设定 gitlab_shell_ssh_port:
gitlab_rails['gitlab_ssh_host']='xx.xx.xx.xx'
gitlab_rails['gitlab_shell_ssh_port'] =8222
# 确认容器配置端口也是9099
vi /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
修改host 与上面.rb文件修改的一致,修改port 为9099
# 重新配置 Gitlab - 运行这个即可
gitlab-ctl reconfigure
---------------------
额外的配置
---------------------
gitlab的备份
vi /etc/gitlab/gitlab.rb(分别修改备份目录和备份保留时间)
gitlab_rails['backup_path'] = “/var/opt/gitlab/backups” (修改备份目录)
gitlab_rails['backup_keep_time'] = 604800 (7天,默认单位为s)
定时备份
0 23 * * * /usr/bin/gitlab-rake gitlab:backup:create
# 重启服务
gitlab-ctl restart
# 容器外重启gitlab
docker restart gitlab-web-1
7、更新gitlab
(1)Upgrade GitLab using Docker Engine
Take a backup. As a minimum, back up the database and the GitLab secrets file.
docker stop gitlab
docker rm gitlab
docker pull gitlab/gitlab-ce:latest
docker run --detach \
--hostname xx.xx.xx.xx \
--publish 8443:443 --publish 9099:9099 --publish 8222:22 \
--name gitlab \
--restart always \
--volume $GITLAB_HOME/config:/etc/gitlab \
--volume $GITLAB_HOME/logs:/var/log/gitlab \
--volume $GITLAB_HOME/data:/var/opt/gitlab \
--shm-size 1024m \
gitlab/gitlab-ce:latest
(2)Upgrade GitLab using Docker compose
在存在yml文件的目录下执行命令
docker-compose pull
docker-compose up -d
8、登录
网页访问9099端口, 初始用户为root, root初始密码见
地址:xx.xx.xx.xx:9099
容器内部:vi etc/gitlab/initial_root_password
物理机:vim /srv/gitlab/config/initial_root_password
9、关于gitlab的说明
- gitlab 默认的数据库是 PostgreSQL
- 本地访问 PostgreSQL
sudo gitlab-rails dbconsole
或者
sudo gitlab-psql -d gitlabhq_production
输入\list查看所有数据库
输入select * from namespaces;查看 gitlab 中已经有了哪些用户。
输入select * from projects;查看有哪些项目文件
- 远端访问待补充,参考地址:https://swmlee.com/2019/12/21/technicalessays/aboutgit/6remote-access-gitlab-ce-postgresql/
10、错误信息
(1)进入具体的容器,3s偶就会自动退出,就是无限重启 (配置1安装就没问题,现初步断定是硬件问题,有点像是腾讯云的锅)
原因:就是容器自己挂掉,我把restart: always 参数去掉
容器里的前台进程挂了,而你又设置了 restart=always 或是 restart=unless-stopped,就会反复在启动 -> 挂掉 -> 退出 -> 重启之间循环了。
如果你确定你这个镜像里有前台进程、或是你在 docker run 的时候指定了别的前台进程,那么你可以 docker inspect 看一下日志路径,然后把它挂载到宿主机上,慢慢分析吧。
看日志:docker logs gitlab
/opt/gitlab/embedded/bin/runsvdir-start: line 24: ulimit: pending signals: cannot modify limit: Operation not permitted
/opt/gitlab/embedded/bin/runsvdir-start: line 37: /proc/sys/fs/file-max: Read-only file system
设置:ulimit -n 1048576
docker exec -it gitlab update-permissions
docker restart gitlab
(2)更改Docker的shm(共享内存)大小
默认 64M,在设置yml配置可以追加参数:shm_size
或者
docker run -it --shm-size="1g"
(3)initial_root_password 即拥有密码的文件,不存在
- 文件首次重新配置后的24小时将被删除
- 设定下密码开启-不管用
#### Toggle if initial root password should be written to /etc/gitlab/initial_root_password
gitlab_rails['store_initial_root_password'] = true
重新删除最开始安装的文件夹:data、logs、config,重新能装就能看到该文件也能看到密码了;
本文含有隐藏内容,请 开通VIP 后查看