GitLab安装经验分享

GitLab简介

    GitLab是一个代码管理平台,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。它拥有与GitHub类似的功能,能够浏览源代码,管理缺陷,可以管理团队对仓库的访问。它非常易于浏览提交过的版本并提供一个文件历史记录。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。
    GitLab 分为 GitLab Community Edition(CE) 社区版 和 GitLab Enterprise Edition(EE) 专业版。社区版免费,专业版收费,不同版本在功能上的差异对比,请参考GitLab官网

GitLab安装

安装环境

CentOS 7.5 64bit

安装步骤

1.安装依赖包并设置sshd服务开机自启

yum install -y curl policycoreutils-python openssh-server
systemctl enable sshd
systemctl start sshd

2.防火墙配置
开启防火墙并设置为开机自启

systemctl start firewalld
systemctl enable firewalld

开放http服务

firewall-cmd --permanent --add-service http

说明:参数–pemmanent表示永久生效,若不加–permanent系统下次启动后就会失效。

加载防火墙配置

firewall-cmd --reload

查看防火墙开通了哪些端口及服务

firewall-cmd --list-all

可选:其它服务及端口

firewall-cmd --permanent --add-service ssh
firewall-cmd --permanent --add-service https
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --permanent --zone=public --add-port=8080/tcp

说明:更改配置之后需要重新加载防火墙配置

3.配置yum源
由于官方安装指导资源为国外资源,推荐使用清华大学开源软件镜像源。
/etc/yum.repos.d新增GitLab-CE.repo,并写入以下内容。

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

4.更新yum缓存

yum makecache

5.安装最新社区版GitLab

yum install gitlab-ce

GitLab基础配置

GitLab的配置都在文件/etc/gitlab/gitlab.rb中完成

建议:除了URL,其它配置都在文件的末尾添加,方便以后维护。

URL配置

在文件的第13行设置访问地址,有域名可以填写域名,没域名填写IP地址

external_url 'http://gitlab.example.com'

邮箱配置

下面是以163为例

### Email Config ###
### date 2018-12-19 ###
### Use smtp instead of sendmail/postfix
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtphm.qiye.163.com"
gitlab_rails['smtp_port'] = 25 
gitlab_rails['smtp_user_name'] = "smtp user"
gitlab_rails['smtp_password'] = "smtp passwd"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
##修改gitlab配置的发信人
gitlab_rails['gitlab_email_from'] = "smtp user"

数据存储路径配置

设置仓库存储地址

### git data dir
git_data_dirs({
  "default" => {
    "path" => "/home/gitlab"
   }
})

加载配置

执行gitlab命令加载之前的配置,使配置生效。

gitlab-ctl reconfigure

访问GitLab

在浏览器输入前面配置的URL,访问GitLab,第一次访问时,会让你设置管理员密码,设置完成后会转到登录界面。使用刚才设置的密码登录即可,登录账号为root.

其它配置

LDAP配置

gitlab_rails['ldap_enabled'] = true
###! **remember to close this block with 'EOS' below**
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
  main: # 'main' is the GitLab 'provider ID' of this LDAP server
    label: 'LDAP'
    host: '_your_ldap_server'
    port: 389
    uid: 'uid' #sAMAccountName
    encryption: 'plain' # "start_tls" or "simple_tls" or "plain"
    bind_dn: 'cn=admin,dc=com,dc=com' #访问LDAP的账户,按照实际情况填写
    password: 'your passwd'
    active_directory: false    
    allow_username_or_email_login: true
    lowercase_usernames: true
    block_auto_created_users: false
    base: 'ou=example,dc=com,dc=com' #按照实际情况填写域
    user_filter: ''
EOS

性能优化

unicorn['worker_processes'] = 2
unicorn['worker_memory_limit_min'] = "200 * 1 << 20"
unicorn['worker_memory_limit_max'] = "300 * 1 << 20"
sidekiq['concurrency'] = 8
postgresql['shared_buffers'] = "256MB"
postgresql['max_worker_processes'] = 4

数据备份

GitLab的默认备份目录是/var/opt/gitlab/backups,在配置文件中添加下面字段表示:
1.修改备份路径为/home/gitlab-backup
2.保留最近一周的备份数据

### GitLab backup
gitlab_rails['backup_path'] = "/home/gitlab-backup"
###! The duration in seconds to keep backups before they are allowed to be deleted
gitlab_rails['backup_keep_time'] = 604800

执行备份

gitlab-rake gitlab:backup:create

该命令会在备份目录/home/gitlab-backup(默认:/var/opt/gitlab/backups/)下创建一个tar压缩包,格式为xxxxxxxx_gitlab_backup.tar,其中开头的xxxxxx是创建备份的时间戳以及gitlab版本信息,这个压缩包包括GitLab整个的完整部分。

添加备份任务

通过任务计划crontab 实现自动备份
执行以下命令查看crontab基本用法

vim /etc/crontab

执行命令添加备份任务

crontab -e

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

表示每天凌晨两点执行命令gitlab-rake gitlab:backup:create

查看已有任务

crontab -l

重启crond服务使配置生效

systemctl restart crond

数据恢复

添加权限

对已经备份的文件添加777权限

chmod 777 xxxxxxxx_gitlab_backup.tar

停止服务

停止unicorn和sidekiq服务

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

恢复数据

gitlab-rake gitlab:backup:restore BACKUP=xxxxxxxx_gitlab_backup.tar

GitLab常用命令

  • 查看版本
    cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
  • 检查GitLab状态
    gitlab-rake gitlab:check SANITIZE=true --trace
  • 清理redis缓存
    gitlab-rake cache:clear
  • 启动GitLab服务
    gitlab-ctl start
  • 停止GitLab服务
    gitlab-ctl stop
  • 重启GitLab服务
    gitlab-ctl restart
  • 查看服务状态
    gitlab-ctl status
  • 加载配置并启动服务
    gitlab-ctl reconfigure
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值