Ubuntu server18.04上搭建Gitlab(使用Docker)

Ubuntu Server 18.04系统安装:

下载官方镜像,使用rufus工具制作U盘安装盘
按照官方文档安装,记得配上sshd

ubuntu18.04 server配置静态ip:

请见https://notes.z-dd.net/2019/05/16/Ubuntu%E7%9B%B8%E5%85%B3/

安装docker及相关操作:

详见https://notes.z-dd.net/2021/01/13/Docker%E7%9B%B8%E5%85%B3/

Install GitLab with Docker:

https://docs.gitlab.com/ce/install/docker.html

  1. 运行gitlab-ee镜像(第一次执行会先下载镜像):

        sudo docker run --detach \
        --hostname gitlab-server \
        --publish 443:443 --publish 80:80 --publish 2222:22 \
        --name gitlab \
        --restart always \
        --volume /srv/gitlab/config:/etc/gitlab \
        --volume /srv/gitlab/logs:/var/log/gitlab \
        --volume /srv/gitlab/data:/var/opt/gitlab \
        gitlab/gitlab-ce:latest  
          
        ```  
    
    2. **设置`external_url``ssh_port``root_password`**  
    `sudo nano /srv/gitlab/config/gitlab.rb `  
    **注意:** 一旦在external_url最后加上端口号,容器内的nginx就会监听这个端口,也就意味着宿主机和容器的映射端口(–publish 9090:9090)必须与external_url的端口一样,都是9090  
    `external_url 'http://192.168.1.101'`  
    修改时区  
    `gitlab_rails['time_zone'] = 'Asia/Shanghai'`
    
    3. **Email Settings**  
    

    gitlab_rails[‘gitlab_email_enabled’] = true
    gitlab_rails[‘gitlab_email_from’] = ‘xxx@xxx.com.cn’
    gitlab_rails[‘gitlab_email_display_name’] = ‘git-server’
    gitlab_rails[‘gitlab_email_reply_to’] = ‘xxx@xxx.com.cn’

    gitlab_rails[‘gitlab_shell_ssh_port’] = 2222
    gitlab_rails[‘initial_root_password’] = “password”

    gitlab_rails[‘smtp_enable’] = true
    gitlab_rails[‘smtp_address’] = “smtphm.qiye.163.com”
    gitlab_rails[‘smtp_port’] = 25
    gitlab_rails[‘smtp_user_name’] = “zdd@xxx.com.cn
    gitlab_rails[‘smtp_password’] = “xxxx”
    gitlab_rails[‘smtp_domain’] = “xxx.com.cn”
    gitlab_rails[‘smtp_authentication’] = “login”
    gitlab_rails[‘smtp_enable_starttls_auto’] = true
    gitlab_rails[‘smtp_tls’] = false

相关配置操作:

重启gitlab
$ sudo docker restart gitlab
停止当前的gitlab容器
$ sudo docker stop gitlab
删除gitlab容器
$ sudo docker rm gitlab
删除docker镜像
sudo docker images
sudo docker rmi <image id>

找出容器的唯一标识:
sudo docker ps
进入了Docker容器的命令行环境:
sudo docker exec -it a2ad5d5d6e7a /bin/bash

进入rails控制台
gitlab-rails console production
重置 gitlab 密码:
u=User.where(id:1).first (User.all 可以查看所有用户)
#u=User.where(username:'admin').first
u.password='12345678'
u.password_confirmation='12345678'
u.save!
邮箱测试:
Notify.test_email('xxxx@qq.com', 'title', 'zhengwen').deliver_now

监听日志
gitlab-ctl tail

生效配置:
gitlab-ctl reconfigure
gitlab-ctl restart

备份:
进入了Docker容器的命令行环境:
sudo docker exec -it gitlab bash
gitlab-rake gitlab:backup:create
/srv/gitlab/data/backups目录下会多一个“**.tar”的文件
迁移数据恢复:
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1508401391_2017_10_19_9.3.7
检查恢复:
gitlab-rake gitlab:check SANITIZE=true