官方文档
参考文档
镜像地址
# 选择社区版
docker pull gitlab/gitlab-ce
GitLab CI
1.CI是Continuous Integration的简称,就是持续集成的意思。
2.每次提交代码都会自动打包一遍。
配置环境变量$GITLAB_HOME
,该变量指向配置,日志和数据文件将驻留的目录。确保目录存在并且已授予适当的权限。
Linux
vim /etc/profile
export GITLAB_HOME=/root/software/gitlab
MacOS
vi ~/.bash_profile # 用户级 - 【推荐】
export GITLAB_HOME=$HOME/gitlab
# 配置文件生效
source ~/.bash_profile
宿主机位置 | 容器位置 | 用法 |
---|---|---|
$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
# 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
查看启动日志
docker logs -f gitlab
进入容器
docker exec -it gitlab /bin/bash
# 记录初始密码(该文件将在24小时后的首次重新配置运行中自动删除。)
cat /etc/gitlab/initial_root_password
编辑配置文件
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协议端口
重新加载配置
gitlab-ctl reconfigure
# 或者重启GitLab :docker restart gitlab
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'] = "[email protected]"
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'] = '[email protected]'
# 更新设置
gitlab-ctl reconfigure
测试
# 启动控制台(控制台对gitlab服务性能影响很大)
gitlab-rails console
# 发送测试邮件
Notify.test_email('[email protected]','邮件标题','邮件内容').deliver_now
irb(main):001:0> Notify.test_email('[email protected]','邮件标题','邮件内容').deliver_now
Delivered mail [email protected] (1397.8ms)
=> #, >, >, , >, , , , , , >
目前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'] = "[email protected]"
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'] = '[email protected]'
# 更新设置
gitlab-ctl reconfigure
# 启动测试
gitlab-rails console
Notify.test_email('[email protected]','邮件标题','邮件内容').deliver_now
# 测试报错:OpenSSL版本不对
irb(main):008:0> Notify.test_email('[email protected]','邮件标题','邮件内容').deliver_now
Delivered mail [email protected] (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)
# 默认账户名是root,密码存放在配置文件 /etc/gitlab/initial_root_password
http://192.168.0.123
docker restart gitlab
docker exec gitlab update-permissions
docker restart gitlab
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
执行 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'
解决办法:直接取消保护,公网可以应该可以配置allowed to push。
window平台在git clone时,输错密码无法继续。
【控制面板】-> 【用户账户】-> 【凭据管理器】-> 【普通凭据】-> 删除
# 尝试重启,结果直接好了(启动有点慢)
# gitlab-ctl reconfigure
docker restart gitlab
docker exec -it gitlab /bin/bash
# 检查报错原因
gitlab-rake gitlab:check
# 1.查看端口是否占用
# 2.查看是否内存不足
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)"}
解决:
# 删除
/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