Gitlab 配置

简介

Gitlab是一个用Ruby on Rails开发的开源项目管理程序.可以通过WEB界面进行访问公开的或者私人项目. 它和Github有类似的功能,能够浏览源代码,管理缺陷和注释.

本文选择NGINX与MYSQL来配合GitLab实现web管理,数据存储等功能,配置过程中难点基本在GitLab的脚本修改,SSH秘钥连接,Nginx SSL证书等这些方面,作者也是耗费非常大的力气,结合很多文档的clue以及很多老外的debug comment,终于最终完成,希望在此给大家一个抛砖引玉的机会,了解到SCM(软件配置管理)其实也不是想象中那么小儿科,很多逻辑也着实需要下功夫investigation.

环境

环境部署
操作系统 centos6.3 x64
GitLab GitLab 6-3-stable
GitLab Shell 1.8.0
Ruby 2.0.0p353
NGINX nginx-1.4.0
MYSQL mysql-5.6.10

Git server(centos6.3 x64): git.example.com
Git client(centos6.3 x64): client.example.com

server端配置:

安装前的准备工作

  1. 关闭iptables和SELINUX
1
2
3
4
5
6
# service iptables stop
# setenforce 0
# vi /etc/sysconfig/selinux
---------------
SELINUX=disabled
---------------
  1. 同步时间
1
# ntpdate cn.pool.ntp.org
  1. 安装GitLab的所需依赖包和工具
1
2
3
4
# su -
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-5-4.noarch.rpm
# yum -y groupinstall 'Development Tools'
# yum -y install vim-enhanced readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel redis sudo wget crontabs logwatch logrotate perl-Time-HiRes git
  1. 配置redis
    配置redis开机启动:
1
2
# chkconfig redis on
# service redis start
  1. 更改gem源(若默认无法连接)
1
2
3
4
5
6
7
8
a.显示当前使用的sources
# gem sources
b.删除缺省source
# gem sources -r http://rubygems.org/
c.添加一个source
# gem sources -a https://ruby.taobao.org
d.更新source cache
# gem sources -u
  1. 安装Ruby
    a.源码安装Ruby
    b.安装bundle组件:
1
# gem install bundler --no-ri --no-rdoc

安装GITLab shell

  1. 创建用户git
1
2
# su -
# adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
  1. 配置GitLab shell
    GitLab shell是专门为GitLab开发的提供ssh访问和版本管理的软件。
1
2
3
4
5
6
7
a.使用git账户登陆
# su - git
b.克隆gitlab shell
# git clone https://github.com/gitlabhq/gitlab-shell.git
c.切换成1.8.0版本,并编辑配置
# cd gitlab-shell
# git checkout v1.8.0
1
2
3
4
5
6
7
8
9
d.拷贝配置文件
# cp config.yml.example config.yml
# vi config.yml
# 将gitlab_url修改成gitlab的访问域名。例如本文档:https://git.example.com/
gitlab_url: "https://git.example.com"
# 将self_signed_cert修改成 true
self_signed_cert: true
# 添加网站SSL证书
ca_file: "/usr/local/nginx/ssl/gitlab.crt"

注:如果gitlab是使用http访问,则需将https替换成http,配置文件中的self_signed_cert要修改成false,否则gitlab shell在通过api和gitlab进行通信的时候就会出现错误,导致项目push出错。因为后面配置web服务器的时候是使用ssl,所以这里要按照ssl的方式配置。
另外本文档的域名为测试域名,不要忘记在C/S两端均做好域名映射。

1
2
e.安装一些需要的目录和文件
# ./bin/install
  1. 配置MySQL数据库
1
2
3
4
5
6
7
8
a.登录数据库
# mysql -u root -p
b. 为gitlab创建使用用户
> create user gitlab@'localhost' identified by '123456';
c.创建gitlaba使用的数据库
> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
d.给予gitlab用户权限
> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

安装GitLab

  1. 将GitLab安装在git的家目录下:
1
# su - git
  1. 克隆GitLab并切换分支到6-3-stable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
