项目案例之GitLab企业级代码管理仓库

一.安项GitLab

 主机名 IP 备注 特殊要求
 git01  192.168.200.136  GIT客户端  无
 girlab  192.168.200.140  GITLAB服务端  内存2G

GitLab国内源下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7

 1 ##初始环境
 2 [root@zhengweiqiang ~]# cat /etc/redhat-release 
 3 CentOS Linux release 7.5.1804 (Core)  4 [root@zhengweiqiang ~]# uname -r  5 3.10.0-862.el7.x86_64  6 [root@zhengweiqiang ~]# echo "git lab 127.0.0.1" >>/etc/hosts  7 [root@zhengweiqiang ~]# tail -1 /etc/hosts  8 git lab 127.0.0.1  9 [root@zhengweiqiang ~]# ls 10 anaconda-ks.cfg 11 gitlab-11-2-stable-zh.tar.gz #GITLAB 汉化包 12 gitlab-ce-11.2.3-ce.0.el7.x86_64.rpm #GITLAB 安装包 13 14 [root@zhengweiqiang ~]# yum localinstall gitlab-ce-11.2.3-ce.0.el 15 7.x86_64.rpm -y 16 17 重要说明:localinstall 利用yum 光盘源装依赖包 18 #初始化GitLab 只需执行一次 19 [root@zhengweiqiang ~]# gitlab-ctl reconfigure 20 #查看gitlab启动状态 21 [root@zhengweiqiang ~]# gitlab-ctl status 22 run: alertmanager: (pid 13022) 185s; run: log: (pid 13048) 183s 23 run: gitaly: (pid 12859) 201s; run: log: (pid 12871) 200s 24 run: gitlab-monitor: (pid 12990) 186s; run: log: (pid 13042) 184s 25 run: gitlab-workhorse: (pid 12844) 201s; run: log: (pid 12850) 20 26 1srun: logrotate: (pid 12172) 263s; run: log: (pid 12881) 200s 27 run: nginx: (pid 12118) 269s; run: log: (pid 12852) 201s 28 run: node-exporter: (pid 12332) 251s; run: log: (pid 12883) 199s 29 run: postgres-exporter: (pid 13037) 184s; run: log: (pid 13045) 1 30 84srun: postgresql: (pid 11641) 324s; run: log: (pid 12869) 200s 31 run: prometheus: (pid 13000) 185s; run: log: (pid 13046) 184s 32 run: redis: (pid 11512) 330s; run: log: (pid 12834) 201s 33 run: redis-exporter: (pid 12553) 239s; run: log: (pid 12993) 185s 34 run: sidekiq: (pid 11993) 281s; run: log: (pid 12870) 200s 35 run: unicorn: (pid 11926) 287s; run: log: (pid 12837) 201s 36 37 ##查看GitLab版本号 38 [root@zhengweiqiang ~]# cat /opt/gitlab/embedded/service/gitlab-r 39 ails/VERSION 11.2.3

宿主机输入http://IP地址就可以访问了

密码最少为8位

登陆管理员账号 : root  密码:66666666

登陆后,我们就可以选择如下功能使用了

安装GitLab中文补丁

GitLab中文社区:https://gitlab.com/xhang/gitlab/tree/11-2-stable-zh

#解压GitLab中文补丁包
[root@zhengweiqiang ~]# tar xf gitlab-11-2-stable-zh.tar.gz 
#查看系统已经安装的GitLab版本号 [root@zhengweiqiang ~]# cat /opt/gitlab/embedded/service/gitlab-r ails/VERSION 11.2.3 #查看解压后的补丁包版本号 [root@zhengweiqiang ~]# cat gitlab-11-2-stable-zh/VERSION 11.2.3 说明: 补丁版本号和安装的GitLab版本号需要一致 #备份英文版GitLab [root@zhengweiqiang ~]# cp -r /opt/gitlab/embedded/service/gitlab -rails{,.bak} #将中文补丁包的内容覆盖英文版 [root@zhengweiqiang ~]# /bin/cp -rf gitlab-11-2-stable-zh/* /opt/ gitlab/embedded/service/gitlab-rails/bin/cp: cannot overwrite non-directory ‘/opt/gitlab/embedded/ser vice/gitlab-rails/log’ with directory ‘gitlab-11-2-stable-zh/log’/bin/cp: cannot overwrite non-directory ‘/opt/gitlab/embedded/ser vice/gitlab-rails/tmp’ with directory ‘gitlab-11-2-stable-zh/tmp’ 说明: 此报错不用管,因为已经设置过root密码,登陆过,所以会报错。 #重新配置GitLab [root@zhengweiqiang ~]# gitlab-ctl reconfigure #重启 [root@zhengweiqiang ~]# gitlab-ctl restart

 重新刷新浏览器访问GitLab

 创建一个项目

