gitlab
目录
gitlab介绍
gitlab部署
- centos8
- 关闭防火墙、SElinux
- gitlab建议在纯净的服务器上部署(因为部署时会安装很多软件,可能影响原服务器上安装的软件)
安装yum源
[root@vm5 yum.repos.d]# yum -y install epel-release
.........................................
Installed:
epel-release-8-8.el8.noarch
Complete!
[root@vm5 yum.repos.d]# ls
CentOS-AppStream.repo CentOS-Extras.repo CentOS-Vault.repo
CentOS-Base.repo CentOS-fasttrack.repo epel-modular.repo
CentOS-centosplus.repo CentOS-HA.repo epel-playground.repo
CentOS-CR.repo CentOS-Media.repo epel.repo
CentOS-Debuginfo.repo CentOS-PowerTools.repo epel-testing-modular.repo
CentOS-Devel.repo CentOS-Sources.repo epel-testing.repo
安装git
Git是一个版本控制系统(version control system),是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.
[root@vm5 ~]# yum -y install git
Installed:
emacs-filesystem-1:26.1-5.el8.noarch
git-2.18.4-2.el8_2.x86_64
git-core-2.18.4-2.el8_2.x86_64
git-core-doc-2.18.4-2.el8_2.noarch
..........................................
安装依赖包
[root@vm5 ~]# yum -y install curl openssh-server openssh-clients postfix cronie
Running transaction
Preparing : 1/1
Installing : libicu-60.3-2.el8_1.x86_64 1/2
Running scriptlet: libicu-60.3-2.el8_1.x86_64 1/2
Running scriptlet: postfix-2:3.3.1-12.el8.x86_64 2/2
Installing : postfix-2:3.3.1-12.el8.x86_64 2/2
Running scriptlet: postfix-2:3.3.1-12.el8.x86_64 2/2
Verifying : libicu-60.3-2.el8_1.x86_64 1/2
Verifying : postfix-2:3.3.1-12.el8.x86_64 2/2
Installed:
libicu-60.3-2.el8_1.x86_64 postfix-2:3.3.1-12.el8.x86_64
[root@vm5 ~]# yum -y install python3-policycoreutils
.......................................
Installed:
checkpolicy-2.9-1.el8.x86_64
python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64
python3-libsemanage-2.9-2.el8.x86_64
python3-policycoreutils-2.9-9.el8.noarch
python3-setools-4.2.2-2.el8.x86_64
[root@vm5 ~]# yum -y install policycoreutils-python-utils
启动postfix服务
[root@vm5 ~]# systemctl enable --now postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@vm5 ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
安装gitlab RPM包
[root@vm5 opt]# pwd
/opt
[root@vm5 opt]# ls
gitlab-ce-13.6.1-ce.0.el8.x86_64.rpm
[root@vm5 opt]# rpm -ivh gitlab-ce-13.6.1-ce.0.el8.x86_64.rpm
warning: gitlab-ce-13.6.1-ce.0.el8.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f27eab47: NOKEY
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-13.6.1-ce.0.el8 ################################# [100%]
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
修改配置文件
- /etc/gitlab/gitlab.rb
[root@vm5 opt]# vim /etc/gitlab/gitlab.rb
...............................
external_url 'http://192.168.225.134' ##修改为gitlab服务器地址或域名
................................
重载配置文件并重启gitlab
[root@vm5 opt]# gitlab-ctl reconfigure
[root@vm5 opt]# gitlab-ctl restart
ok: run: alertmanager: (pid 16607) 0s
ok: run: gitaly: (pid 16621) 0s
ok: run: gitlab-exporter: (pid 16636) 1s
ok: run: gitlab-workhorse: (pid 16640) 0s
ok: run: grafana: (pid 16650) 1s
ok: run: logrotate: (pid 16662) 0s
ok: run: nginx: (pid 16668) 0s
ok: run: node-exporter: (pid 16676) 1s
ok: run: postgres-exporter: (pid 16687) 0s
ok: run: postgresql: (pid 16736) 0s
ok: run: prometheus: (pid 16745) 0s
ok: run: puma: (pid 16855) 1s
ok: run: redis: (pid 16860) 0s
ok: run: redis-exporter: (pid 16865) 1s
ok: run: sidekiq: (pid 16875) 0s
[root@vm5 opt]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 511 0.0.0.0:8060 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9121 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9090 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9187 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9093 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9100 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9229 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9168 0.0.0.0:*
LISTEN 0 511 0.0.0.0:80 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:9236 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 1024 127.0.0.1:3000 0.0.0.0:*
LISTEN 0 100 127.0.0.1:25 0.0.0.0:*
LISTEN 0 1024 *:9094 *:*
LISTEN 0 1024 [::1]:9168 [::]:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 100 [::1]:25 [::]:*
查看安装版本
[root@vm5 opt]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 13.6.1
gitlab管理
ip访问gitlab-web页面
- ip(gitlab服务器地址)
- 第一次登录需要设置gitlab的root账户密码
![]()

破解密码
[root@vm5 ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------
Ruby: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]
GitLab: 13.6.1 (1b6a590b197) FOSS
GitLab Shell: 13.13.0
PostgreSQL: 11.9
--------------------------------------------------------------------------------
Loading production environment (Rails 6.0.3.3)
irb(main):001:0>
irb(main):002:0> user = User.where(id:1).first //id=1表示root
=> #<User id:1 @root>
irb(main):003:0> user.password = '12345678!'
=> "12345678!"
irb(main):004:0> user.password_confirmation = '12345678!'
=> "12345678!"
irb(main):005:0> user.save!
Enqueued ActionMailer::MailDeliveryJob (Job ID: 616ad49a-74b0-4a65-a711-ecb501081022) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", {:args=>[#<GlobalID:0x00007fcce10224d8 @uri=#<URI::GID gid://gitlab/User/1>>]}
=> true //true表示设置成功
irb(main):007:0> exit
中文界面设置


