gitlab-ctl start # 启动所有 gitlab 组件
gitlab-ctl stop # 停止所有 gitlab 组件
gitlab-ctl restart # 重启所有 gitlab 组件
gitlab-ctl status # 查看服务状态
gitlab-ctl reconfigure # 启动服务
gitlab-ctl show-config # 验证配置文件
gitlab-ctl tail # 查看日志
gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab
vim /etc/gitlab/gitlab.rb # 修改默认的配置文件
fatal: unable to access 'http://gitlab-ci-token:[MASKED]@01e9376e1922/test/test.git/': Could not resolve host: 01e9376e1922
原因: 如果是docker部署的gitlab,宿主机端口如果映射的不是80,则需更改环境external_url=域名,否则会报以下错误
修复方式:当增加 --clone-url
gitlab-runner register \
> --non-interactive \
> --executor "shell" \
> --url "http://47.99.47.196:8080/" \
> --registration-token "zdATHs2jnjbFwPyeUyVz" \
> --description "devops-runner" \
> --tag-list "build,deploy" \
> --run-untagged="true" \
> --locked="false" \
> --access-level="not_protected" \
> --clone-url "http://47.99.47.196:8080/"
Gitlab控制台更改管理员密码
docker -v 挂载目录 docker里面没有权限修改: www.cnblogs.com/smiler/p/10…
docker登录报WARNING! Using --password via the CLI is insecure. Use --password-stdin.
# 解决方式
- echo $DOCKER_REGISTRY_PASSWD > docker_passwd
- cat docker_passwd | docker login --username $DOCKER_REGISTRY_USER --password-stdin $DOCKER_REGISTRY_ENDPOINT
pipeline 报错:
Reinitialized existing Git repository in /home/gitlab-runner/builds/UGCSuB-m/0/digital_team/sale-center-statistics/.git/ fatal: git fetch-pack: expected shallow list fatal: The remote end hung up unexpectedly
解决方式: github.com/sameersbn/d…
同样的问题,Git 不是最新的 (1.8)。
将 git 策略更改为clone也可以解决问题。
但就我而言,我将其设置为获取并更改Git 浅层克隆选项(设置 > CI/CD > 常规管道)从 50 到 0。
pipeline docker login 报错:
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
[55](http://git.hunliji.com/digital_team/sale-center-statistics/-/jobs/286#L55) Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
自己在gitlab-runner 服务器 使用root 执行以下命令修复:
docker login --username xxx --password xxx registry.xxxx.com
但是不解决实际问题,不能每次都手动login 看有个博客上面说使用 sudo, 后面可以尝试测试下
博客地址: www.jianshu.com/p/4cb068911…
gitlab runner 执行器为 docker模式, pipeline 登录 docker 镜像仓库报错:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/auth: dial unix /var/run/docker.sock: connect: permission denied
原因: centos 7 默认使用 SELinux 来增强底层系统的安全性
解决办法: docs.gitlab.com/runner/inst…
gitlab 汉化: www.cnblogs.com/yinzhengjie…
gitlab 限制只能通过域名访问,不能通过ip访问 (方便后续更换服务器等操作)
说明: gitlab 自带的 nginx 配置文件在 /var/opt/gitlab/nginx/conf路径下
通过修改 gitlab-http.conf 可以达到目的, 但是 gitlab 自带 nginx的配置文件在每次执行 gitlab-ctl reconfigure 后都会被覆盖, 所以只修改nginx配置文件虽然可以,但是每次 gitlab reconfigure都需要重新配置, 所以需要一种新的方式来配置.
参考:
stackoverflow.com/questions/5…
操作方式:
- 新建nginx配置文件 /var/opt/gitlab/nginx/conf/gitlab-access-domain.conf
# 限制只能通过 git.yunsicai.com 域名访问, 其他访问方式全部拒绝
if ($host != "git.yunsicai.com") {
return 403;
}
- 修改gitlab配置文件 /etc/gitlab/gitlab.rb
nginx['custom_gitlab_server_config'] = "include /var/opt/gitlab/nginx/conf/gitlab-access-domain.conf;"
- 重启 gitlab 使配置生效
sudo gitlab-ctl reconfigure
- 测试 通过ip访问直接返回403:
通过域名访问成功:
- 查看 nginx 配置文件
/var/opt/gitlab/nginx/conf/nginx.conf
http {
...
include /var/opt/gitlab/nginx/conf/gitlab-http.conf;
include /var/opt/gitlab/nginx/conf/nginx-status.conf;
}
/var/opt/gitlab/nginx/conf/gitlab-http.conf
server {
...
include /var/opt/gitlab/nginx/conf/gitlab-access-domain.conf;
}
/var/opt/gitlab/nginx/conf/gitlab-access-domain.conf
# 限制只能通过 git.yunsicai.com 域名访问, 其他访问方式全部拒绝
if ($host != "git.yunsicai.com") {
return 403;
}
原来 gitlab reconfigure 会将配置文件 gitlab.rb 中 nginx['custom_gitlab_server_config'] 配置项的内容原样复制到 gitlab-http.conf 中, 通过此种方式可以达到目的.
集成 sonar 代码扫描
参考文档: www.cnblogs.com/ioops/p/143…
问题
执行docker pull 报错, timeout
# docker pull sonarqube:8.2-community
Error response from daemon: Head "https://registry-1.docker.io/v2/library/sonarqube/manifests/8.2-community": Get "https://auth.docker.io/token?scope=repository%3Alibrary%2Fsonarqube%3Apull&service=registry.docker.io": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
解决方案: 使用阿里云镜像加速: blog.csdn.net/shao_yc/art…
阿里云地址: cr.console.aliyun.com/cn-hangzhou…
导入其他git项目
3.1 方式一: gitlab 直接同步源仓库项目
New project -> import project -> git Repo bh URL -> 填入源仓库git http地址 -> 填写新仓库的项目名称 -> 保存提交
问题
# Url is blocked: Requests to the local network are not allowed
解决方式: blog.csdn.net/anqixiang/a…
3.2 方式二:将本地代码push到新仓库
以项目名称为 test为例, 项目gitlab路径为: git.hunliji.com:demo/test.git
cd existing_repo
git remote rename origin old-origin
git remote add origin git@git.hunliji.com:demo/test.git
git push -u origin --all
git push -u origin --tags
4 gitlab 支持 SSH方式克隆
先按照这个文档配置, 文档中行数可能不一样,直接配置文件里面搜索: www.jianshu.com/p/193e4c8eb…
然后报错
sh: git-upload-pack: 未找到命令
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
服务端没有安装git, 开始安装git: www.cnblogs.com/jhxxb/p/105…
安装后,继续git clone, 错误变为
fatal: 'devops/devops-templates.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
不知道什么原因, 修复办法感觉是临时性的. forum.gitlab.com/t/cant-get-…
每次有人添加公钥后, gitlab 服务器执行命令: gitlab-rake gitlab:shell:setup 即可clone