跳转至

3. 使用

9. 浏览器访问gitlab,直接输入192.168.178.181

10. 首次运行gitlab需要修改密码

输入2次密码chupeng666

然后输入账号密码:root:chupeng666

11. gitlab汉化配置

1.获取汉化包(注意:必须与gitlab版本一致!!!)

浏览器输入地址:https://gitlab.com/xhang/gitlab/-/tree/v10.2.2-zh,下载相应版本

[root@gitlab opt]# ls
gitlab  gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm  gitlab-v10.2.2-zh.tar.gz

2.解压缩汉化包

[root@gitlab opt]# tar -zxvf gitlab-v10.2.2-zh.tar.gz ^C
[root@gitlab opt]# ls
gitlab  gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm  gitlab-v10.2.2-zh  gitlab-v10.2.2-zh.tar.gz

3.拷贝汉化包到gitlab

[root@gitlab opt]# \cp -rf /opt/gitlab-v10.2.2-zh/* /opt/gitlab/embedded/service/gitlab-rails/
cp: cannot overwrite non-directory ‘/opt/gitlab/embedded/service/gitlab-rails/log’ with directory ‘/opt/gitlab-v10.2.2-zh/log’
cp: cannot overwrite non-directory ‘/opt/gitlab/embedded/service/gitlab-rails/tmp’ with directory ‘/opt/gitlab-v10.2.2-zh/tmp’

4.重启gitlab

[root@gitlab opt]# gitlab-ctl restart
ok: run: gitaly: (pid 34480) 0s
ok: run: gitlab-monitor: (pid 34491) 1s
ok: run: gitlab-workhorse: (pid 34500) 0s
ok: run: logrotate: (pid 34508) 1s
ok: run: nginx: (pid 34515) 0s
ok: run: node-exporter: (pid 34521) 0s
ok: run: postgres-exporter: (pid 34527) 1s
ok: run: postgresql: (pid 34570) 0s
ok: run: prometheus: (pid 34578) 1s
ok: run: redis: (pid 34588) 0s
ok: run: redis-exporter: (pid 34592) 1s
ok: run: sidekiq: (pid 34599) 0s
ok: run: unicorn: (pid 34608) 1s

5.浏览器再次访问gitlab 登录后查看是否汉化成功!!!

12. gitlab新建群组

填入群组路径和描述,然后点击创建

13. gitlab创建项目

点击项目,新建项目 选择群组,填入项目名和描述,点击创建 查看新建的项目

14. gitlab创建用户

填入姓名和邮箱,点击创建 登录邮箱,点击修改密码 弹出界面,填入新密码chupeng888 使用chupeng用户登录

15. 用户与工程绑定

在群组中,添加用户 添加成功后, 此时,再次查看chupeng用户登录的gitlab,点击刷新,即可看到工程 修改完密码和添加到工程,chupeng用户的邮箱都会收到邮件通知!

16. 配置ssh免密登录gitlab

1.生成密钥对

[root@gitlab opt]# 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:kFOL0NfxOfI8bieD2w4/Zn7127BvnLv+ozgUyqkJ/wo root@gitlab
The key's randomart image is:
+---[RSA 2048]----+
|    ..  ....     |
|     ..+.... .   |
|      =.. . +    |
|       o   = .   |
|        S o =    |
|     .   + + .  .|
|     Eo o + = ooo|
|      .+   B=+.==|
|       .o..**++BX|
+----[SHA256]-----+

2.查看公私钥

