部署

添加映射

vim /etc/hosts

192.168.1.101 gitlab.wakamizu.club

添加社区版Package

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

安装

yum install -y gitlab-ce

安装成功会显示以下画面

gitlab配置文件路径

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

配置gitlab站点

vim /etc/gitlab/gitlab.rb

external_url 'http://gitlab.wakamizu.club'

配置服务并启动

gitlab-ctl reconfigure

访问前端(http://gitlab.wakamizu.club)

设置root密码

gitlab邮箱配置

vim /etc/gitlab/gitlab.rb

#配置SMTP服务器参数
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.server"  #smtp服务器
gitlab_rails['smtp_port'] = 465 #smtp服务端口
gitlab_rails['smtp_user_name'] = "smtp user"  #smtp用户/邮箱
gitlab_rails['smtp_password'] = "smtp password" #smtp授权码
gitlab_rails['smtp_domain'] = "example.com" #smtp服务器
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true    
#配置邮件发送参数
gitlab_rails['gitlab_email_enabled'] = true  #开启email功能
gitlab_rails['gitlab_email_from'] = '[email protected]'  #邮箱
gitlab_rails['gitlab_email_display_name'] = 'Example'  #email显示名字

gitlab-ctl reconfigrue

测试发送

gitlab-rails console
Notify.test_email('
你的收件邮箱', '测试邮件标题', '测试邮件正文').deliver_now

配置HTTPS

mkdir /etc/gitlab/ssl

上传证书

vim /etc/gitlab/gitlab.rb

external_url "https://gitlab.wakamizu.club"
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.wakamizu.club.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.wakamizu.club.key"

gitlab-ctl reconfigure

修改root密码

gitlab-rails console production
user=User.where(id:1).first
user.password='
new_password'
user.password_confirmation='
new_password'
user.save

gitlab-ctl命令参数

gitlab运维管理命令

查看版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

检查
gitlab gitlab-rake gitlab:check SANITIZE=true --trace

实时查看日志
gitlab-ctl tail

数据库关系升级
gitlab-rake db:migrate

清理redis缓存
gitlab-rake cache:clear

升级GitLab-ce 版本
yum update gitlab-ce

升级PostgreSQL最新版本
gitlab-ctl pg-upgrade

实时查看所有日志
gitlab-ctl tail

实时查看某组件日志

gitlab-ctl tail 组件名<redis|postgresql|gitlab-workhorse|logrotate|nginx|sidekiq|unicorn>

gitlab备份/恢复操作

备份目录配置

vim /etc/gitlab/gitlab.rb

gitlab_rails['backup_path'] = '/var/opt/gitlab/backups' 
#默认目录

gitlab-ctl reconfigure

备份

gitlab-rake gitlab:backup:create

注意红字警告部分,gitlab.rb和gitlab-secerts.json需要手动备份
gitlab.rb路径:/etc/gitlab/gitlab.rb
gitlab-secrets.json路径:/etc/gitlab/gitlab-secrets.json

恢复备份

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore BACKUP=
备份文件名(不加上_gitlab_backup.tar)
复制手动备份的两个配置文件到对应路径后启动服务
gitlab-ctl reconfigure
gitlab-ctl start

备份有效期配置

vim /etc/gitlab/gitlab.rb

gitlab_rails['backup_keep_time'] = 604800 
#单位:秒