Administrator
发布于 2025-01-06 / 7 阅读
0
0

Gitlab部署教程

查看并拉取docker镜像

# 查看镜像
docker search gitlab
# 拉取镜像
docker pull gitlab/gitlab-ce:latest

docker-compose.yml文件

mkdir -p /usr/local/docker/gitlab_docker
cd /usr/local/docker/gitlab_docker
vim docker-compose.yml
version: '3.1'
​
services:
  gitlab:
    image: 'gitlab/gitlab-ce:latest'
    container_name: gitlab
    restart: always
    environment:
      TZ: 'Asia/Shanghai'
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://192.168.33.131:80'
        gitlab_rails['gitlab_shell_ssh_port'] = 2222
    ports:
      - '80:80'
      - '443:443'
      - '2222:2222'
    volumes:
      - './config:/etc/gitlab'
      - './logs:/var/log/gitlab'
      - './data:/var/opt/gitlab'

安装命令

# 启动gitlab
docker-compose up -d
# 进入容器
docker exec -it gitlab bash
# 查看初始密码
cat /etc/gitlab/initial_root_password

备份

# 进入容器
docker exec -it CONTAINER_ID bash
# 备份命令
/usr/bin/gitlab-rake gitlab:backup:create
# 如果想实现定时备份,可以在宿主机上结合crontab 和 docker命令进行备份。
docker exec -t CONTAINER_ID gitlab-rake gitlab:backup:create

恢复

# 停止unicorn和sidekiq,保证数据库没有新的连接,不会有写数据情况
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
    
# 进入备份目录进行恢复,1476900742为备份文件的时间戳
cd /var/opt/gitlab/backups
gitlab-rake gitlab:backup:restore BACKUP=1553965778_2019_03_31_10.7.3
    
# 启动unicorn和sidekiq
gitlab-ctl start unicorn
gitlab-ctl start sidekiq

常用命令

# 启动所有 gitlab 组件;
gitlab-ctl start
​
# 停止所有 gitlab 组件;
gitlab-ctl stop
​
# 重启所有 gitlab 组件;
gitlab-ctl restart
​
# 查看服务状态;
gitlab-ctl status
​
# 修改gitlab配置文件;
vim /etc/gitlab/gitlab.rb
​
# 重新编译gitlab的配置;
gitlab-ctl reconfigure
    
# 检查gitlab;
gitlab-rake gitlab:check SANITIZE=true --trace    
​
# 查看日志;
gitlab-ctl tail      
gitlab-ctl tail nginx/gitlab_access.log



评论