文章目录
一、gitlab server搭建过程
[root@vm1 ~]# yum install -y policycoreutils-python
//10.x以后开始依赖policycoreutils-python
gitlab的下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
安装gitlab:
[root@vm1 ~]# rpm -ivh gitlab-ce-11.10.1-ce.0.el7.x86_64.rpm
warning: gitlab-ce-11.10.1-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:gitlab-ce-11.10.1-ce.0.el7 ################################# [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
[root@vm1 ~]#
gitlab的配置文件
[root@vm1 ~]# vim /etc/gitlab/gitlab.rb
[root@vm1 ~]#egrep "^external_url|^nginx" /etc/gitlab/gitlab.rb
external_url 'http://192.168.1.146:8081' #绑定监听的域名或IP(企业中最好是域名)
nginx['listen_port'] = 8081 #修改nginx的port
[root@vm1 ~]#
gitlab-ctl reconfigure 自动配置
使用gitlab-ctl reconfigure 自动配置,初始化信息
[root@vm1 ~]# gitlab-ctl reconfigure
#<生成 /var/opt/gitlab/ 各种子配置, 该命令建议仅在初始化时使用一次>
.....
使用gitlab-ctl start 启动gitlab服务
[root@vm1 ~]# gitlab-ctl start
ok: run: gitaly: (pid 22896) 2922s
ok: run: gitlab-monitor: (pid 22914) 2921s
ok: run: gitlab-workhorse: (pid 22882) 2922s
ok: run: logrotate: (pid 22517) 2987s
ok: run: nginx: (pid 22500) 2993s
ok: run: node-exporter: (pid 22584) 2974s
ok: run: postgres-exporter: (pid 22946) 2919s
ok: run: postgresql: (pid 22250) 3047s
ok: run: prometheus: (pid 22931) 2920s
ok: run: redis: (pid 22190) 3053s
ok: run: redis-exporter: (pid 22732) 2962s
ok: run: sidekiq: (pid 22472) 3005s
ok: run: unicorn: (pid 22433) 3011s
[root@vm1 ~]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 22500 root 7u IPv4 50923 0t0 TCP *:http (LISTEN)
nginx 22501 gitlab-www 7u IPv4 50923 0t0 TCP *:http (LISTEN)
[root@vm1 ~]#
二、gitlab的使用
在浏览器中输入 http://192.168.1.146,然后 change password: ,并使用root用户登录 即可 (后续动作根据提示操作)
修改初始密码
修改密码也可以:gitlab-rails console production
irb(main):001:0> user = User.where(id: 1).first // id为1的是超级管理员
irb(main):002:0>user.password = 'yourpassword' // 密码必须至少8个字符,最好是数字
irb(main):003:0>user.save! // 如没有问题 返回true
exit // 退出
登录gitlab 如下所示:
创建 group ,组名为test01 ,如下所示:
去掉用户的自动注册功能:
admin are -> settings -> Sign-up Restrictions 去掉钩钩,然后拉到最下面保存,重新登录
创建用户test如下所示:
将用户添加到组中,并指定test为本组的owner:
使用test用户的身份与密码登录到gitlab界面中
根据提示,修改密码
test用户创建Project
指定项目的存储路径和项目名称,如下所示
根据提示,选择上传代码的方式
为项目创建Dev分支,如下所示:
在 client 上添加Tompson的用户:
[root@vm2 ~]# useradd test
[root@vm2 ~]# su - test
[test@vm2 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/test/.ssh/id_rsa):
Created directory '/home/test/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/test/.ssh/id_rsa.
Your public key has been saved in /home/test/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:kA/sGksTUUGuttuVD3VzGYpbhsvyCuxaH2OOr3DSucE test@vm2
The key's randomart image is:
+---[RSA 2048]----+
| .o+. |
| + . |
| . * . |
| + + o . o |
| * . S + * o |
| o X . + * o |
| * E O + |
| O X B |
| o.*o=.o |
+----[SHA256]-----+
[test@vm2 ~]$ cat .ssh/id_rsa.pub ssh-rsa
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+TsjXYeb9LmWIVzX2H2wYnt13dBmFZ8uKYofzuzpCtwaEh9E7fHWnycXFcN9yfCCxXJQj6EnM2W6dPNHRxgKodldm05Vg+YkyzKnHt1gX/bPl5vT6LiQw/6wWAoHmq2Jvcr228asutvNHB5ARAbXXbcjSEDNsB+2OZU+xd1c6ww4zr3eRwl/pDcrG4tYZjSl4cwK7mz+fzlokwou5JQnwkPI8ZoPZm5s9ef2NozwdB6rVKWDjn3KAD0Hqr4htmLi7Sc9t4XFUA7nxncgU2N/nswo0z1gB39Ju78n/c/UQDjUhn1WY7r86cSitglK7JH7CAYwjXlW1Ml89b9xaoRfb test@vm2
将test的公钥复制到gitlab中: 使用test用户的身份与密码登录到gitlab界面中,然后在ssh-key中添加 相关的key ,如下所示:
为test用户配置git
[test@vm2 ~]$ git config --global user.email "test@domain.cn"
[test@vm2 ~]$ yum -y install git
Loaded plugins: fastestmirror
You need to be root to perform this command.
[test@vm2 ~]$ git config --global user.name "Tompson"
[test@vm2 ~]$ yum -y install git
Loaded plugins: fastestmirror
You need to be root to perform this command.
[test@vm2 ~]$ http://192.168.1.146:8081/test/study-plan.git
-bash: http://192.168.1.146:8081/test/study-plan.git: No such file or directory
[test@vm2 ~]$ git clone http://192.168.1.146:8081/test/study-plan.git
Cloning into 'study-plan'...
Username for 'http://192.168.1.146:8081': test
Password for 'http://test@192.168.1.146:8081':
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
[test@vm2 ~]$
创建一下新文件,添加内容,并提交到master分支:
[test@vm2 study-plan]$ vim sag
[test@vm2 study-plan]$ git add .
[test@vm2 study-plan]$ git commit -m "test"
[master 2f8ca12] test
1 file changed, 1 insertion(+)
create mode 100644 sag
[test@vm2 study-plan]$ git push origin master
Username for 'http://192.168.1.146:8081': test
Password for 'http://test@192.168.1.146:8081':
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 276 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.1.146:8081/test/study-plan.git
c500d03..2f8ca12 master -> master
使用test用户登录gitlab web,在界面中创建一个合并请求:
提×××并请求:
然后使用test用户登录 gitlab web ,找到“合并请求” ,然后将master分支合并到dev分支,如下所示:
gitlab的版本不一样,Web界面所在的位置可能回发生变化文章中所用的版本为:gitlab-ce-11.10.1
大部分公司的处理流程如下:
PM在gitlab创建任务,分配给开发人员
开发人员领取任务后,在本地使用git clone拉取代码库
开发人员创建开发分支(git checkout -b dev),并进行开发
开发人员完成之后,提交到本地仓库(git commit )
开发人员在gitlab界面上申请分支合并请求(Merge request)
PM在gitlab上查看提交和代码修改情况,确认无误后,确认将开发人员的分支合并到主分支(master)
开发人员在gitlab上Mark done确认开发完成,并关闭issue。这一步在提×××并请求时可以通过描述中填写"close #1"等字样,可以直接关闭issue