Ubuntu Server 22.04 安装 Gitlab-ce

This is an article that was created 574 days ago, and the information may have evolved or changed.

本文记录VMware Workstation 环境下Ubuntu server 22.04系统安装gitlab-ce_15.8.3的过程。

准备环境

  • 一台安装好 ubuntu server的虚拟机
  • ubuntu可联网
  • SecureCRT软件(或其它带SSH登陆功能的工具)

更新软件包信息和安装软件

首先设置好国内更新源,在安装Ubuntu的时候我已经填写了阿里云的站点(mirrors.aliyun.com/ubuntu),如果你没有修改这一项,登陆服务器后修改 /etc/apt/sources.list即可

1
sudo apt-get update

安装或更新以下软件(虽然安装Ubuntu的时候勾选了Openssh但是不是最新版本,提示升级)

1
sudo apt-get install curl openssh-server ca-certificates postfix 

命令回显

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
kir@gitlabserver:/etc/apt$  sudo apt-get install curl openssh-server ca-certificates postfix 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libcurl4 openssh-client openssh-sftp-server ssl-cert
Suggested packages:
keychain libpam-ssh monkeysphere ssh-askpass molly-guard procmail postfix-mysql postfix-pgsql postfix-ldap
postfix-pcre postfix-lmdb postfix-sqlite sasl2-bin | dovecot-common resolvconf postfix-cdb mail-reader
postfix-mta-sts-resolver postfix-doc
The following NEW packages will be installed:
postfix ssl-cert
The following packages will be upgraded:
ca-certificates curl libcurl4 openssh-client openssh-server openssh-sftp-server
6 upgraded, 2 newly installed, 0 to remove and 181 not upgraded.
Need to get 3,271 kB of archives.
After this operation, 4,243 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 openssh-sftp-server amd64 1:8.9p1-3ubuntu0.1 [38.7 kB]
Get:2 http://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 openssh-server amd64 1:8.9p1-3ubuntu0.1 [434 kB]
Get:3 http://mirrors.aliyun.com/ubuntu jammy-updates/main amd64 openssh-client amd64 1:8.9p1-3ubuntu0.1 [908 kB]
……
……
……

postfix 软件安装后会弹出一个”Postfix Configuration”向导,直接选No configuration不进行配置(本地环境不实用)

下载和安装gitlab-ce_15.8.3

