当前位置:   article > 正文

Docker安装配置Gitlab,以及常见问题解决_docker部署gitlab时仓库地址是乱码

docker部署gitlab时仓库地址是乱码

一、文档
  • 官方文档

  • 参考文档

  • 镜像地址

    # 选择社区版
    docker pull gitlab/gitlab-ce
    
    • 1
    • 2
  • GitLab CI

    1.CI是Continuous Integration的简称,就是持续集成的意思。

    2.每次提交代码都会自动打包一遍。

二、安装
1.设置环境变量

配置环境变量$GITLAB_HOME ,该变量指向配置,日志和数据文件将驻留的目录。确保目录存在并且已授予适当的权限。

  • Linux

    vim /etc/profile
    
    export GITLAB_HOME=/root/software/gitlab
    
    • 1
    • 2
    • 3
  • MacOS

    vi ~/.bash_profile # 用户级 - 【推荐】
    
    export GITLAB_HOME=$HOME/gitlab
    # 配置文件生效
    source ~/.bash_profile
    
    • 1
    • 2
    • 3
    • 4
    • 5
2.创建存储目录
宿主机位置容器位置用法
$GITLAB_HOME/data/var/opt/gitlab用于存储应用程序数据。
$GITLAB_HOME/logs/var/log/gitlab用于存储日志。
$GITLAB_HOME/config/etc/gitlab用于存储GitLab配置文件。

如果遇到问题实在无法启动了,将这三个数据备份,重装即可自动恢复数据

# 创建文件夹
mkdir -p /root/software/gitlab/etc
mkdir -p /root/software/gitlab/log
mkdir -p /root/software/gitlab/data
  • 1
  • 2
  • 3
  • 4
3.启动容器
# 80(http)、22(ssh)和443(https)
sudo docker run --detach \
  --publish 443:443 --publish 80:80 --publish 22: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 256m \
  gitlab/gitlab-ce:latest

# 启动报错执行
# yum update systemd
# service docker restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 查看启动日志

    docker logs -f gitlab
    
    • 1
4.配置GitLab实例
  • 进入容器

    docker exec -it gitlab /bin/bash
    
    # 记录初始密码(该文件将在24小时后的首次重新配置运行中自动删除。)
    cat /etc/gitlab/initial_root_password
    
    • 1
    • 2
    • 3
    • 4
  • 编辑配置文件

    vi /etc/gitlab/gitlab.rb
    
    external_url 'http://192.168.1.123:80' # GitLab服务器的访问地址
    nginx['listen_port'] = 80 # 监听端口
    gitlab_rails['gitlab_ssh_host'] = '192.168.1.123' # ssh协议地址
    gitlab_rails['gitlab_shell_ssh_port'] = 22 # ssh协议端口
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 重新加载配置

    gitlab-ctl reconfigure
    # 或者重启GitLab :docker restart gitlab
    
    • 1
    • 2
5.配置邮件服务
QQ邮箱服务器
vi /etc/gitlab/gitlab.rb

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "88888888@qq.com"
gitlab_rails['smtp_password'] = "xxxxxxxxx"   # 授权码去掉中间空格
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
# gitlab发信人
gitlab_rails['gitlab_email_from'] = '88888888@qq.com'

# 更新设置
gitlab-ctl reconfigure
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

测试

# 启动控制台(控制台对gitlab服务性能影响很大)
gitlab-rails console
# 发送测试邮件
Notify.test_email('66666666@qq.com','邮件标题','邮件内容').deliver_now

irb(main):001:0> Notify.test_email('66666666@qq.com','邮件标题','邮件内容').deliver_now
Delivered mail 6231871241f74_53835a641829@1568f33492b8.mail (1397.8ms)
=> #<Mail::Message:282340, Multipart: false, Headers: <Date: Wed, 16 Mar 2022 06:43:30 +0000>, <From: GitLab <1071278087@qq.com>>, <Reply-To: GitLab <noreply@192.168.1.123>>, <To: 85614628@qq.com>, <Message-ID: <6231871241f74_53835a641829@1568f33492b8.mail>>, <Subject: 邮件标题>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
163邮箱服务器(不推荐)

目前OpenSSL版本不对报错。

vim /etc/gitlab/gitlab.rb

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "xxxxxxx@163.com"
gitlab_rails['smtp_password'] = "xxxxxx"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

#  gitlab发信人
gitlab_rails['gitlab_email_from'] = 'xxxxxxxx@163.com'

# 更新设置
gitlab-ctl reconfigure

# 启动测试
gitlab-rails console
Notify.test_email('85614628@qq.com','邮件标题','邮件内容').deliver_now

# 测试报错:OpenSSL版本不对
irb(main):008:0> Notify.test_email('liuwang.vip@163.com','邮件标题','邮件内容').deliver_now
Delivered mail 62317e6a2951a_43105a6432269@1568f33492b8.mail (231.7ms)
Traceback (most recent call last):
        1: from (irb):1
OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=error: wrong version number)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
三、访问
# 默认账户名是root,密码存放在配置文件 /etc/gitlab/initial_root_password
http://192.168.0.123
  • 1
  • 2
四、常见异常
500内部错误
docker restart gitlab
  • 1
权限问题
docker exec gitlab update-permissions
docker restart gitlab
  • 1
  • 2
无法启动
Cannot start service zk: oci runtime error: container_linux.go:235: starting container process caused "process_linux.go:258: applying cgroup configuration for process caused \"Cannot set property TasksAccounting, or unknown property.\""

# 解决方法:
yum update systemd
service docker restart
  • 1
  • 2
  • 3
  • 4
  • 5
无法push代码

执行 git push -uf origin main时报错,为了防止肆意提交代码到master,master默认保护状态。

Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To http://192.168.1.123/up/insp-service.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'http://192.168.1.123/up/insp-service.git'
  • 1
  • 2
  • 3
  • 4
  • 5

解决办法:直接取消保护,公网可以应该可以配置allowed to push。

1

输错密码后,无法继续

window平台在git clone时,输错密码无法继续。

【控制面板】-> 【用户账户】-> 【凭据管理器】-> 【普通凭据】-> 删除

502
# 尝试重启,结果直接好了(启动有点慢)
# gitlab-ctl reconfigure
docker restart gitlab

docker exec -it gitlab /bin/bash
# 检查报错原因
gitlab-rake gitlab:check

# 1.查看端口是否占用

# 2.查看是否内存不足
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
Redis无法连接
docker logs -f --tail 100 gitlab
# systemctl status docker
tail -f /root/software/gitlab/logs/gitlab-rails/production.log

{"severity":"ERROR","time":"2022-04-18T07:20:16.902Z","message":"Error fetching job: Error connecting to Redis on /var/opt/gitlab/redis/redis.socket (Errno::ENOENT)"}
  • 1
  • 2
  • 3
  • 4
  • 5

解决:

# 删除
/var/opt/gitlab/redis/dump.rdb
# find / -name dump.rdb
rm /root/software/gitlab/data/redis/dump.rdb
# 重启
docker restart gitlab

gitlab chown gitlab-redis /var/opt/gitlab/redis/*
gitlab-ctl restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/806991
推荐阅读
相关标签
  

闽ICP备14008679号