用户管理
用户注册限制

添加用户




管理用户

创建成员组



项目管理

创建项目
- tom 账户登录






仓库克隆

- 克隆到终端
[root@vm5 opt]# git clone http://192.168.225.134/tom/test.git
Cloning into 'test'...
Username for 'http://192.168.225.134': tom
Password for 'http://tom@192.168.225.134':
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
[root@vm5 opt]# ls
gitlab gitlab-ce-13.6.1-ce.0.el8.x86_64.rpm test
[root@vm5 opt]# cd test
[root@vm5 test]# ls
README.md
[root@vm5 test]# vim
.git/ README.md
[root@vm5 test]# cat README.md
this is just a test !
上传文件
[root@vm5 test]# git config --global user.name "tom"
[root@vm5 test]# git config --global user.email "619585019@qq.com"
[root@vm5 test]# echo "123456" > 123.txt
[root@vm5 test]# ls
123.txt README.md
[root@vm5 test]# git remote add origin http://192.168.225.134/tom/test.git
fatal: remote origin already exists.
[root@vm5 test]# git add .
[root@vm5 test]# git commit -m "Initial commit"
[master 526cdd9] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 123.txt
[root@vm5 test]# git push -u origin master
Username for 'http://192.168.225.134': tom
Password for 'http://tom@192.168.225.134':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 271 bytes | 271.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.225.134/tom/test.git
6f72a97..526cdd9 master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

创建新仓库
[root@vm5 opt]# mkdir test2
[root@vm5 opt]# cd test2
[root@vm5 test2]# git init
Initialized empty Git repository in /opt/test2/.git/
[root@vm5 test2]# ls -a
. .. .git
[root@vm5 test2]# git remote add origin http://192.168.225.134/tom/test2.git
[root@vm5 test2]# git push -u origin --all
Username for 'http://192.168.225.134': tom
Password for 'http://tom@192.168.225.134':
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
Everything up-to-date
[root@vm5 test2]# git push -u origin --tags
Username for 'http://192.168.225.134': tom
Password for 'http://tom@192.168.225.134':
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
Everything up-to-date
- 推送新文件
[root@vm5 test2]# touch README.md
[root@vm5 test2]# echo "hello" >> README.md
[root@vm5 test2]# git add .
[root@vm5 test2]# git commit -m "Initial commit"
[master (root-commit) 506a97d] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
[root@vm5 test2]# git push -u origin master
Username for 'http://192.168.225.134': tom
Password for 'http://tom@192.168.225.134':
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 210 bytes | 210.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.225.134/tom/test2.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

免登录
- 创建密钥
[root@vm5 test2]# ssh-keygen -t rsa
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:Z2Mj7PQqAdv0yrSSOb505xKUihllAfmIpoW1Nzz1P8M root@vm5.localdomain
The key's randomart image is:
+---[RSA 3072]----+
| .o.. |
| o o . |
| + B . o |
|o.= B +.. |
|o. = X .So* |
|. o o =o.*Eo |
| .=.=o .o |
| .=.*o . |
| .o+ oo |
+----[SHA256]-----+
[root@vm5 test2]# cd
[root@vm5 ~]# ls
anaconda-ks.cfg
[root@vm5 ~]# cd .ssh/
[root@vm5 .ssh]# ls
id_rsa id_rsa.pub
[root@vm5 .ssh]# vim id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDhkqRAmX9Hr0GqGRiHWY+eb6mmi0OeAtNz3nJE7nTRVYKV1hZjYgGftcdc2jVs1ec3xhcK/E6wI2kjbAiUk39t5zsyrnqNjd1ZG6u9pOMvdS8blhg55HvmJbmR+S5MqJjkdtgIvQguTJjZ3YyNP76tNKoN+q765LvLyC/an5Ofgq857AKzGI2TMcjNVRHblGejQpyRaUy80LT7oaqP7npvFSnr8Tw5gp2y+88Abu1yf4cOFHqHlP5GpwJ4p/J17ab7e6cFdzes/HPxVU3HS0NQ+dMGBdZSR+DjHaaLCytigQzxq0SmGg3/ijfZK3rxyI27hiR+8KDvg4ti6si8wYdYTEE6BNaLAIR7Z4aoOASo3horGiFRD6xQVW1X+8+vdGb+AObC8M6Aw/FcTjVTxAsaCjWqir3LQ6dbq/aAacZmboMzqVSPmwt984eCbQ32Nfxu8SQnL4j4UXSlXruTJ60GzlqDsHqc0QzhJEbpaghvsaVRK+IKYuhVduLRph6LFJk= root@vm5.localdomain
- 添加密钥

##若使用了http协议克隆,则需要更改克隆协议为ssh
[root@vm5 test]# git remote set-url origin git@github.com:tom/test

- 验证
[root@vm5 ~]# git clone git@192.168.225.134:tom/test.git
Cloning into 'test'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 12 (delta 2), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (12/12), done.
Resolving deltas: 100% (2/2), done.
[root@vm5 ~]# cd test/
[root@vm5 test]# ls
123.txt hello.txt README.md
[root@vm5 test]#
[root@vm5 test]# echo "123546" >> 123.txt
[root@vm5 test]# git add 123.txt
[root@vm5 test]# git commit
Aborting commit due to empty commit message.
[root@vm5 test]# git commit -m "Initial commit"
[master 228ad8f] Initial commit
1 file changed, 1 insertion(+)
[root@vm5 test]# git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 309 bytes | 309.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To 192.168.225.134:tom/test.git
f36da63..228ad8f master -> master
[root@vm5 test]#


浙公网安备 33010602011771号