修改GitLab配置文件/etc/gitlab/gitlab.rb

我们需要修改GitLab的默认访问域名

GitLab默认监听端口为80,但是企业中,这个端口经常被别的服务占用,所以我们需要更换端口

 1 [root@zhengweiqiang ~]# cat /etc/gitlab/gitlab.rb | sed -n '13p;9
 2 43p' external_url 'http://gitlab.example.com'
 3 # nginx['listen_port'] = nil
 4 [root@zhengweiqiang ~]# vim /etc/gitlab/gitlab.rb 
 5 [root@zhengweiqiang ~]# cat /etc/gitlab/gitlab.rb | sed -n '13p;9
 6 43p' external_url 'http://192.168.200.140:8888'
 7 nginx['listen_port'] = 8888
 8 #重新配置
 9 [root@zhengweiqiang ~]# gitlab-ctl reconfigure
10 
11 #重新启动GitLab
12 [root@zhengweiqiang ~]# gitlab-ctl restart

重新访问浏览器192.168.200.144:8888

尝试将本地仓库代码推送到私有GitLab

 1 #添加GitLab仓库管理
 2 [root@zhengweiqiang mycode]# git remote add test http://192.168.200.140:8888/root/yunjisuan.git
 3 [root@zhengweiqiang mycode]# git remote -v
 4 test    http://192.168.200.140:8888/root/yunjisuan.git (fetch)
 5 test    http://192.168.200.140:8888/root/yunjisuan.git (push)
 6 
 7 #推送本地仓库master分支到远程仓库GitLab上
 8 [root@zhengweiqiang mycode]# git add *
 9 [root@zhengweiqiang mycode]# git commit -m "测试一下"
10 ####省略输出#####
11 [root@zhengweiqiang mycode]# git push -u test master
12 Username for 'http://192.168.200.140:8888': root
13 Password for 'http://[email protected]:8888': 
14 Counting objects: 3, done.
15 Compressing objects: 100% (2/2), done.
16 Writing objects: 100% (3/3), 244 bytes | 0 bytes/s, done.
17 Total 3 (delta 0), reused 0 (delta 0)
18 To http://192.168.200.140:8888/root/yunjisuan.git
19  * [new branch]      master -> master
20 
21 #推送本地仓库标签V1.0到远程仓库GitLab上
22 [root@zhengweiqiang mycode]# git tag v1.0
23 [root@zhengweiqiang mycode]# git push -u test v1.0
24 Username for 'http://192.168.200.140:8888': root
25 Password for 'http://[email protected]:8888': 
26 Total 0 (delta 0), reused 0 (delta 0)
27 To http://192.168.200.140:8888/root/yunjisuan.git
28  * [new tag]         v1.0 -> v1.0
29 
30 #推送本地仓库Linux分支到远程仓库GitLab上
31 [root@zhengweiqiang mycode]# git branch linux
32 [root@zhengweiqiang mycode]# git checkout linux
33 Switched to branch 'linux'
34 #切换到linux分支
35 [root@zhengweiqiang mycode]# git branch
36 * linux
37   master
38 #添加一个文件
39 [root@zhengweiqiang mycode]# touch linun.txt
40 [root@zhengweiqiang mycode]# git add *
41 [root@zhengweiqiang mycode]# git commit -m "分支第一次"
42 [linux b2e4ca5] 分支第一次
43  1 file changed, 0 insertions(+), 0 deletions(-)
44  create mode 100644 linun.txt
45 
46 [root@zhengweiqiang mycode]# git push -u test linux
47 Username for 'http://192.168.200.140:8888': root
48 Password for 'http://[email protected]:8888': 
49 Counting objects: 2, done.
50 Compressing objects: 100% (2/2), done.
51 Writing objects: 100% (2/2), 256 bytes | 0 bytes/s, done.
52 Total 2 (delta 1), reused 0 (delta 0)
53 remote: 
54 remote: To create a merge request for linux, visit:
55 remote:   http://192.168.200.140:8888/root/yunjisuan/merge_reques
56 ts/new?merge_request%5Bsource_branch%5D=linuxremote: 
57 To http://192.168.200.140:8888/root/yunjisuan.git
58  * [new branch]      linux -> linux

 尝试在本地仓库克隆GitLab的项目Linux分支到本地仓库

 1 #创建测试目录
 2 [root@zhengweiqiang mycode]# mkdir -p /test
 3 [root@zhengweiqiang mycode]# cd /test/
 4 #克隆远程仓库分支Linux
 5 [root@zhengweiqiang test]# git clone -b linux http://192.168.200.
 6 140:8888/root/yunjisuan.git
 7 Cloning into 'yunjisuan'...
 8 Username for 'http://192.168.200.140:8888': root
 9 Password for 'http://[email protected]:8888': 