[root@gitlab opt]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCU7/pB7mxd+D5ln+dB59EUYovAth235rkXe5TNbwwMWtnflBASsgISHLIR2pbKbAoLVp1Uqz7iFSGbmMv3/oZ1orT0vstw9HrJBZ49vJvZ0mzOeo7/GnjaG35hqXue1EtEP7Lx6oQShzM+iDftILXsrHbAcUZJ0HscqjLy/ClSleRxHbeRrEjAg6OU5yIA5eEG4O/qc4GovhjJVpCbQbhGFTfgLQWVZdyNEzM3PPDEVFbpSx+pYxrpSn6jejiEPzRfb6K8V1J3D9PEIVjOb0ujD1TAmPv0+xiLaW9ISQL5LK5JHW9qpvgEpiP9FWJC5W54SlYmIKd9JAQxf2onrKTH root@gitlab
[root@gitlab opt]# cat ~/.ssh/id_rsa
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAlO/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IBl9tfY
Jv2JQCbkdhACE7WYdOT8JvATlUjzt7Mb16Op/wEb43on+71FiT4SQeEpOOGtzmp5
F7qE6469mYK8moDBFem0/xXmw1XgBCe0qJaBznF27vqiem91bSEfD9BAFFgr6Pm8
0gIozG2X8+QU5YX2APvkIQKBgApn43kuQ+pgvekrFJGWTbN8ehgdSREvFzniQuB0
AczF02+bOOOfh2FycqvM5aCEYNbiBeHpA+wgk6o5sGLVvheLNdLJ8YlDiwtWO5wY
zCzXxiSNy4i7SEdwwJ0TfOTw9lvi/rayhdtrPcJ7ECYjdezMYJjvPt3Wu6cxtcW4
+IBJAoGAJ0/HWMbUWP7iEMRkbwDbbxZsWU+GR0PIG2eCm0IVp6UYPQjtX+Z5Bhon
WdcXNNNmab8SbH550Sfoy3un/poBZT9/pvwgjVUAEpDMPp4TV1KaopXlD+fBlIva
/bxjd3nvo4UQ1YZrQhMocDToLpjMrHy0ubZVe4yPMJGW5EOVfO0=
-----END RSA PRIVATE KEY-----

3.root用户登录gitlab,将公钥复制到gitlab中

公钥添加成功后,此Linux机器即可免密登录gitlab了

17. gitlab代码管理

1.查看gitlab项目的ssh地址:git@192.168.178.181:cmdb_dev/chupeng_gitlab_project.git

2.Linux机器上没有代码的情况,直接克隆工程到本地

[root@gitlab opt]# mkdir /cp_gitlab && cd /cp_gitlab && git clone git@192.168.17                                                                                                         8.181:cmdb_dev/chupeng_gitlab_project.git
[root@gitlab cp_gitlab]# git clone git@192.168.178.181:cmdb_dev/chupeng_gitlab_project.git
Cloning into 'chupeng_gitlab_project'...
warning: You appear to have cloned an empty repository.
[root@gitlab cp_gitlab]# ls -a
.  ..  chupeng_gitlab_project
[root@gitlab cp_gitlab]# cd chupeng_gitlab_project/
[root@gitlab chupeng_gitlab_project]# ls -a
.  ..  .git

3.此时,可以在工程目录中写代码,然后提交

[root@gitlab chupeng_gitlab_project]# echo chupeng666 > cp_v1.txt
[root@gitlab chupeng_gitlab_project]#
[root@gitlab chupeng_gitlab_project]# ls
cp_v1.txt
[root@gitlab chupeng_gitlab_project]# git add .
[root@gitlab chupeng_gitlab_project]# git commit -m "this is the first commit add v1 file"

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@gitlab.(none)')

4.将代码推送到gitlab

[root@gitlab chupeng_gitlab_project]# git remote
origin
[root@gitlab chupeng_gitlab_project]# git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'git@192.168.178.181:cmdb_dev/chupeng_gitlab_project.git'
[root@gitlab chupeng_gitlab_project]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   cp_v1.txt
#

报错了。。。开始查找原因

原来没有创建git的用户配置。。。创建全局配置

[root@gitlab chupeng_gitlab_project]# git config --list --global
fatal: unable to read config file '/root/.gitconfig': No such file or directory
[root@gitlab chupeng_gitlab_project]#

