News:三分天注定,七分靠打拼,爱拼才会赢!致力打造专业IT博客。如果你对本博客有任何意见或建议请联系作者,邮箱:blog@mymail.com.cn

GitLab 服务器搭建

逝水无痕 3493 0 条

GitLab 是一个用于仓库管理系统的开源项目,使用 Git 作为代码管理工具,并在此基础上搭建起来的 web 服务。目前很多的公司和团队都在使用 GitLab。本篇文章将介绍对于中小团队来说如何搭建 GitLab 服务器(4 核 8G 服务器)。

gitlab.jpg

安装 Docker

详见《CentOS 7 安装 Docker 及 MySQL、Redis

拉取镜像

docker pull gitlab/gitlab-ce:11.11.8-ce.0

启动容器

docker run -d --hostname git.caokuan.cn --expose 80 \
  --name gitlab \
  --restart always \
  -v /home/gitlab/config:/etc/gitlab \
  -v /home/gitlab/logs:/var/log/gitlab \
  -v /home/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ce:11.11.8-ce.0
  • --hostname 指定一个域名即可
  • --expose 80 表示暴露容器的80端口,可以使用 nginx 代理该容器的80端口,访问更安全
  • --restart always 容器随 docker 启动

如果需要调整容器运行时的内存,则执行如下命令即可:

docker update -m 4G --memory-swap 4G gitlab

基础配置

配置文件位置:/home/gitlab/config/gitlab.rb

邮箱设置

### Email Settings
# gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = 'gitapp@mymail.com.cn'
gitlab_rails['gitlab_email_display_name'] = 'GitApp'
gitlab_rails['gitlab_email_reply_to'] = 'gitapp@mymail.com.cn'
# gitlab_rails['gitlab_email_subject_suffix'] = ''

...
...

### GitLab email server settings
###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html
###! **Use smtp instead of sendmail/postfix.**

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.mxhichina.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "gitapp@mymail.com.cn"
gitlab_rails['smtp_password'] = "这里是邮箱密码"
gitlab_rails['smtp_domain'] = "smtp.mxhichina.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

以 4 核 8G 服务器为例设置内存占用等参数

###! Minimum worker_processes is 2 at this moment
###! See https://gitlab.com/gitlab-org/gitlab-ce/issues/18771
unicorn['worker_processes'] = 4

...
...

### **Only change these settings if you understand well what they mean**
###! Docs: https://about.gitlab.com/2015/06/05/how-gitlab-uses-unicorn-and-unicorn-worker-killer/
###!       https://github.com/kzk/unicorn-worker-killer
unicorn['worker_memory_limit_min'] = "400 * 1 << 20"
unicorn['worker_memory_limit_max'] = "600 * 1 << 20"

...
...

################################################################################
## GitLab Sidekiq
################################################################################

# sidekiq['log_directory'] = "/var/log/gitlab/sidekiq"
# sidekiq['log_format'] = "json"
# sidekiq['shutdown_timeout'] = 4
sidekiq['concurrency'] = 15
# sidekiq['metrics_enabled'] = true
# sidekiq['listen_address'] = "localhost"
# sidekiq['listen_port'] = 8082

...
...

##! **recommend value is 1/4 of total RAM, up to 14GB.**
postgresql['shared_buffers'] = "256MB"

...
...

postgresql['max_worker_processes'] = 8

参数修改完成后重启 GitLab 服务器

## 连接容器
docker exec -it gitlab bash

## 执行以下命令
gitlab-ctl reconfigure
gitlab-ctl restart
发表我的评论
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址