centos7搭建gitlab服务器

安装并配置必要的依赖关系

1.安装ssh

1
2
3
4
5
6
7
8
9
10
11
12
[root@szl ~]# sudo yum install -y curl policycoreutils-python openssh-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
软件包 curl-7.29.0-59.el7_9.1.x86_64 已安装并且是最新版本
软件包 policycoreutils-python-2.5-34.el7.x86_64 已安装并且是最新版本
软件包 openssh-server-7.4p1-21.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@szl ~]# systemctl enable sshd
[root@szl ~]# systemctl start sshd

2.安装Postfix以发送通知邮件

1
2
3
4
5
6
7
8
9
10
[root@szl ~]# yum install postfix
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
软件包 2:postfix-2.10.1-9.el7.x86_64 已安装并且是最新版本
无须任何处理
[root@szl ~]# systemctl enable postfix
[root@szl ~]# systemctl start postfix

3.安装wget

1
2
3
4
[root@szl ~]# yum -y install wget

[root@szl ~]# wget -V
GNU Wget 1.14 在 linux-gnu 上编译。

添加GitLab镜像源并安装gitlab服务器

1.添加gitlab镜像

1
2
3
4
5
6
7
8
9
10
11
[root@szl ~]# wget https://mirrors.cloud.tencent.com/gitlab-ce/yum/el7/gitlab-ce-13.8.0-ce.0.el7.x86_64.rpm
--2021-04-16 21:19:10-- https://mirrors.cloud.tencent.com/gitlab-ce/yum/el7/gitlab-ce-13.8.0-ce.0.el7.x86_64.rpm
正在解析主机 mirrors.cloud.tencent.com (mirrors.cloud.tencent.com)... 125.74.5.205, 118.180.31.97, 118.180.60.84, ...
正在连接 mirrors.cloud.tencent.com (mirrors.cloud.tencent.com)|125.74.5.205|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:863899009 (824M) [application/x-redhat-package-manager]
正在保存至: “gitlab-ce-13.8.0-ce.0.el7.x86_64.rpm”

100%[=========================================================================================================>] 863,899,009 1.31MB/s 用时 11m 38s

2021-04-16 21:30:49 (1.18 MB/s) - 已保存 “gitlab-ce-13.8.0-ce.0.el7.x86_64.rpm” [863899009/863899009])

2.2.安装gitlab

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
[root@szl ~]# rpm -i gitlab-ce-13.8.0-ce.0.el7.x86_64.rpm
警告:gitlab-ce-13.8.0-ce.0.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID f27eab47: NOKEY
It looks like GitLab has not been configured yet; skipping the upgrade script.

*. *.
*** ***
***** *****
.****** *******
******** ********
,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
,,,,,,,,,*****,,,,,,,,,.
,,,,,,,****,,,,,,
.,,,***,,,,
,*,.



_______ __ __ __
/ ____(_) /_/ / ____ _/ /_
/ / __/ / __/ / / __ `/ __ \
/ /_/ / / /_/ /___/ /_/ / /_/ /
\____/_/\__/_____/\__,_/_.___/


Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=13-8

3.修改gitlab配置文件指定服务器ip和自定义端口

1
2
[root@szl ~]# vim  /etc/gitlab/gitlab.rb
external_url 'http://192.168.80.3:8099' //修改访问地址和端口

4.重置并启动GitLab

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@szl ~]# gitlab-ctl reconfigure
[root@szl ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 14913) 0s
ok: run: gitaly: (pid 14927) 0s
ok: run: gitlab-exporter: (pid 14946) 0s
ok: run: gitlab-workhorse: (pid 14948) 1s
ok: run: grafana: (pid 14966) 0s
ok: run: logrotate: (pid 14979) 0s
ok: run: nginx: (pid 14986) 1s
ok: run: node-exporter: (pid 14994) 0s
ok: run: postgres-exporter: (pid 15081) 1s
ok: run: postgresql: (pid 15091) 0s
ok: run: prometheus: (pid 15100) 1s
ok: run: puma: (pid 15112) 0s
ok: run: redis: (pid 15117) 0s
ok: run: redis-exporter: (pid 15122) 1s
ok: run: sidekiq: (pid 15131) 0s

5.访问 GitLab页面
如果没有域名,直接输入服务器ip和指定端口进行访问
第一次登录修改密码

6.gitlab重置密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sudo gitlab-rails console production    //或sudo gitlab-rails console
-------------------------------------------------------------------------------------
GitLab: 11.1.4 (63daf37)
GitLab Shell: 7.1.4
postgresql: 9.6.8
-------------------------------------------------------------------------------------
Loading production environment (Rails 4.2.10)
irb(main):001:0> u=User.where(id:1).first
=> #<User id:1 @root>
irb(main):002:0> u.password='123456'
=> "123456"
irb(main):003:0> u.password_confirmation='123456'
=> "123456"
irb(main):004:0> u.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 7bffac81-aab5-4d3a-b771-bdffb4145020) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1
=> true
irb(main):005:0> exit
You have new mail in /var/spool/mail/root

(1)sudo gitlab-rails console production
(2)u=User.where(id:1).first
(3)u.password=’123456’
(4)u.password_confirmation=’123456’
(5)u.save!
(6)exit

7.创建public key

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@szl ~]# ssh-keygen        //一路回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:bgX3EgqCCRfGZp8JwovkrLTXVP5blGF0Lzli/5s9BQk root@szl
The key's randomart image is:
+---[RSA 2048]----+
|o.+. .. . |
|.*=o . oE o |
|=++o.o+ . +oo= o |
|.= +o o +.=o = |
|o . o S + .. . |
|.. . . . o o . .|
| . o o ..|
| . . .+|
| oo|
+----[SHA256]-----+
[root@szl ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7J+INTf+hmoS/rHPrSvNLH+cyJsPykN/NNMmTg0jLlUQjZjwUSLO6APcUyGJDv0GaasKowfwhSfmH31fo4y0gEToOBV/ZzbgLETjya0744smMQK9nRZvNZ8YQML76ifBMrK5T5N2tTwnCbEiu2M2UlYEmsDJUtsqePd0Ice2OZ4KiEd620S++5NV8lp3QJ6qobP3wkhzlbtBhfLk8X2ZWvoNqvJPNxGFJKetIGyDVpKip2+ziUM9U/LHudiRJuOJxIMLnBXCn4fzEPlHMWPnrvSrz1Mk8pDZS/stdwRkMBCxUo1oPWLzxbb9c7Pv9nQruCJa+Ilezr/iC/4xv50eX root@szl

8.复制id_rsa.pub公钥添加到gitlab