[root@gitlab chupeng_gitlab_project]# git config --global user.name cp1
[root@gitlab chupeng_gitlab_project]# git config --global user.email chupeng130@163.com
[root@gitlab chupeng_gitlab_project]# git config --global color.ui true
[root@gitlab chupeng_gitlab_project]# git config --global --list
user.name=cp1
user.email=chupeng130@163.com
color.ui=true

再次提交。。。成功!!!

[root@gitlab chupeng_gitlab_project]# git commit -m "commit v1"
[master (root-commit) a1637d5] commit v1
 2 files changed, 2 insertions(+)
 create mode 100644 chupeng.txt
 create mode 100644 cp_v1.txt
[root@gitlab chupeng_gitlab_project]# git log --oneline
a1637d5 commit v1

再次推送到gitlab

[root@gitlab chupeng_gitlab_project]# git status
# On branch master
nothing to commit, working directory clean
[root@gitlab chupeng_gitlab_project]# git remote
origin
[root@gitlab chupeng_gitlab_project]# git push -u origin master
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 265 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To git@192.168.178.181:cmdb_dev/chupeng_gitlab_project.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

此时,去浏览器查看gitlab的工程

18. 推送分支代码到gitlab

1.创建进入分支,创建文件,提交

[root@gitlab chupeng_gitlab_project]# git branch
* master
[root@gitlab chupeng_gitlab_project]# git checkout -b cp_branch1
Switched to a new branch 'cp_branch1'
[root@gitlab chupeng_gitlab_project]# git branch
* cp_branch1
  master
[root@gitlab chupeng_gitlab_project]# echo branch1 > branch.txt
[root@gitlab chupeng_gitlab_project]# git add .
[root@gitlab chupeng_gitlab_project]# git commit -m "branch first commit v2"
[cp_branch1 e1fc739] branch first commit v2
 1 file changed, 1 insertion(+)
 create mode 100644 branch.txt
[root@gitlab chupeng_gitlab_project]# ls
branch.txt  chupeng.txt  cp_v1.txt

2.推送到gitlab

[root@gitlab chupeng_gitlab_project]# git remote
origin
[root@gitlab chupeng_gitlab_project]# git push -u origin cp_branch1
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 310 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for cp_branch1, visit:
remote:   http://192.168.178.181/cmdb_dev/chupeng_gitlab_project/merge_requests/new?merge_request%5Bsource_branch%5D=cp_branch1
remote:
To git@192.168.178.181:cmdb_dev/chupeng_gitlab_project.git
 * [new branch]      cp_branch1 -> cp_branch1
Branch cp_branch1 set up to track remote branch cp_branch1 from origin.

3.回到master,合并branch分支

[root@gitlab chupeng_gitlab_project]# git checkout master
Switched to branch 'master'
[root@gitlab chupeng_gitlab_project]# git branch
  cp_branch1
* master
[root@gitlab chupeng_gitlab_project]# git merge cp_branch1
Updating a1637d5..e1fc739
Fast-forward
 branch.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 branch.txt

4.推送到gitlab

[root@gitlab chupeng_gitlab_project]# git push -u origin master
Total 0 (delta 0), reused 0 (delta 0)
To git@192.168.178.181:cmdb_dev/chupeng_gitlab_project.git
   a1637d5..e1fc739  master -> master
Branch master set up to track remote branch master from origin.

5.添加标签

[root@gitlab chupeng_gitlab_project]# git log --oneline
e1fc739 branch first commit v2
a1637d5 commit v1

[root@gitlab chupeng_gitlab_project]# git tag -a v2.0 -m "e1fc739 add tag"
[root@gitlab chupeng_gitlab_project]# git tag
v2.0

6.再次推送到gitlab

[root@gitlab chupeng_gitlab_project]# git push origin v2.0
Counting objects: 1, done.
Writing objects: 100% (1/1), 155 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@192.168.178.181:cmdb_dev/chupeng_gitlab_project.git
 * [new tag]         v2.0 -> v2.0

7.浏览器查看gitlab工程版本库


最后更新: 2022-02-20 12:36:30