gitlab常用操作

安装

  • 安装docker

  • 准备docker-compose.yml文件

web:
  image: 'gitlab/gitlab-ce:11.0.3-ce.0'
  restart: always
  hostname: 'gitlab.example.com'
  environment:
    GITLAB_OMNIBUS_CONFIG: |
      external_url 'http://5.25.24.16:6100'
      gitlab_rails['gitlab_shell_ssh_port'] = 6101
      gitlab_rails['gitlab_email_from'] = '[email protected]'
      gitlab_rails['smtp_enable'] = true
      gitlab_rails['smtp_address'] = "smtp.szfangle.com"
      gitlab_rails['smtp_port'] = 25
      gitlab_rails['smtp_user_name'] = "[email protected]"
      gitlab_rails['smtp_password'] = "123456"
      gitlab_rails['smtp_domain'] = "smtp.szfangle.com"
      gitlab_rails['smtp_authentication'] = "login"
      gitlab_rails['smtp_enable_starttls_auto'] = true
      gitlab_rails['smtp_tls'] = false
  ports:
    - '6100:6100'
    - '6101:22'
  volumes:
    - '/srv/gitlab/config:/etc/gitlab'
    - '/srv/gitlab/logs:/var/log/gitlab'
    - '/srv/gitlab/data:/var/opt/gitlab'
  • 启动 docker-compose up -d

手动备份

sudo gitlab-rake gitlab:backup:create

默认备份文件在目录/var/opt/gitlab/backups/

还原

  • 假设备份文件包名为1531608284_2018_07_15_11.0.3_gitlab_backup.tar

  • 拷贝备份文件到/var/opt/gitlab/backups/目录下,如果是docker安装,可拷贝到挂在点上

  • 还原文件

export time_stamp=1531608284_2018_07_15_11.0.3
sudo gitlab-ctl stop unicorn
sudo gitlab-ctl stop sidekiq
chown git:git ${time_stamp}_gitlab_backup.tar
sudo gitlab-ctl start
sudo gitlab-rake gitlab:check SANITIZE=true
sudo gitlab-rake gitlab:backup:restore BACKUP=${time_stamp}

如果是docker安装,可使用docker exec -it xxxxxx bash 进入容器,执行相关命令;

升级gitlab

  • 备份 (可选),备份好的数据保存在目录/var/opt/gitlab/backups
sudo gitlab-rake gitlab:backup:create STRATEGY=copy
  • 升级
sudo yum install -y gitlab-ce      #社区版运行该命令
# sudo yum install -y gitlab-ee      #企业版运行该命令

配置邮箱

这里邮箱是我们公司邮箱配置,更多配置说明见官网
vim /etc/gitlab/gitlab.rb

### GitLab email server settings
gitlab_rails['gitlab_email_from'] = '[email protected]'

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.szfangle.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "PASWORD"
gitlab_rails['smtp_domain'] = "smtp.szfangle.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false

设置外网端口

  • 修改配置文件/etc/gitlab/gitlab.rb修改如下:
# external_url "http://gitlab.example.com"
external_url 'http://10.200.80.255:8081'
nginx['listen_port'] = 8081
  • 重置配置
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart

自动备份

  • 安装软件
apt-get -y install crontabs 
  • 准备文件 /var/opt/gitlab/auto_backup.sh
#!/bin/bash
cd /srv/
tar -czf gitlab_$(date +"%Y%m%d").tar.gz gitlab
find "/srv/" -name "*.tar.gz" -ctime +31 -type f -exec rm -rf {} \;
  • chmod +x /var/opt/gitlab/auto_backup.sh
  • crontab -e 配置每周日1点备份
* 1 * * 0  /srv/backup.sh

你可能感兴趣的:(gitlab常用操作)