ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

ubuntu18搭建Gitlab服务

ubuntu18搭建Gitlab服务 文章目录安装配置镜像路径添加sshkeygtilab部分命令gitlab开机启动卸载gitlab其它操作自动备份手动备份配置备份自动定时备份恢复恢复数据恢复配置迁移迁移备份迁移恢复升级本机升级gitlab runner远程clone问题忘记密码问题安装参考https://docs.gitlab.com/omnibus/settings/configuration.html官方https://about.gitlab.com/install/#ubuntusudoapt-getinstall-ycurlopenssh-server ca-certificatessudoapt-getinstall-ypostfix#选择 Internet Sitecurlhttps://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh|sudobashsudosystemctlenablepostfixsudosystemctl start postfixsudoapt-getinstallgitlab-ce#安装可用最新版本#sudo apt-get install gitlab-ce11.7.5-ce.0 #指定版本号#由于版本太低需要指定源进行下载#sudo apt-get install gitlab-ce12.9.2-ce.0 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu/pool/bionic/main/g/gitlab-ce/# ubuntu18# #指定清华源 apt install gitlab-ce方法# sudo vim /etc/apt/sources.list.d/gitlab-ce.list #写入如下内容# deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main# #首先信任 GitLab 的 GPG 公钥:# curl https://packages.gitlab.com/gpg.key 2 /dev/null | sudo apt-key add - /dev/nullsudoaptupdatesudoaptlist gitlab-ce-a#查看所有的gilab-ce版本# 如果在ubuntu22系统上没有需要低版本gitlab在新增ubuntu20/focal源#/etc/apt/sources.list.d/gitlab_gitlab-ce.list文件添加如下内容# 原有行已注释或删除# deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ jammy main# deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ jammy main# 新增focal源#deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal main#deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ focal mainsudoapt-getinstallgitlab-ce12.9.2-ce.0#指定版本安装sudovim/etc/gitlab/gitlab.rb#配置external_url 通常是本机局域网ip的形式,例如external_url http://192.168.1.106:80#设置git-data存储位置#git_data_dirs({ default { path /mnt/gitlab/git-data } }) #添加指定存储位置sudogitlab-ctl reconfiguresudogitlab-ctl stop#If you already have existing Git repositories in /var/opt/gitlab/git-data you can move them to the new location as follows:sudorsync-av/var/opt/gitlab/git-data/repositories /mnt/nas/git-data/#同步文件内容sudogitlab-ctl upgradesudogitlab-ctl start#设置下次开机自启动gitlab服务sudosystemctlenablegitlab-runsvdir.servicesudosystemctl start gitlab-runsvdir.service错误STDERR: sysctl: cannot open “/etc/sysctl.d/90-omnibus-gitlab-kernel.sem.conf”:参考https://www.jianshu.com/p/134c1107114a错误1resql/.s.PGSQL.5432? [execute] psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket /var/opt/gitlab/postgresql一般是文件权限问题只要修改/var/opt/gitlab/postgresql权限sudochmod755/var/opt/gitlab/postgresqlsudogitlab-ctl reconfigure错误2storage_directory[/var/opt/gitlab/.ssh](gitlab::gitlab-shell line 38)had an error:Mixlib::shellout::shellcommandfailed:ruby_block[directory resource: xxx_path]一般是文件权限问题只要修改xxx_path权限使git用户有读写权限即可sudochowngit:root xxx_path错误4Gitlab更新后gitlab-ctl reconfigure报错rails_migration[gitlab-rails] (gitlab::database_migrations line 51) had an error方法 https://yangyq.net/2022/05/gitlab-update-error.html解决方法#重起系统sudogitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,push_event_payloads,event_id,[[event_id]\, [event_id_convert_to_bigint]]]sudogitlab-ctl reconfiguresudogitlab-ctl restartsudogitlab-rake db:migrate#反馈如下继续执行如下建议命令sudogitlab-rake gitlab:background_migrations:finalize[CopyColumnUsingBackgroundMigrationJob,events,id,[[id]\, [id_convert_to_bigint]]]# 显示成功后sudogitlab-ctl reconfiguresudogitlab-ctl restart原文链接https://blog.csdn.net/qq_35540820/article/details/85037923https://blog.csdn.net/qq_35540820/article/details/85037923错误3在某些机型中如果无显示器连接启动主机会出现gitlab服务无法启动参考http://www.mamicode.com/info-detail-3035147.html$sudogitlab-ctl start fail: alertmanager: runsv not running fail: gitaly: runsv not running fail: gitlab-monitor: runsv not running fail: gitlab-workhorse: runsv not running fail: logrotate: runsv not running fail: nginx: runsv not running fail: node-exporter: runsv not running fail: postgres-exporter: runsv not running fail: postgresql: runsv not running fail: prometheus: runsv not running fail: redis: runsv not running fail: redis-exporter: runsv not running fail: registry: runsv not running fail: sidekiq: runsv not running fail: unicorn: runsv not runningsudosystemctl start gitlab-runsvdir#卡死状态#如果冻结不动的话就需要查看系统服务项了sudosystemctl-ttarget#可以清楚的看到有服务启动出错graphical.target loaded inactive dead start Graphical Interface multi-user.target loaded inactive dead start Multi-User System#如果系统正常的话所有任务应该是loaded active active如果存在inactive dead选型意味着有些服务出错了sudosystemctl list-jobs#如果存在某个任务是running则是该任务堵塞了其他所有服务包括gitlab服务。plymouth-quit-wait.service start running graphical.target start waiting...#此时就可以利用 systemctl stop xxxx.service结束该任务sudosystemctl stop plymouth-quit-wait.servicesudosystemctl list-jobs Nojobsrunning#结果显示sudosystemctl-ttarget#显示所有服务全是loaded active active状态#问题解决错误4在某些机型中 gitlab-ctl reconfigure出现如下问题gitlab-ctl reconfigure ffi-libarchive could not be loaded, libarchive issudoaptinstalllibarchive-devsudogitlab-ctl reconfigure软件版本号查看请参考参考https://www.centos.bz/2017/07/ubuntu-apt-cache-version-list-install-specify-version/配置镜像路径#国外源网速太慢使用清华大学镜像的路径sudovim/etc/apt/sources.list.d/gitlab_gitlab-ce.list deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main#或者deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic mainsudoapt-getupdateapt-cacheshow gitlab-ce|grepVersion添加sshkey浏览器登陆gitlab页面user setting - ssh Keys - 根据向导自行操作如果不执行此操作会导致gitlab的仓库代码无法远程clone代码时输入正确密码但会被拒绝参考https://my.oschina.net/stefanzhlg/blog/529403gtilab部分命令sudogitlab-ctl stop#停止sudogitlab-ctl start#开启sudogitlab-ctl restart#重启sudogitlab-ctl status#查看状态sudogitlab-ctl reconfigure#更新配置修改配置后必须执行sudogitlab-ctltail#查看日志cat/opt/gitlab/embedded/service/gitlab-rails/VERSION#查看 GitLab 版本号gitlab开机启动#设置GitLab开机自启动命令为sudosystemctlenablegitlab-runsvdir.service#禁止GitLab开机自启动命令为sudosystemctl disable gitlab-runsvdir.service卸载gitlab执行如下四步#前提必须在Gitlab运行状态下才能卸载# Stop gitlab and remove its supervision processsudosystemctl stop gitlab-runsvdir.servicesudosystemctl disable gitlab-runsvdir.servicesudorm/usr/lib/systemd/system/gitlab-runsvdir.servicesudosystemctl daemon-reloadsudogitlab-ctl restartsudogitlab-ctl remove-accountssudogitlab-ctl uninstallsudogitlab-ctl cleanse# Debian/Ubuntusudoaptremove gitlab-ce#对应apt 安装方法#sudo dpkg -P gitlab-ce #对应dpkg 安装方法# 清理其它数据sudorm/opt/gitlab-rfsudorm/var/opt/gitlab-rfsudorm/root/gitlab*-rfsudorm/var/log/gitlabsudorm/etc/gitlab#查看gitlab进程psaux|grepgitlabrebootRemove servicessudo gitlab-ctl uninstallClean any data generated by usage of the packagesudo gitlab-ctl cleanseYou may also want to remove any accounts you configured. To do sosudo gitlab-ctl remove-accountsThen remove the package usingsudo dpkg -P gitlab-ceFurthermore, gitlab-ce uses these directories (as described here 1.2k)/opt/gitlab holds application code for GitLab and its dependencies./var/opt/gitlab holds application data and configuration files that gitlab-ctl reconfigure writes to./etc/gitlab holds configuration files for omnibus-gitlab. These are the only files that you should ever have to edit manually./var/log/gitlab contains all log data generated by components of omnibus-gitlab.So, First remove the package recommended way (Even if you need to reinstall it). You can then remove those data using rm safely.Information found from omnibus-gitlab README page 1.2k其它操作自动备份参考https://blog.csdn.net/zhayushui/article/details/79757911手动备份#需要先启动gitlab服务$sudogitlab-rake gitlab:backup:create默然的备份目录为 /var/opt/gitlab/backups备份文件名类似 xxxxxx_gitlab_backup.tar备份目录的修改关键字 backup_path$sudovi/etc/gitlab/gitlab.rb#gitlab_rails[backup_path] /mnt/gitlab_backups注意/mnt/gitlab_backups硬盘例如新挂载的硬盘文件系统格式必须与/var/opt/gitlab/backups相同配置备份通常只需要备份/etc/gitlab/gitlab-secrets.json备份/etc/gitlab/gitlab.rb备份/etc/gitlab/gitlab.sh自动定时备份备份如果不能及时清理硬盘的空间很快会不够用同时也要能够自动清理不需要人工花时间在这一块。设置备份自动清理,只保存最近7天的备份sudoaptinstallzipunzipvim/etc/gitlab/gitlab.rb#gitlab_rails[backup_keep_time] 604800 # 删除注释 # 7天*3600秒*24时604800sgitlab-ctl reconfigure 配置定时任务 需重启cron服务sudocrontab-e02* *6/opt/gitlab/bin/gitlab-rake gitlab:backup:create#每周六凌晨2点备份562* *6/etc/gitlab/gitlab.sh#配置文件和解密文件备份推荐如下方法02* * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create#每天凌晨2点备份562* * * /etc/gitlab/gitlab.sh#配置文件和解密文件备份推荐如下方法## gitlab.sh: gitlab cfg backup# cd /etc/gitlab/# zip -r /mnt/diskbackup/gitlab/gitcfg-date %Y_%m_%d_%H%M.zip ./gitlab*# gitlab解密文件数据恢复或者迁移使用#* * * * * 格式表示分时日月周crontab-l查看定时任务#sudo systemctl enable cron #设置cron服务开机使能sudosystemctlenablecron.service#设置cron服务开机使能sudosystemctl restartcron#修改后重启cron服务#$sudo systemctl start cron #启动cron服务#$sudo systemctl stop cron #停止cron服务#$sudo systemctl restart cron #重启cron服务参考shell文件日期名使用gitlab.sh文件内容如下#!/bin/bashcd/etc/gitlab/zip-r/mnt/diskbackup/gitlab/gitcfg-date%Y_%m_%d.zip ./gitlab*# 或者rsync方式备份#0 2 * * 6 rsync -av /mnt/disk/tools /mnt/diskbackup/tools #每周六凌晨2点备份恢复恢复数据#注意xxxx_2020_yyyy__gitlab_backup.tar 存放在gitlab backup_path路径#gitlab_rails[backup_path] /mnt/gitlab_backups#注意修改/mnt/gitlab_backups夹及文件权限 chown git:root /mnt/gitlab_backupssudogitlab-ctl reconfigure#停止与连接 数据库有关的进程sudogitlab-ctl stop unicorn#高于13.8.8版本不在使用sudogitlab-ctl stop puma#高于13.8.8版本使用sudogitlab-ctl stop sidekiq# Verify是否停止sudogitlab-ctl status# restoresudochowngit:git 1586249194_2020_04_07_12.9.2*.tar#对应文件名sudogitlab-backup restoreBACKUP1586249194_2020_04_07_12.9.2#or#sudo gitlab-rake gitlab:backup:restore BACKUP1586249194_2020_04_07_12.9.2#注意.tar文件权限问题Restoring PostgreSQL database gitlabhq_production... ERROR: must be owner of extension pg_trgm ERROR: must be owner of extension btree_gist ERROR: must be owner of extension btree_gist ERROR: must be owner of extension pg_trgm解决方法#1.$vim/var/opt/gitlab/postgresql/data/postgresql.conf listen_addresses#改成如下listen_addresses*#2.$vim/var/opt/gitlab/postgresql/data/pg_hba.conf# 最下面新增两行localall all trusthostall all127.0.0.1/32 trust#3.sudogitlab-ctl restartsu- gitlab-psql /opt/gitlab/embedded/bin/psql-h127.0.0.1 gitlabhq_productiongitlabhq_production# ALTER USER gitlab WITH SUPERUSER;ALTER ROLEgitlabhq_production# \q#4. 再次恢复数据已不报错参考解决方法#backup目录权限改为git用户权限sudochowngit:git /var/opt/gitlab/backups#对应于gitlab.rb中的backup路径恢复配置#恢复密码配置sudocp~/Downloads/etc/gitlab/gitalb-secrets.json /etc/gitlabsudogitlab-ctl restart#重启服务sudogitlab-rake gitlab:checkSANITIZEtrue#检查恢复情况迁移需要先对齐版本对旧版本进行升级到迁移目的机新版本一致才行下载地址各版本升级路径迁移备份参考:手动备份在就版本机中进行 备份数据和备份配置迁移恢复#查看旧服务器gitlab版本号cat/opt/gitlab/embedded/service/gitlab-rails/VERSION#将新服务器安装相同版本gitlab#sudo dpkg -i /mnt/disk2/tools/git/gitlab-ce_12.9.2-ce.0_amd64.debsudoaptinstallgitlab-ceversion#sudo apt install gitlab-ce12.9.2-ce.0#启动新版本#复制备份中的配置gitlab.rb到新服务器/etc/gitlab/中,注意修改backup等参数为新服务器中的路径sudogitlab-ctl reconfigure再参考:恢复升级升级过程的问题Error executing actionrunon resourcebash[migrate gitlab-rails database]原因是升级版本一次跨度太大造成的如下是12.9.2升级到15.1.0的版本步骤路径需要多此小步骤升级实测成功升级记录12.9.2-12.10.14-13.0.14- 13.1.11-13.8.8 -13.12.15-14.0.12-14.3.6-14.6.2-14.9.4-14.10.3 - 15.0.2 - 15.1.0GitLab 8: 8.11.Z 8.12.0 8.17.7GitLab 9: 9.0.13 9.5.10GitLab 10: 10.0.7 10.8.7GitLab 11: 11.0.6 11.11.8GitLab 12: 12.0.12 12.1.17 12.10.14GitLab 13: 13.0.14 13.1.11 13.8.8 13.12.15GitLab 14: 14.0.12 14.3.6 14.9.5 14.10.5GitLab 15: 15.0.5 15.1.6 15.4.6 15.11.0#1. 查看旧服务器gitlab版本号cat/opt/gitlab/embedded/service/gitlab-rails/VERSIONsudogitlab-ctl start#启动旧版本gitlab服务,如果已经启动,跳过此步骤,#2. 根据版本升级路径安装最近的版本sudoaptinstallgitlab-ceversion#sudo apt install gitlab-ce12.9.2-ce.0#3. 启动新版本sudogitlab-ctl reconfigure# 4. 如果是最新版本- 终止操作. 如果不是最新版本 - 跳到步骤 #2. 继续升级如果没有启动gitlab服务,升级时会出现如下错误:connections on Unix domain socket “/var/opt/gitlab/postgresql/.s.PGSQL.5432”?因为升级时必须保证所有条件匹配时才能升级成功本机升级sudoaptinstallgitlab-ceversion#sudo apt install gitlab-ce12.9.2-ce.0#将备份好的gitlab-secrets.json,gitlab.rb 覆盖/etc/gitlab/中的配置文件sudogitlab-ctl reconfiguresudogitlab-ctl upgradesudogitlab-ctl restartgitlab runner参考https://blog.csdn.net/lzxlfly/article/details/84071806远程clone问题gitclone gitxxxxx:prj#如果无法克隆则建议使用http方式clonegitclone http:ip:port/prj#忘记密码# centossudogitlab-rails console production# ubuntusudogitlab-rails console#此命令等待时间比较长请耐心等待# 根据邮箱或账号查找用户userUser.find_by(email:注册邮箱账号)#或者userUser.find_by(username:注册账号)# 修改密码user.passwordxxxxxx# 保存密码千万不要忘记这一步user.save!# 退出exit#然后新密码重新登陆试试问题https://docs.gitlab.com/omnibus/common_installation_problems/
返回列表