这个看各自网络的网速,官网下载(ubuntu/jammy/gitlab-ce_15.8.3-ce.0_amd64.deb - gitlab/gitlab-ce · packages.gitlab.com

ScreenCaputure230223130323

清华镜像站下载(Index of /gitlab-ce/ubuntu/pool/jammy/main/g/gitlab-ce/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

ScreenCaputure230223130553

下载完成后,校验一下MD5值,对比官网提供的校验信息

1
2
kir@gitlabserver:~$ sudo md5sum gitlab-ce_15.8.3-ce.0_amd64.deb 
feaecd81f1b2a39600114c873b1b9085 gitlab-ce_15.8.3-ce.0_amd64.deb

命令回显

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
kir@gitlabserver:~$ sudo dpkg -i gitlab-ce_15.8.3-ce.0_amd64.deb 
Selecting previously unselected package gitlab-ce.
(Reading database ... 73398 files and directories currently installed.)
Preparing to unpack gitlab-ce_15.8.3-ce.0_amd64.deb ...
Unpacking gitlab-ce (15.8.3-ce.0) ...
Setting up gitlab-ce (15.8.3-ce.0) ...
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=15-8

修改外部url和reconfigure

  1. 修改/etc/gitlab/下的gitlab.rb文件,external_url直接修改为ubuntu系统的的IP地址,如果 80 端口有冲突可在后边加上端口号
1
external_url 'http://192.168.x.x'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
kir@gitlabserver:~$ cd /etc/gitlab
kir@gitlabserver:/etc/gitlab$ ll
total 148
drwxr-xr-x 2 root root 4096 Feb 23 03:49 ./
drwxr-xr-x 102 root root 4096 Feb 23 03:49 ../
-rw------- 1 root root 140235 Feb 23 03:49 gitlab.rb
kir@gitlabserver:/etc/gitlab$ sudo cp gitlab.rb gitlab.rb_bak
kir@gitlabserver:/etc/gitlab$ ll
total 288
drwxr-xr-x 2 root root 4096 Feb 23 03:50 ./
drwxr-xr-x 102 root root 4096 Feb 23 03:49 ../
-rw------- 1 root root 140235 Feb 23 03:49 gitlab.rb
-rw------- 1 root root 140235 Feb 23 03:50 gitlab.rb_bak
kir@gitlabserver:/etc/gitlab$ sudo nano gitlab.rb
  1. 重配置(这一步骤耗时较长)
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
kir@gitlabserver:/opt/gitlab/bin$   sudo gitlab-ctl reconfigure
[2023-02-23T03:52:56+00:00] INFO: Started Cinc Zero at chefzero://localhost:1 with repository at /opt/gitlab/embedded (One version per cookbook)
Cinc Client, version 17.10.0
Patents: https://www.chef.io/patents
Infra Phase starting
[2023-02-23T03:52:57+00:00] INFO: *** Cinc Client 17.10.0 ***
[2023-02-23T03:52:57+00:00] INFO: Platform: x86_64-linux
[2023-02-23T03:52:57+00:00] INFO: Cinc-client pid: 18551
[2023-02-23T03:52:58+00:00] INFO: Setting the run_list to ["recipe[gitlab]"] from CLI options
[2023-02-23T03:52:58+00:00] INFO: Run List is [recipe[gitlab]]
[2023-02-23T03:52:58+00:00] INFO: Run List expands to [gitlab]
[2023-02-23T03:52:58+00:00] INFO: Starting Cinc Client Run for gitlabserver
[2023-02-23T03:52:58+00:00] INFO: Running start handlers
[2023-02-23T03:52:58+00:00] INFO: Start handlers complete.
Resolving cookbooks for run list: ["gitlab"]
……
……
……

Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.

NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

gitlab Reconfigured!
  1. 重启gitlab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
kir@gitlabserver:/opt/gitlab/bin$ sudo gitlab-ctl restart
ok: run: alertmanager: (pid 21046) 0s
ok: run: gitaly: (pid 21058) 0s
ok: run: gitlab-exporter: (pid 21077) 0s
ok: run: gitlab-kas: (pid 21085) 0s
ok: run: gitlab-workhorse: (pid 21095) 1s
ok: run: logrotate: (pid 21107) 0s
ok: run: nginx: (pid 21115) 0s
ok: run: node-exporter: (pid 21123) 1s
ok: run: postgres-exporter: (pid 21129) 0s
ok: run: postgresql: (pid 21144) 1s
ok: run: prometheus: (pid 21153) 0s
ok: run: puma: (pid 21166) 0s
ok: run: redis: (pid 21171) 0s
ok: run: redis-exporter: (pid 21177) 1s
ok: run: sidekiq: (pid 21260) 1s

修改 root 密码

根据重配置步骤后的提示Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.,root的初始密码储存在initial_root_password,文件在第一次reconfigure 24小时后清除。

  1. 使用initial_root_password文件里的密码 web登陆,”Edit profile”–”Panssword”修改

ScreenCaputure230223133138

  1. 使用命令修改
1
2
3
4
5
kir@gitlabserver:/etc/gitlab$ sudo gitlab-rake "gitlab:password:reset[root]"
Enter password:
Confirm password:
Password successfully updated for user with username root.
kir@gitlabserver:/etc/gitlab$
  1. 控制台修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
切换路径
cd /opt/gitlab/bin/

kir@gitlabserver:/opt/gitlab/bin$ sudo gitlab-rails console -e production
--------------------------------------------------------------------------------
Ruby: ruby 2.7.7p221 (2022-11-24 revision 168ec2b1e5) [x86_64-linux]
GitLab: 15.8.3 (22f43167474) FOSS
GitLab Shell: 14.15.0
PostgreSQL: 13.8
------------------------------------------------------------[ booted in 90.93s ]
Loading production environment (Rails 6.1.6.1)
irb(main):001:0> u=User.where(id:1).first
irb(main):001:0> u=User.where(id:1).first
=> #<User id:1 @root>
irb(main):002:0> u.password=12345678
=> 12345678
irb(main):003:0> u.password_confirmation=12345678
=> 12345678
irb(main):004:0> u.save!
=> true
irb(main):005:0> quit

注册和登陆Gitlab

在启动gitlab后,直接用浏览器登陆可能出现下图所示502错误,等一会儿再打开就ok了,猜测是服务没有完全运行起来,也有可能是我物理机配置差劲。

ScreenCaputure230223121024

  1. 注册,由于是本地使用,之前也没配置邮件Postfix,填上舒服的信息即可

ScreenCaputure230223121304

  1. 注册完后登陆出错,看提示是账号被挂起,使用root管理员账户登陆进行审批通过即可

ScreenCaputure230223122038

  1. 登陆管理员账户进行审批通过

ScreenCaputure230223123908

ScreenCaputure230223123923

ScreenCaputure230223123957

ScreenCaputure230223124009

ScreenCaputure230223124018

  1. 退出管理员登陆,使用刚才注册的账号登陆,确认后,选择一个角色

ScreenCaputure230223124141

ScreenCaputure230223124150

最后

  • 为什么写这篇文,因为我的一块硬盘报废了,整块硬盘直接奔溃,各种尝试后放弃了,因为这块500G的硬盘是大学时候台式电脑的,间接原因是使用时间和寿命,直接原因是电脑死机强制关机。
  • 然后京东购了一块固态盘,一看价格现在同容量的固态硬盘比机械硬盘还便宜了。都说固态硬盘一坏文件全扑街,机械硬盘还有抢救的机会,这个只能靠自己掌控了,临近使用寿命或电脑出现异常就要考虑换硬盘了,最好的方法是做备份。
  • 虽然这块盘报废了,也丢失了一些文件,但是由于我把重要的文件都做有备份,但是像这种虚拟机的环境一般都不留备份(文件太大太多)。
  • 得益于硬盘报废,实操了一把前面文章写的自动备份Hexo源文件到私有仓库Hexo环境新电脑环境重构,博客源文件回来了。
  • 备份很重要-备份很重要-备份很重要
配置跨域的Option C MPLS VPN(Cisco) Hexo环境新电脑环境重构
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×