10 remote: Enumerating objects: 5, done.
11 remote: Counting objects: 100% (5/5), done.
12 remote: Compressing objects: 100% (4/4), done.
13 remote: Total 5 (delta 1), reused 0 (delta 0)
14 Unpacking objects: 100% (5/5), done.
15 Checking connectivity... done.
16 [root@zhengweiqiang test]# ls
17 yunjisuan
18 [root@zhengweiqiang test]# ls yunjisuan/
19 1  10  2  3  4  5  6  7  8  9  linun.txt

配置GitLab的SSH密钥连接方式

#git01生成密钥对
[root@zhengweiqiang ~]# ssh-keygen -t rsa -C '[email protected]'
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:EPfg/7kL5kvu5lKrpD1o//ONoWVNvBizwNfWyeIBK9o [email protected]
omThe key's randomart image is:
+---[RSA 2048]----+
|      . o        |
|       + o       |
|      . . ..     |
|       . o  oo...|
|        S.+.+o=o.|
|        o o+.Xo. |
|       o.E+.O.o  |
|      o+o=+= =   |
|     ...+OO+=..  |
+----[SHA256]-----+

#公钥内容,复制到GitLab上
[root@zhengweiqiang ~]# cd ~/.ssh/
[root@zhengweiqiang .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQChdR9x4cbGdm0YMz+3ENiLX96Ol
q2ucoNf63qB4XeC0ilHHj8YboZf5Fs/8MygrVulLG6E5GJnDDx7PcN8hUaF5NfmuiWRb+KK6UJ/olWb+hnathPgvlpuEC7hpF2aCM3tF3Hr55OMxWf0u7Vnj02dHcnYgtoG1/H2OfVqDVL2F4gm45IWB8cPMvuOoECqbgsZOkl2IrQaotlzJUhhRtujCa3ATaE6gQuHztFWqPoXdDCvc1/gzKVPwFHZQvD2PJRDUBl0SRkfUo4EhQcpAYjJS+oU0bwALL++KCXOHPbR8a+2wEEHr2NzxSLfCJ9eGyJRRkwUtSs7wWBzyOMpaFhJ 804225249@qq.com

在浏览器打开GitLab

 

利用SSH方式克隆GitLab上的一个项目

 1 [root@zhengweiqiang ~]# mkdir -p /test
 2 root@zhengweiqiang ~]# cd /test/
 3 
 4 [root@zhengweiqiang test]# git clone -b linux git@192.168.200.140
 5 :root/yunjisuan.git
 6 Cloning into 'yunjisuan'...
 7 .The authenticity of host '192.168.200.140 (192.168.200.140)' can
 8 't be established.ECDSA key fingerprint is SHA256:Eeo38Y88KcOSuPspyYgLADrIhrx3wRCQQ
 9 fm1/4qHYZY.ECDSA key fingerprint is MD5:93:67:c9:91:71:11:9b:af:80:d0:ed:79:
10 bc:f9:a3:bd.Are you sure you want to continue connecting (yes/no)? yes
11 Warning: Permanently added '192.168.200.140' (ECDSA) to the list 
12 of known hosts.\remote: Enumerating objects: 5, done.
13 remote: Counting objects: 100% (5/5), done.
14 remote: Compressing objects: 100% (4/4), done.
15 remote: Total 5 (delta 1), reused 0 (delta 0)
16 Receiving objects: 100% (5/5), done.
17 Resolving deltas: 100% (1/1), done.
18 Checking connectivity... done.
19 
20 [root@zhengweiqiang test]# ls
21 yunjisuan
22 [root@zhengweiqiang test]# ls yunjisuan/
23 1  10  2  3  4  5  6  7  8  9  linun.txt

配置GitLab邮件服务

配置邮件服务的用途:

  • 有和并要求时,邮件通知
  • 账号注册时,邮件验证
  • 修改密码时,通过邮件修改

配置步骤:

  • 开启QQ邮箱的smtp服务
  • 修改GitLab配置
  • 测试邮件服务是否正常

开启GitLab服务postfix服务并开启QQ邮箱的smtp服务

[root@zhengweiqiang ~]# systemctl start postfix
[root@zhengweiqiang ~]# systemctl enable postfix
[root@zhengweiqiang ~]# systemctl status postfi

 

 

修改配置文件/etc/gitlab/gitlab.rb

[root@zhengweiqiang ~]# cat -n /etc/gitlab/gitlab.rb | sed -n '53p;472,480p;618p;'
    53     gitlab_rails['gitlab_email_from'] = '[email protected]' #GitLab默认邮箱
   472    gitlab_rails['smtp_enable'] = true                     #开启功能
   473    gitlab_rails['smtp_address'] = "smtp.qq.com"      #QQ的smtp服务
   474    gitlab_rails['smtp_port'] = 465                     
   475    gitlab_rails['smtp_user_name'] = "[email protected]"  #smtp的邮箱
   476    gitlab_rails['smtp_password'] = "开通QQsmtp的字符串" 
   477    gitlab_rails['smtp_domain'] = "qq.com"                 #smtp域名
   478    gitlab_rails['smtp_authentication'] = "login"
   479    gitlab_rails['smtp_enable_starttls_auto'] = true
   480    gitlab_rails['smtp_tls'] = true
   618    user['git_user_email'] = "[email protected]"      #git用户邮箱

#重新加载GitLab配置文件
[root@zhengweiqiang ~]# gitlab-ctl reconfigure

#重启服务
[root@zhengweiqiang ~]# gitlab-ctl restart

#进入GitLab控制台进行邮箱发送测试
[root@zhengweiqiang ~]# gitlab-rails console
-----------------------------------------------------------------
-------------------- GitLab:       11.2.3 (06cbee3)
 GitLab Shell: 8.1.1
 postgresql:   9.6.8
-----------------------------------------------------------------
--------------------Loading production environment (Rails 4.2.10)
irb(main):001:0> Notify.test_email('[email protected]','this is ti
irb(main):002:1' tle','hello').deliver_now


特别说明:
Notify.test.email('收件人邮箱''邮件标题','邮件内容')

 

GitLab的账号注册及分组

账户注册测试

 

我们在注册的时候,用的时乱写的邮箱并能注册和登陆

显然这在企业里是绝对不允许的

 

开启GitLab邮箱验证功能

重新登陆管理员账户root,密码666666,进行如下操作

退出账号,从新注册后

由上图,我们发现,此时注册用户,已经进不去GitLab了

必须要用户进行邮箱确认后,才可登陆

 

创建一个项目组

给组员添加成员并授权

 添加权限成功后,GitLab会自动邮件通知这个用户

给项目组创建一个新项目

[root@zhengweiqiang ~]# mkdir test
[root@zhengweiqiang ~]# cd test/
[root@zhengweiqiang test]# git init
Initialized empty Git repository in /root/test/.git/
[root@zhengweiqiang test]# 
[root@zhengweiqiang test]# touch {1..5}
[root@zhengweiqiang test]# git add *
[root@zhengweiqiang test]# git commit -m "yun169"

[root@zhengweiqiang test]# git push -u test master
Username for 'http://192.168.200.140:8888': [email protected]     
Password for 'http://[email protected]@192.168.200.140:8888': Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 215 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.200.140:8888/dev/yun169.git
 * [new branch]      master -> master

猜你喜欢

转载自www.cnblogs.com/GokouRuri-zwq/p/10164799.html
今日推荐