a.克隆GitLab
# git clone https://github.com/gitlabhq/gitlabhq.git gitlab
b. 切换到6-3-stable分支
# cd /home/git/gitlab
# git checkout 6-3-stable
c、配置项目
a.复制配置文件
# cp config/gitlab.yml.example config/gitlab.yml
b.修改配置文件中的访问域名
# sed -i 's|localhost|git.example.com|g' config/gitlab.yml
d.设定log和tmp目录所有者和权限
# chown -R git log/
# chown -R git tmp/
# chmod -R u+rwX log/
# chmod -R u+rwX tmp/
e.创建gitlab-satellites目录
# mkdir /home/git/gitlab-satellites
f.创建tmp/pids/和tmp/sockets/目录,确保gitlab有相应的权限
# mkdir tmp/pids/
# mkdir tmp/sockets/
# chmod -R u+rwX tmp/pids/
# chmod -R u+rwX tmp/sockets/
g.创建public/uploads目录
# mkdir public/uploads
# chmod -R u+rwX public/uploads
h.复制unicorn配置
# cp config/unicorn.rb.example config/unicorn.rb
i.保持unicorn配置文件默认配置
g.配置git的用户和邮件
# git config --global user.name "GitLab"
# git config --global user.email "gitlab@git.example.com”
# git config --global core.autocrlf input
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
k.配置数据库访问文件
# cp config/database.yml.mysql config/database.yml
编辑config/database.yml,设置其中连接数据库的账号密码
# vi config/database.yml
———————————————————————————————————
#
# PRODUCTION
#
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 10
username: gitlab
password: “123456”
# host: localhost
# socket: /tmp/mysql.sock
———————————————————————————————————
修改其中username和password就可以了,其中密码就是上面数据库步骤中创建gitlab用户的密码。
1
2
l.确保该文件只有git账号有权限读取。
# chmod o-rwx config/database.yml

安装Gems

  1. 安装charlock_holmes
1
2
3
# su -
# gem install charlock_holmes --version '0.6.9.4'
# exit
  1. 安装mysql包
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# cd /home/git/gitlab/
# vi Gemfile
修改 https://rubygems.org 为 https://ruby.taobao.org
# bundle install --deployment --without development test postgres puma aws
若报Could not find modernizr-2.6.2 in any of the sources错误,没有则无视:
修复方案:
# vi Gemfile
搜索该行 gem "modernizr", "2.6.2"
更改为: gem "modernizr-rails", "2.7.1"
# vi Gemfile.lock
搜索该行 modernizr (2.6.2)
更改为: modernizr-rails (2.7.1)
搜索该行 modernizr (= 2.6.2):
更改为: modernizr-rails (= 2.7.1)
重新执行
# bundle install --deployment --without development test postgres puma aws
  1. 初始化数据和激活高级功能
1
2
3
4
# cd /home/git/gitlab
# bundle exec rake gitlab:setup RAILS_ENV=production
这步完成后,会生一个默认的管理员账号/密码:
admin@local.host/5iveL!fe
  1. 安装启动脚本
1
2
3
# su -
# wget -O /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/5-0-stable/init.d/gitlab
# chmod +x /etc/init.d/gitlab

5.开机时启动

1
2
# chkconfig --add gitlab
# chkconfig gitlab on

6.检测应用程序状态

1
2
3
4
# su - git
# cd gitlab/
# bundle exec rake gitlab:env:info RAILS_ENV=production
# exit

可以查看到系统、Ruby、GitLab和GitLab Shell的版本和其他信息。

  1. 启动GitLab实例
1
# service gitlab start
  1. 查看应用更加详细的信息
1
2
3
4
5
6
7
8
9
10
11
12
13
# su - git
# cd gitlab/
# bundle exec rake gitlab:check RAILS_ENV=production
这里会提示一个Init script up-to-date的错误,如下:
——————————————————————————————————————————————————
Init script up-to-date? ... no
Try fixing it:
Redownload the init script
For more information see:
doc/install/installation.md in section "Install Init Script"
Please fix the error above and rerun the checks.
——————————————————————————————————————————————————
查阅官方自带文档,说明此问题可忽略.

Nginx配置

  1. 配置Gitlab虚拟主机及SSL连接:
