要想在 linux 系统中安装 gitlab 本身不是很复杂的过程。可以直接通过官方安装教程,就可以很顺序的进行安装运行。
比如希望在centos7上安装 gitlab 就可参考此处 https://about.gitlab.com/installation/#centos-7
寻找 docker 版的 gitlab 镜像
因为 gitlab 是提供的公司很多人使用,通过官方安装的只有英文版。而且 gitlab 还要依赖其它的软件,占用端口。
正好最近了解了 docker 的使用,于是就想不如直接安装 docker 版本的 gitlab 吧。
于是我使用了以下命令来搜索 docker 版的 gitlab。
[root@docker ~]# docker search gitlab INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED docker.io docker.io/gitlab/gitlab-ce GitLab Community Edition docker image base... 1352 [OK] docker.io docker.io/sameersbn/gitlab Dockerized gitlab web server 930 [OK] docker.io docker.io/gitlab/gitlab-runner GitLab CI Multi Runner used to fetch and r... 223 [OK] docker.io docker.io/gitlab/gitlab-ee GitLab Enterprise Edition docker image bas... 68 docker.io docker.io/twang2218/gitlab-ce-zh 汉化的 GitLab 社区版 Docker Image 53 [OK] docker.io docker.io/sameersbn/gitlab-ci 47 [OK] docker.io docker.io/anapsix/gitlab-ci GitLab-CI Continuous Integration in Docker... 28 [OK] docker.io docker.io/jangrewe/gitlab-ci-android GitLab CI image for building Android apps 25 [OK] docker.io docker.io/centurylink/gitlab This image uses the image from sameersbn /... 24 [OK] docker.io docker.io/gitlab/dind 20 [OK] docker.io docker.io/cdrx/rancher-gitlab-deploy Painless deployment of projects built with... 13 [OK] docker.io docker.io/karbon001/gitlab-ci-laravel-php GitLab CI runner for PHP including Git, Co... 4 [OK] docker.io docker.io/edbizarro/gitlab-ci-pipeline-php Build and test PHP applications with Gitla... 3 docker.io docker.io/gitlab/cog GitLab Bundle for Cog 3 docker.io docker.io/gitlab/gitlab-runner-helper 2 docker.io docker.io/benyoo/gitlab 基于sameersbn/gitlab:8.9.4和GitLab 中䬮. 1 [OK] docker.io docker.io/gotfix/gitlab Dockerized Gitlab with a lot of configurab... 1 docker.io docker.io/primetoninc/gitlab gitlab-ce 1 [OK] docker.io docker.io/sgillespie/gitlab-runner A Dockerized GitLab Runner that automatica... 1 [OK] docker.io docker.io/evili/gitlabci Basic gitlabci runner image with basic dev... 0 [OK] docker.io docker.io/gitlab/gitlab-qa GitLab QA has a test suite that allows end... 0 docker.io docker.io/instrumentisto/gitlab-builder Docker image with minimal toolchain requir... 0 [OK] docker.io docker.io/mastertinner/gitlab-merge-request-resource A concourse resource to check for new merg... 0 [OK] docker.io docker.io/recteurlp/gitlab-ci-multi-runner-fedora GitLab CI Multi Runner on Fedora 26 0 [OK] docker.io docker.io/stanfordlegion/gitlab-ci An image for Gitlab CI. 0 [OK]
这下搜寻出了很多 gitlab 相关的镜像,现在就找一个中意的镜像来下载运行。
其中第1行点赞的人最多,它应该是下载人最多的原版吧。
下载 gitlab 镜像
还发行其中有一行备注为:汉化的 GitLab 社区版 Docker Image,没想到这里还提供已经汉化好的镜像,非常赞。记录这个镜像名称:twang2218/gitlab-ce-zh
使用命令下载镜像:docker pull twang2218/gitlab-ce-zh
[root@docker ~]# docker pull twang2218/gitlab-ce-zh Using default tag: latest Trying to pull repository docker.io/twang2218/gitlab-ce-zh ... latest: Pulling from docker.io/twang2218/gitlab-ce-zh 60730f960363: Pull complete f7d512d82502: Pull complete a7cad26d0357: Pull complete 25bb6f291ceb: Pull complete 630ceed02486: Pull complete 37a4aa3e8681: Pull complete a23921b13f83: Pull complete 2fd688092d72: Pull complete 8615aa8dd726: Pull complete 3c5c33a64e41: Pull complete 4e45a593a587: Pull complete 3abf31d2ceec: Pull complete 3785b8335f9e: Pull complete Digest: sha256:30e298916584c3a3a71b377044d2e8ecd6e502fd2a082e0126aee5e0701752a0
经过一段时间的下载,就会将此镜像添加到你的 docker 镜像库中。
现在通过命令查看镜像库中是否存在:docker images
[root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/twang2218/gitlab-ce-zh latest 39be86bde8c0 2 days ago 1.525 GB docker.io/wordpress latest dccaeccfba36 2 weeks ago 405.8 MB docker.io/centos latest 328edcd84f1b 4 weeks ago 192.5 MB docker.io/nginx latest b8efb18f159b 5 weeks ago 107.5 MB docker.io/httpd latest e74fcb59d25b 5 weeks ago 177.3 MB docker.io/ubuntu 15.10 9b9cb95443b5 13 months ago 137.2 MB docker.io/training/webapp latest 6fae60ef3446 2 years ago 348.7 MB
其中第一条就是刚下载的 gitlab 镜像
运行 gitlab 镜像
要使得 gitlab-ce-zh镜像能正确的运行,还是需要参考一下官方的资料。地址:https://github.com/twang2218/gitlab-ce-zh
一、先在本地创建三个gitlab运行目录:etc、log、data,分别是配置、日志、数据。
于是我在 /home/gitlab/ 目录下,分别创建了这三个目录。
二、通过命令运行 gitlab 镜像。
docker run -d \ --hostname git.kayura.org \ -p 5080:80 \ -p 5443:443 \ -p 5022:22 \ --name gitlab \ --restart unless-stopped \ -v /home/gitlab/etc:/etc/gitlab \ -v /home/gitlab/log:/var/log/gitlab \ -v /home/gitlab/data:/var/opt/gitlab \ twang2218/gitlab-ce-zh
注意这里,如果你的Linux使用了 SELinux,那么使用以下命令来替代上面的命令。
docker run -d \ --hostname git.kayura.org \ -p 5080:80 \ -p 5443:443 \ -p 5022:22 \ --name gitlab \ --restart unless-stopped \ -v /home/gitlab/etc:/etc/gitlab:Z \ -v /home/gitlab/log:/var/log/gitlab:Z \ -v /home/gitlab/data:/var/opt/gitlab:Z \ twang2218/gitlab-ce-zh
这样就不会因为权限的问题,而无法启动 gitlab 了。
三、查看刚运行的 gitlab 容器。
[root@docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 958056de33cc twang2218/gitlab-ce-zh "/assets/wrapper" About a minute ago Up 2 seconds (health: starting) 22/tcp, 443/tcp, 0.0.0.0:5080->80/tcp gitlab
四、查看 gitlab 的启动日志。
[root@docker gitlab]# docker logs --tail 5000 --follow --timestamps gitlab 2017-09-11T12:01:35.453770000Z Thank you for using GitLab Docker Image! 2017-09-11T12:01:35.453989000Z Current version: gitlab-ce=9.5.2-ce.0 2017-09-11T12:01:35.454250000Z Configure GitLab for your system by editing /etc/gitlab/gitlab.rb file 2017-09-11T12:01:35.454373000Z And restart this container to reload settings. 2017-09-11T12:01:35.454540000Z To do it use docker exec: 2017-09-11T12:01:35.454845000Z docker exec -it gitlab vim /etc/gitlab/gitlab.rb 2017-09-11T12:01:35.454982000Z docker restart gitlab 2017-09-11T12:01:35.455258000Z For a comprehensive list of configuration options please see the Omnibus GitLab readme 2017-09-11T12:01:35.455392000Z https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md 2017-09-11T12:01:35.455662000Z If this container fails to start due to permission problems try to fix it by executing: 2017-09-11T12:01:35.455931000Z docker exec -it gitlab update-permissions 2017-09-11T12:01:35.456071000Z docker restart gitlab 2017-09-11T12:01:38.468893000Z Installing gitlab.rb config... 2017-09-11T12:01:38.486318000Z Generating ssh_host_rsa_key... 2017-09-11T12:01:38.580706000Z Generating public/private rsa key pair. 2017-09-11T12:01:38.580911000Z Your identification has been saved in /etc/gitlab/ssh_host_rsa_key. 2017-09-11T12:01:38.581036000Z Your public key has been saved in /etc/gitlab/ssh_host_rsa_key.pub. 2017-09-11T12:01:38.581158000Z The key fingerprint is: 2017-09-11T12:01:38.581284000Z SHA256:jxzfel0GHwGVscQ5UU3Adkg0m/5wJXmCUATiO8s3g24 [email protected] 2017-09-11T12:01:38.581472000Z The key's randomart image is: 2017-09-11T12:01:38.581593000Z +---[RSA 2048]----+ 2017-09-11T12:01:38.581760000Z | . o+o=OOX| 2017-09-11T12:01:38.581932000Z | . . . .=@+| 2017-09-11T12:01:38.582143000Z | . ..*o=| 2017-09-11T12:01:38.582326000Z | . ..=.| 2017-09-11T12:01:38.582476000Z | S ooo| 2017-09-11T12:01:38.582588000Z | o O . ++| 2017-09-11T12:01:38.582701000Z | * * .. o.| 2017-09-11T12:01:38.582915000Z | .E. +. . | 2017-09-11T12:01:38.583093000Z | .. .. | 2017-09-11T12:01:38.583213000Z +----[SHA256]-----+ 2017-09-11T12:01:38.584359000Z Generating ssh_host_ecdsa_key... 2017-09-11T12:01:38.584568000Z Generating public/private ecdsa key pair. 2017-09-11T12:01:38.584867000Z Your identification has been saved in /etc/gitlab/ssh_host_ecdsa_key. 2017-09-11T12:01:38.585074000Z Your public key has been saved in /etc/gitlab/ssh_host_ecdsa_key.pub. 2017-09-11T12:01:38.585208000Z The key fingerprint is: 2017-09-11T12:01:38.585422000Z SHA256:RtTti3LwgnQn2/mSUA0BnvAqXHpYvQQQclKR4j9gwxE [email protected] 2017-09-11T12:01:38.585555000Z The key's randomart image is: 2017-09-11T12:01:38.585668000Z +---[ECDSA 256]---+ 2017-09-11T12:01:38.585787000Z | Eo*=o oo.o | 2017-09-11T12:01:38.585993000Z | o+. B .o . | 2017-09-11T12:01:38.586122000Z | o o o B + | 2017-09-11T12:01:38.586234000Z | *. =.++.o o | 2017-09-11T12:01:38.586444000Z | . +=.ooSO o . | 2017-09-11T12:01:38.586560000Z | oo..= * . | 2017-09-11T12:01:38.586677000Z | . = o | 2017-09-11T12:01:38.586788000Z | o . | 2017-09-11T12:01:38.587061000Z | . | 2017-09-11T12:01:38.587238000Z +----[SHA256]-----+ 2017-09-11T12:01:38.588215000Z Generating ssh_host_ed25519_key... 2017-09-11T12:01:38.588573000Z Generating public/private ed25519 key pair. 2017-09-11T12:01:38.588698000Z Your identification has been saved in /etc/gitlab/ssh_host_ed25519_key. 2017-09-11T12:01:38.588893000Z Your public key has been saved in /etc/gitlab/ssh_host_ed25519_key.pub. 2017-09-11T12:01:38.589029000Z The key fingerprint is: 2017-09-11T12:01:38.589146000Z SHA256:686UxYzNvYLhv8O7N5wm3VurrAH+BpniDFQfuKG48Y8 [email protected] 2017-09-11T12:01:38.589263000Z The key's randomart image is: 2017-09-11T12:01:38.589438000Z +--[ED25519 256]--+ 2017-09-11T12:01:38.589554000Z | . | 2017-09-11T12:01:38.589671000Z | + . | 2017-09-11T12:01:38.589813000Z | . o + . | 2017-09-11T12:01:38.590012000Z | o o . B . | 2017-09-11T12:01:38.590124000Z | = S.O . | 2017-09-11T12:01:38.590391000Z | . o o.X. . | 2017-09-11T12:01:38.590569000Z | * Boo+.o .| 2017-09-11T12:01:38.590701000Z | E B .=oX ...| 2017-09-11T12:01:38.590948000Z | .+ *@.+oo | 2017-09-11T12:01:38.591123000Z +----[SHA256]-----+ 2017-09-11T12:01:38.591374000Z Preparing services... 2017-09-11T12:01:38.598479000Z Starting services... 2017-09-11T12:01:38.598794000Z Configuring GitLab package... 2017-09-11T12:01:38.615758000Z Configuring GitLab... 2017-09-11T12:01:38.615917000Z /opt/gitlab/embedded/bin/runsvdir-start: line 24: ulimit: pending signals: cannot modify limit: Operation not permitted 2017-09-11T12:01:38.616083000Z /opt/gitlab/embedded/bin/runsvdir-start: line 34: ulimit: max user processes: cannot modify limit: Operation not permitted 2017-09-11T12:01:38.616230000Z /opt/gitlab/embedded/bin/runsvdir-start: line 37: /proc/sys/fs/file-max: Read-only file system 2017-09-11T12:01:45.986869000Z * Moving existing certificates found in /opt/gitlab/embedded/ssl/certs 2017-09-11T12:01:45.987171000Z * Symlinking existing certificates found in /etc/gitlab/trusted-certs 2017-09-11T12:03:13.513565000Z gitlab Reconfigured! Checking for an omnibus managed postgresql: OK Checking if we already upgraded: OK 2017-09-11T12:03:13.836318000Z The latest version 9.6.3 is already running, nothing to do
如果你看到了这样的日志信息,那表示已经正常运行了。
五、运行 gitlab 网站。
访问 http://127.0.0.1:8580,如果顺序的话应该可以看到首页了。
等等,还没有结束
虽然很开心 gitlab 已经可以运行了,但是 gitlab 是通过邮件来激活、修改密码的。这部分配置工作尚未完成。
一、修改配置
需要配置 /home/gitlab/etc 目录下的 gitlab.rb 文件,需要配置的内容如下:
gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.qq.com" gitlab_rails['smtp_port'] = 465 gitlab_rails['smtp_user_name'] = "[email protected]" gitlab_rails['smtp_password'] = "xxxxxxxxxxxx" gitlab_rails['smtp_domain'] = "smtp.qq.com" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true gitlab_rails['smtp_tls'] = true gitlab_rails['gitlab_email_from'] = "[email protected]" user['git_user_email'] = "[email protected]"
这里的示例是配置QQ邮箱的,需要注意的是 smtp_password 并不是指你的QQ邮箱密码。
而是,在QQ邮箱 => 设置 => 账户 中获取。
其中“POP3/SMTP服务”,默认是“已关闭”状态。点击开启,再通过验证,就会提供给你密码。
二、重新配置并启动 gitlab
使用命令:docker exec -it gitlab bash 进行 docker 容器的交互命令行,
再使用 gitlab-ctl reconfigure 来重新配置。
[root@docker etc]# docker exec -it gitlab bash
root@git:/# gitlab-ctl reconfigure
Starting Chef Client, version 12.12.15
resolving cookbooks for run list: ["gitlab"]
Synchronizing Cookbooks:
- gitlab (0.0.1)
- runit (0.14.2)
- package (0.1.0)
- consul (0.0.0)
- registry (0.1.0)
Installing Cookbook Gems:
Compiling Cookbooks...
......
Running handlers:
Running handlers complete
Chef Client finished, 11/462 resources updated in 19 seconds
gitlab Reconfigured!
三、测试邮箱配置是否成功
执行 gitlab-rails console进入控制台。
然后在控制台提示符后输入下面的命令 发送一封测试邮件:Notify.test_email(‘收件人邮箱’, ‘邮件标题’, ‘邮件正文’).deliver_now
root@git:~# gitlab-rails console Loading production environment (Rails 4.2.8) irb(main):001:0> Notify.test_email('[email protected]', 'gitlab测试邮件', 'gitlab测试邮件').deliver_now Notify#test_email: processed outbound mail in 123.7ms Sent mail to [email protected] (864.3ms) Date: Mon, 11 Sep 2017 20:29:38 +0800 From: GitLab <[email protected]> Reply-To: GitLab <[email protected]> To: [email protected] Message-ID: <[email protected]> Subject: =?UTF-8?Q?gitlab=E6=B5=8B=E8=AF=95=E9=82=AE=E4=BB=B6?= Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Auto-Submitted: auto-generated X-Auto-Response-Suppress: All <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www= .w3.org/TR/REC-html40/loose.dtd"> <html><body><p>gitlab=E6=B5=8B=E8=AF=95=E9=82=AE=E4=BB=B6</p></body></htm= l> => #<Mail::Message:70098091070800, Multipart: false, Headers: <Date: Mon, 11 Sep 2017 20:29:38 +0800>, <From: GitLab <[email protected]>>, <Reply-To: GitLab <[email protected]>>, <To: [email protected]>, <Message-ID: <[email protected]>>, <Subject: gitlab测试邮件>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: quoted-printable>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
这样就表示邮件已经发送成功了。打开我的QQ邮件,看一下是否收到邮件。
到这里,就完成了全部的配置工作。接下来就可以享用 gitlab 带来的工作便利……