本文最后更新于 2024-08-08,文章内容可能已经过时。

搭建

点击查看官方搭建教程: https://about.gitlab.cn/install/

卸载

gitlab-ctl stop //停止
ps aux | grep gitlab //查看相关进程
kill 进程ID //杀掉主进程

//删除对应文件!
rm -rf  /opt/gitlab
rm -rf  /etc/gitlab
rm -rf  /var/log/gitlab

管理

gitlab-ctl start //启动所有组件
gitlab-ctl stop //停止所有组件
gitlab-ctl restart //重启所有组件
gitlab-ctl start redis/postgresql/gitlab-workhorse/logrotate/nginx/sidekiq/unicorn  //启用指定组件
gitlab-ctl stop 模块名  //停用指定组件
gitlab-ctl status //查看状态
gitlab-ctl reconfigure //生成配置并启动服务
gitlab-ctl tail redis/postgresql/gitlab-workhorse/logrotate/nginx/sidekiq/unicorn //实时查看所有日志

gitlab-ctl tail  //实时查看日志
gitlab-rake db:migrate //数据库关系升级
gitlab-rake cache:clear //清理redis缓存
yum update gitlab-ce //升级GitLab-ce 版本
gitlab-ctl pg-upgrade //升级PostgreSQL最新版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION  //查看当前版本
cat /etc/gitlab/initial_root_password //查看初始密码

Gitlab服务构成

nginx: 静态web服务器 gitlab-shell: 用于处理Git命令和修改authorized keys列表 gitlab-workhorse: 轻量级的反向代理服务器 logrotate:日志文件管理工具 postgresql:数据库 redis:缓存数据库 sidekiq:用于在后台执行队列任务(异步执行) unicorn:HTTP服务,GitLab Rails应用是托管在这个服务器上面的。

主要配置文件目录

主配置文件: /etc/gitlab/gitlab.rb 文档根目录: /opt/gitlab 默认存储库位置: /var/opt/gitlab/git-data/repositories Nginx配置文件: /var/opt/gitlab/nginx/conf/gitlab-http.conf Postgresql数据目录: /var/opt/gitlab/postgresql/data

重设管理员或指定用户密码

[root@test bin]# gitlab-rails console production
-------------------------------------------------------------------------------------
 GitLab:       11.10.4 (62c464651d2)
 GitLab Shell: 9.0.0
 PostgreSQL:   9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.2)
irb(main):001:0> user = User.where(id:1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = 'qwer1234'
=> "qwer1234"
irb(main):003:0> user.password_confirmation = 'qwer1234'
=> "qwer1234"
irb(main):004:0> user.save
Enqueued ActionMailer::DeliveryJob (Job ID: 4752a4a4-4e85-4e8b-9f27-72788abfe97c) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f519e7501d8 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
irb(main):005:0> exit

使用smtp来发送邮件通知

vim /etc/gitlab/gitlab.rb
gitlab_rails['smtp_address'] = "smtp.yourdomain.com" gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "xxx"
gitlab_rails['smtp_password'] = "xxx"
gitlab_rails['smtp_domain'] = "smtp.yourdomain.com" gitlab_rails['smtp_authentication'] = 'plain'
gitlab_rails['smtp_enable_starttls_auto'] = true

配置gitlab访问方式为https

# 创建ssl证书存放目录
mkdir -p /etc/gitlab/ssl
chmod 0700 /etc/gitlab/ssl

# 上传证书,修改证书访问权限
chmod 600 /etc/gitlab/ssl/gitlab.xxx.com.crt

# 修改住配置,支持ssl访问
vim /etc/gitlab/gitlab.rb
external_url "[https://gitlab.79tian.com]  (https://gitlab.79tian.com)"
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.xxx.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.xxx.com.key"

# 重启
gitlab-ctl reconfigure# 开启防火墙  firewall-cmd --zone=public --add-port=443/tcp --permanent  firewal-cmd reload

备份

/var/opt/gitlab/backups //默认备份目录
gitlab-rake gitlab:backup:create //开始备份

#修改默认备份目录
vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = '/data/backups'  //新目录

#恢复数据[需要版本相同]
gitlab-rake gitlab:backup:restore BACKUP=serail_number_date[压缩包日期]