1
2
3
4
# cd /usr/local/nginx/conf/vhosts/
# vi gitlab-ssl.conf
注: 这里先感谢提供此脚本的极客,该脚本在原基础上稍作改动.
内容用红字标注的地方为需要自定义的地方.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
## GitLab
## Contributors: randx, yin8086, sashkab, orkoden, axilleas
## App Version: 5.4 - 6.0
##
## Modified from nginx http version
## Modified from http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/
##
## Lines starting with two hashes (##) are comments containing information
## for configuration. One hash (#) comments are actual configuration parameters
## which you can comment/uncomment to your liking.
##
###################################
## SSL configuration ##
###################################
##
## Optimal configuration is taken from:
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
## Make sure to read it and understand what each option does.
##
## [Optional] Generate a self-signed ssl certificate:
## mkdir /etc/nginx/ssl/
## cd /etc/nginx/ssl/
## sudo openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
## sudo chmod o-r gitlab.key
##
## Edit `gitlab-shell/config.yml`:
## 1) Set "gitlab_url" param in `gitlab-shell/config.yml` to `https://git.example.com`
## 2) Set "ca_file" to `/etc/nginx/ssl/gitlab.crt`
## 3) Set "self_signed_cert" to `true`
## Edit `gitlab/config/gitlab.yml`:
## 1) Define port for http "port: 443"
## 2) Enable https "https: true"
## 3) Update ssl for gravatar "ssl_url: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm"
##
##################################
## CHUNKED TRANSFER ##
##################################
##
## It is a known issue that Git-over-HTTP requires chunked transfer encoding [0]
## which is not supported by Nginx < 1.3.9 [1]. As a result, pushing a large object
## with Git (i.e. a single large file) can lead to a 411 error. In theory you can get
## around this by tweaking this configuration file and either:
## - installing an old version of Nginx with the chunkin module [2] compiled in, or
## - using a newer version of Nginx.
##
## At the time of writing we do not know if either of these theoretical solutions works. As a workaround
## users can use Git over SSH to push large files.
##
## [0] https://git.kernel.org/cgit/git/git.git/tree/Documentation/technical/http-protocol.txt#n99
## [1] https://github.com/agentzh/chunkin-nginx-module#status
## [2] https://github.com/agentzh/chunkin-nginx-module
upstream gitlab {
## Uncomment if you have set up puma/unicorn to listen on a unix socket (recommended).
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
## Uncomment if puma/unicorn are configured to listen on a tcp port.
## Check the port number in /home/git/gitlab/config/{puma.rb/unicorn.rb}
# server 127.0.0.1:8080;
}
## This is a normal HTTP host which redirects all traffic to the HTTPS host.
server {
listen *:80;
## Replace git.example.com with your FQDN.
server_name git.example.com;
server_tokens off;
## This doesn't have to be a valid path since we are redirecting,
## you don't have to change it.
root /nowhere;
rewrite ^ https://$server_name$request_uri permanent;
}
server {
listen 443 ssl;
## Replace git.example.com with your FQDN.
server_name git.example.com;
server_tokens off;
root /home/git/gitlab/public;
## Increase this if you want to upload large attachments
## Or if you want to accept large git objects over http
client_max_body_size 20m;
## Strong SSL Security
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
ssl on;
ssl_certificate /usr/local/nginx/ssl/gitlab.crt;
ssl_certificate_key /usr/local/nginx/ssl/gitlab.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache builtin:1000 shared:SSL:10m;

#add_header Strict-Transport-Security max-age=63072000;
#add_header X-Frame-Options DENY;
#add_header X-Content-Type-Options nosniff;
## Individual nginx logs for this GitLab vhost
access_log /usr/local/nginx/logs/gitlab_access.log;
error_log /usr/local/nginx/logs/gitlab_error.log;
location / {
## Serve static files from defined root folder.
## @gitlab is a named location for the upstream fallback, see below.
try_files $uri $uri/index.html $uri.html @gitlab;
}
## If a file, which is not found in the root folder is requested,
## then the proxy pass the request to the upsteam (gitlab unicorn).
location @gitlab {
## If you use https make sure you disable gzip compression
## to be safe against BREACH attack.
gzip off;
## https://github.com/gitlabhq/gitlabhq/issues/694
## Some requests take more than 30 seconds.
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Ssl on;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:8080;
}
## Enable gzip compression as per rails guide:
## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
location ~ ^/(assets)/ {
root /home/git/gitlab/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
error_page 502 /502.html;
}
  1. 将nginx加入git用户组(重要)
1
2
# usermod -a -G git nginx
# chmod g+rx /home/git/
  1. 生成ssl证书
1
2
3
# mkdir /usr/local/nginx/ssl
# cd /usr/local/nginx/ssl
# openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
  1. 开启Git over SSL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# vi /home/git/gitlab/config/gitlab.yml
## GitLab settings
gitlab:
## Web server settings
host: git.example.com
port: 443
https: true
# vi /home/git/gitlab-shell/config.yml
gitlab_url: "https://git.example.com"
http_settings:
# user: someone
# password: somepass
# ca_file: /etc/ssl/cert.pem
# ca_path: /etc/ssl/
self_signed_cert: true

ca_file: "/usr/local/nginx/ssl/gitlab.crt"
  1. 启动nginx
1
# service nginx start
  1. 打开web页面 git.example.com
    nginx直接跳转URL为https://git.example.com

GitLab默认的账号密码如下:
admin@local.host/5iveL!fe

Client端配置:

上传git仓库

  1. 客户端生成秘钥
1
2
# cd ~
# ssh-keygen -t rsa

一路回车后生成公钥和秘钥对
$ cat ~/.ssh/id_rsa.pub

将这里生成的公钥全部复制并粘贴到gitlab web SSH Keys后台保存即可。

  1. 测试SSH连接
1
# ssh -p22 git@git.example.com

若报如下错误:
——————————————————————————————————————
PTY allocation request failed on channel 1
/usr/bin/env: ruby: No such file or directory
Connection to git.example.com closed.
——————————————————————————————————————
说明服务端ruby环境变量未在此目录/usr/bin/ruby
在服务器端加此软链即可:

1
# ln -s /usr/local/ruby/bin/ruby /usr/bin/ruby

注:若服务器端SSH自定义端口,则需要在客户端~/.ssh/config下添加端口配置
假定自定义SSH端口为2222

1
# echo “Port 2222” >> ~/.ssh/config
  1. 命令行上传git仓库
1
2
3
4
5
6
7
8
9
# su - 
# mkdir testprojiect
# cd testprojiect/
# git init
# echo "What a fucking Hello World" > readme.txt
# git add .
# git commit -m 'first commit'
# git remote add origin git@git.example.com:root/testproject.git
# git push -u origin master

问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
注: 若主页CSS出现错误未加载, 可从新编译assets, 可从新获取CSS文件.
# cd /home/git/gitlab
# bundle exec rake assets:precompile RAILS_ENV=production

注: 解决Gravatar的头像加载timeout问题
搜索plain_url部分, 将原有部分改成:
plain_url: "http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon"
#cd /home/git/gitlab
清除缓存
# RAILS_ENV=production bundle exec rake cache:clear
# service gitlab restart

注: 解决内存耗尽问题
如果你的VPS 为1G内存+1核处理器
建议将默认的unicorn worker_process设置为2, timeout设定为60s, 这样就不会因为长时间加载web页面而出现timeout等问题.
# vi /home/git/gitlab/config/unicorn.rb

Docker 部署 GitLab

获取 GitLab 镜像

1
docker pull gitlab/gitlab-ce:11.7.5-ce.0

查看本地镜像

1
docker images

创建目录

1
mkdir -p /data/gitlab/{config,data,logs}

创建并运行容器

1
2
3
4
5
6
7
8
9
docker run --detach \
--hostname gitlab.ovwane.com \
--publish 10443:443 --publish 80:80 --publish 10022:22 \
--name gitlab \
--restart always \
--volume ${PWD}/gitlab/config:/etc/gitlab:Z \
--volume ${PWD}/gitlab/logs:/var/log/gitlab:Z \
--volume ${PWD}/gitlab/data:/var/opt/gitlab:Z \
gitlab/gitlab-ce:12.10.1-ce.0

查看运行状态

1
2
docker ps
netstat -ntulap | grep docker

修改配置文件

添加https, 需要导入证书

1
2
3
4
5
6
# 进入挂载配置目录
cd /data/gitlab/config
# 创建密钥文件夹, 并放入证书
mkdir ssl;cd ssl
# 移动证书,使用的是Let’s Encrypt证书
mv fullchain.cer 域名.key .

修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
vi /data/gitlab/config/gitlab.rb

###################################################
# 添加外部请求的域名(如果不支持https, 可以改成http)
external_url 'https://git.xxx.com'
# 修改gitlab对应的时区
gitlab_rails['time_zone'] = 'Asia/Shanghai'
# 配置ssl参数
nginx['enable'] = true
nginx['redirect_http_to_https'] = false
nginx['redirect_http_to_https_port'] = 443
nginx['ssl_certificate'] = "/etc/gitlab/ssl/fullchain.cer"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/域名.key"
###################################################

重启服务

1
2
3
# 登陆容器, 重启配置
docker exec -it xxxxxx bash
gitlab-ctl reconfigure

访问 GitLab

  • https://git.xxx.com

    • 默认用户名:root
    • 如果没有域名,直接使用 IP 访问即可。

gitlab-runner

安装gitlab-runner

1
2
3
4
docker run -d --name gitlab-runner-11.1.0 --restart always \
-v /data/gitlab-runner/config:/etc/gitlab-runner \
-v /var/run/docker.sock:/var/run/docker.sock \
gitlab/gitlab-runner:v11.1.0

参数说明:

  • -d: 设置容器后台运行
  • –name:容器名称
  • -restart always:每次启动容器就重启 gitlab-runner
  • -v: 共享目录挂载

安装好后,执行$ docker ps查看容器是否运行。

注册和初始化

编辑vim /data/gitlab-runner/config/config.toml,手动修改配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
concurrent = 1
check_interval = 0

[[runners]]
name = "runner1"
url = "https://git.xxx.com"
token = "e7b1109634c7082f3363fccbb9f165"
executor = "docker"
[runners.docker]
tls_verify = false
image = "ruby:2.1"
privileged = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[runners.cache]

或者交互式注册runner信息

1
docker exec -it gitlab-runner gitlab-ci-multi-runner register
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# gitlab-ci-multi-runner register
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
# https://git.xxx.com
Please enter the gitlab-ci token for this runner:
# v7YsuyhYduqSyxJi8fmW #在gitlib中寻找runner token
Please enter the gitlab-ci description for this runner:
# alpine 3.8
Please enter the gitlab-ci tags for this runner (comma separated):
# qa
Registering runner... succeeded runner=v7YsuyhY
Please enter the executor: kubernetes, parallels, ssh, docker+machine, virtualbox, docker-ssh+machine, docker, docker-ssh, shell:
# docker
Please enter the default Docker image (e.g. ruby:2.1):
# alpine:3.8
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

注册后使用 gitlab-runner list 查阅配置

gitlab-runner unregister 命令

  1. 通过 url 和 token 取消注册 gitlab-runner unregister --url https://git.xxx.com/ --token t0k3n
  2. 通过name取消注册 gitlab-runner unregister --name test-runner
  3. 删除所有注册runner gitlab-runner unregister --all-runners

docker-compose.yml

时间没有搞定

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# https://docs.gitlab.com/omnibus/docker/
version: '3'
services:
gitlab:
image: gitlab/gitlab-ce:12.5.5-ce.0
restart: always
hostname: 'gitlab.ovwane.com' # 项目内 git clone 的域名。
environment:
GITLAB_OMNIBUS_CONFIG: |
#external_url 'https://gitlab.ovwane.com'
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '80:80'
- '443:443'
- '22:22'
volumes:
- /data/gitlab/config:/etc/gitlab
- /data/gitlab/logs:/var/log/gitlab
- /data/gitlab/data:/var/opt/gitlab

# gitlab-runner:
# image: gitlab/gitlab-runner:alpine
#depends_on:
# - gitlab
#volumes:
# - ./config/gitlab-runner:/etc/gitlab-runner
# - /var/run/docker.sock:/var/run/docker.sock

console 操作

1
gitlab-rails console -e production

How to reset your root password | GitLab

配置邮件功能

/etc/gitlab/gitlab.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#配置下面,需要配置smtp_tls 
#注意gitlab_rails['smtp_tls'] 这个是设定为true
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "邮箱用户"
gitlab_rails['smtp_password'] = "密码"
gitlab_rails['smtp_domain'] = "smtp.163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
#配置邮箱来源, 与展示的名称
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '邮箱用户'
gitlab_rails['gitlab_email_display_name'] = 'Gitlab'

重新设置 gitlab-ctl reconfigure

测试发送邮件:gitlab-rails console,输入Notify.test_email('收件人@qq.com', '邮件标题', '邮件正文').deliver_now 测试。

关闭注册功能

Admin Area->Settings->Sign-up restrictions->Sign-up enabled 取消

添加用户

account_info.txt

1
2
12345678 test1@qq.com test1 测试账号1
12345678 test2@qq.com test2 测试账号2

root 用户生成 private_token

batch_add_account.sh

1
2
3
4
5
6
7
8
9
10
11
#!/bin/bash
#gitlab用户文本
accountinfo="account_info.txt"
while read line
do
password=`echo $line | awk '{print $1}'`
mail=`echo $line | awk '{print $2}'`
username=`echo $line | awk '{print $3}'`
name=`echo $line | awk '{print $4}'`
curl -d "password=$password&email=$mail&username=$username&name=$name&private_token=cwUxu3-2kiamVyKJQpW5" "http://192.168.0.115/api/v4/users"
done < $accountinfo

GitLab → 搭建中常遇的问题与日常维护 - 青石路 - 博客园

Gitlab 搜索关键字限制

https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/doc/user/search/index.md#searching-for-specific-terms

https://gitlab.com/xhang/gitlab/-/issues/86

1
2
3
4
/opt/gitlab/embedded/service/gitlab-rails/lib/gitlab/sql/pattern.rb

# 修改数量 1 个字符
MIN_CHARS_FOR_PARTIAL_MATCHING = 1

Gitlab 组件

  • gitlab (0.0.1)
  • package (0.1.0)
  • postgresql (0.1.0)
  • redis (0.1.0)
  • monitoring (0.1.0)
  • mattermost (0.1.0)
  • registry (0.1.0)
  • consul (0.1.0)
  • gitaly (0.1.0)
  • praefect (0.1.0)
  • nginx (0.1.0)
  • letsencrypt (0.1.0)
  • runit (4.3.0)
  • acme (4.0.0)
  • crond (0.1.0)

GitLab Architecture Overview | GitLab

Production Architecture | GitLab

参考

GitLab Installation

使用Docker来搭建gitlab

通过 docker 搭建自用的 gitlab 服务

GitLab Docker images

在 CentOS 7 上使用 Docker 部署安装 GitLab

Docker+Gitlab https

利用docker搭建gitlab及持续集成模块

Docker+Gitlab 配置

Docker部署GitLab

Gitlab CI 自动部署 asp.net core web api 到Docker容器

【GITLAB】 服务配置可持续集成部署的项目案例 - 安装篇

Registering Runners

使用 GitLab-CI 来自动创建 Docker 镜像

Gitlab CI 与 Docker 的配置与整合流程

GitLab安装部署

https://github.com/sameersbn/docker-gitlab

https://docs.gitlab.com/omnibus/docker/

Omnibus GitLab Docs | GitLab

从零开始搭建Gitlab服务器 - 知乎

×

纯属好玩

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
  1. 1. 简介
  2. 2. 环境
  3. 3. server端配置:
    1. 3.1. 安装前的准备工作
    2. 3.2. 安装GITLab shell
    3. 3.3. 安装GitLab
    4. 3.4. 安装Gems
    5. 3.5. Nginx配置
  4. 4. Client端配置:
    1. 4.1. 上传git仓库
  5. 5. 问题
  6. 6. Docker 部署 GitLab
    1. 6.1. 访问 GitLab
  7. 7. gitlab-runner
    1. 7.1. 安装gitlab-runner
    2. 7.2. 注册和初始化
    3. 7.3. 关闭注册功能
    4. 7.4. Gitlab 搜索关键字限制
  8. 8. Gitlab 组件
    1. 8.1. 参考
,