5月 272019
 

对于内部项目使用的GitLab服务关闭用户注册功能

取消勾选Sign-up enable选项并提交保存

退出登录后再次访问首页,显示只有Sign in功能,注册入口已关闭

新建用户tom及jerry,在无邮件服务器配置的情况下,重置用户密码(Gitlab.2019)

新建用户tom

新建用户jerry

初始化用户tom的密码

提示用户tom密码初始化成功

初始化用户jerry的密码

 

提示用户jerry密码初始化成功

使用用户tom登录GitLab服务

按照系统提示修改密码

 

提示密码修改成功并重新登录

在GitLab上使用tom用户新建项目1st并赋予Jerry用户访问权限

创建项目(Private)

项目创建成功

在项目设置的成员设置中添加用户jerry并指定为Developer角色权限

查看当前项目的成员信息,显示已成功添加jerry用户

在客户机上添加tom和jerry两个用户并安装git客户端

[root@client ~]# useradd tom
[root@client ~]# useradd jerry
[root@client ~]# yum -y install git

切换为tom用户并新建SSH密钥并查看公钥信息

[root@client ~]# su - tom
[tom@client ~]$ ssh-keygen -t ed25519 -C "tom@licensebox.cn"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/tom/.ssh/id_ed25519): 
Created directory '/home/tom/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/tom/.ssh/id_ed25519.
Your public key has been saved in /home/tom/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:UVeM2yOmysAcgcl708kGa3kbenZXDWHw2l6NmvwiyOA tom@licensebox.cn
The key's randomart image is:
+--[ED25519 256]--+
| . o . o=+. |
| + o . ..oo |
| . B.. o.o |
| . B B. +o+.o|
| = *So o.oo.o|
| * + o..+ . |
| . B + .+ . |
| E = . .. |
| . .. |
+----[SHA256]-----+
[tom@client ~]$ cat .ssh/id_ed25519.pub 
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOSSfWAFWITPSj+qXuXTIYhqRg6Stw96birC/7gzTiOg tom@licensebox.cn
[tom@client ~]$

将公钥信息复制粘贴至GitLab用户tom的SSH密钥配置信息中

添加公钥信息

添加成功

用户tom本地客户机使用git命令访问仓库并新建文件和添加注释并上传

[tom@client ~]$ git config --global user.name "Tom"
[tom@client ~]$ git config --global user.email "tom@licensebox.cn"
[tom@client ~]$ git clone git@gitlab.licensebox.cn:tom/1st.git
Cloning into '1st'...
The authenticity of host 'gitlab.licensebox.cn (47.75.246.214)' can't be established.
ECDSA key fingerprint is SHA256:O/ea5Lg0EzQZc+901DKkDlmv5IxBvShOQ6wknzCJRS4.
ECDSA key fingerprint is MD5:04:5a:fd:80:b9:1d:81:ed:2e:df:a8:f7:1b:02:33:7f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.licensebox.cn,47.75.246.214' (ECDSA) to the list of known hosts.
warning: You appear to have cloned an empty repository.
[tom@client ~]$ cd 1st/
[tom@client 1st]$ touch README.md
[tom@client 1st]$ echo "Hello World" > README.md 
[tom@client 1st]$ git add README.md
[tom@client 1st]$ git commit -m "add README"
[master (root-commit) de77d4d] add README
1 file changed, 1 insertion(+)
create mode 100644 README.md
[tom@client 1st]$ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 223 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitlab.licensebox.cn:tom/1st.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
[tom@client 1st]$

在GitLab页面确认已上传的项目文件

用户jerry使用本地客户机生成密钥对并将公钥信息添加至GitLab上用户jerry的SSH密钥配置信息中

[jerry@client ~]$ ssh-keygen -t ed25519 -C "jerry@licensebox.cn" 
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/jerry/.ssh/id_ed25519): 
Created directory '/home/jerry/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/jerry/.ssh/id_ed25519.
Your public key has been saved in /home/jerry/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:6uVleGBOpisnPjeJR2bEy5VmV9CMX08kkLOmHQ4m3eQ jerry@licensebox.cn
The key's randomart image is:
+--[ED25519 256]--+
| .=.o...|
| . B ...|
| . o * + o |
| o * = E .|
| o =S+ * . |
| *B o. o |
| =o.+ + |
| =.*+ + |
| ..Bo.. |
+----[SHA256]-----+
[jerry@client ~]$ cat .ssh/id_ed25519.pub 
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMmxHQCKvwn38NIyLuhc9EOwymQePQkwnA1EbIt9Mhpz jerry@licensebox.cn
[jerry@client ~]$

使用jerry用户在客户机上进行git clone操作并查看从服务器上拉取的仓库文件及内容

[jerry@client ~]$ git config --global user.name "Jerry"
[jerry@client ~]$ git config --global user.email "jerry@licensebox.cn"
[jerry@client ~]$ git clone git@gitlab.licensebox.cn:tom/1st.git
Cloning into '1st'...
The authenticity of host 'gitlab.licensebox.cn (47.75.246.214)' can't be established.
ECDSA key fingerprint is SHA256:O/ea5Lg0EzQZc+901DKkDlmv5IxBvShOQ6wknzCJRS4.
ECDSA key fingerprint is MD5:04:5a:fd:80:b9:1d:81:ed:2e:df:a8:f7:1b:02:33:7f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.licensebox.cn,47.75.246.214' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[jerry@client ~]$ ls 1st/
README.md
[jerry@client ~]$ cat 1st/README.md 
Hello World
[jerry@client ~]$ 
5月 272019
 

新建仓库

在没有配置SSH密钥对之前,无法使用基于SSH的代码推拉操作。

You won’t be able to pull or push project code via SSH until you add an SSH key to your profile

为root用户准备SSH密钥(未设置私钥密码)

[root@client ~]# ssh-keygen -t ed25519 -C "harvey.mei@msn.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/root/.ssh/id_ed25519): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_ed25519.
Your public key has been saved in /root/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:zZYLuVxm+EDjPAHGjlgJjTGdkw0hrjMwOuLs6r0rrnU harvey.mei@msn.com
The key's randomart image is:
+--[ED25519 256]--+
| =*oOo |
| ..oO.o. |
|o .o + + |
|oo. . .+ B . |
|B S O |
|++ . @ . |
| o. E o o |
|.o.. |
|B+.+o |
+----[SHA256]-----+
[root@client ~]#

为私钥文件添加或者修改密码

ssh-keygen -p -o -f <keyname>

复制公钥内容到GitLab账户设置中

[root@client ~]# cat .ssh/id_ed25519.pub 
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHWIgmnrN7FGjKTdMxYE3y6py3SKp5cO0wnc2dlWNj5o harvey.mei@msn.com
[root@client ~]#
 

查看已导入的SSH公钥信息


测试用户root的SSH密钥有效性,按照提示将服务器端公钥存储在本地已知主机列表文件known_hosts文件中

[root@client ~]# ssh -i .ssh/id_ed25519 -T git@gitlab.licensebox.cn
The authenticity of host 'gitlab.licensebox.cn (47.75.246.214)' can't be established.
ECDSA key fingerprint is SHA256:s+kUB7fDvU43bDqTmukBOoSd/8o/gxzuQC/Kk1aYLio.
ECDSA key fingerprint is MD5:f4:2a:7f:58:6c:d8:d3:ee:90:3a:14:9f:f9:5b:d4:4c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.licensebox.cn,47.75.246.214' (ECDSA) to the list of known hosts.
Welcome to GitLab, @root!
[root@client ~]#

查看保留在本地的服务器端

[root@client ~]# cat .ssh/known_hosts

gitlab.licensebox.cn,47.75.246.214 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLPz49yrtFCwkwt+5/kCXekab8jtrEmf8OpPyfjqtoOuPMlHbhH/rnlNxcicFMF+0U9AD/RIigglJh5SFgSYQ3A=
[root@client ~]#

本地操作系统安装Git客户端程序

[root@client ~]# git
-bash: git: command not found
[root@client ~]# yum -y install git

将仓库Clone到本地磁盘(无需再次验证身份)

[root@client ~]# git clone git@gitlab.licensebox.cn:root/licensebox.git 
Cloning into 'licensebox'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

查看本地Git目录及文件内容,确认成功Clone仓库至本地磁盘

[root@client ~]# ls
licensebox
[root@client ~]# ls licensebox/
README.md
[root@client ~]# cat licensebox/README.md 
# licensebox

LicenseBox Project[root@client ~]#
5月 242019
 

配置要求:最低4GB可用内存

查看当前系统版本

[root@iZj6cehstgjoj3qav88fidZ ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[root@iZj6cehstgjoj3qav88fidZ ~]#

安装GitLab服务YUM仓库

企业版

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

社区版

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

查看仓库配置文件

企业版

[root@iZj6cehstgjoj3qav88fidZ ~]# ls /etc/yum.repos.d/
CentOS-Base.repo epel.repo gitlab_gitlab-ee.repo
[root@iZj6cehstgjoj3qav88fidZ ~]#

社区版

[root@iZj6cehstgjoj3qav88fidZ ~]# ls /etc/yum.repos.d/
CentOS-Base.repo epel.repo gitlab_gitlab-ce.repo gitlab_gitlab-ee.repo
[root@iZj6cehstgjoj3qav88fidZ ~]# cat /etc/yum.repos.d/gitlab_gitlab-ce.repo 
[gitlab_gitlab-ce]
name=gitlab_gitlab-ce
baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/7/$basearch
repo_gpgcheck=1
gpgcheck=1
enabled=1
gpgkey=https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey
https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[gitlab_gitlab-ce-source]
name=gitlab_gitlab-ce-source
baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=1
enabled=1
gpgkey=https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey
https://packages.gitlab.com/gitlab/gitlab-ce/gpgkey/gitlab-gitlab-ce-3D645A26AB9FBD22.pub.gpg
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[root@iZj6cehstgjoj3qav88fidZ ~]#

执行安装时,变量中设置有效的域名解析并指定为https协议时,将自动请求Let’s Encrypt证书并安装,首次安装建议使用http协议,之后自行安装TLS证书

启用TLS证书安装

sudo EXTERNAL_URL="https://gitlab.licensebox.cn" yum install -y gitlab-ce

禁用TLS证书安装

sudo EXTERNAL_URL="http://gitlab.licensebox.cn" yum install -y gitlab-ce

提示安装成功

Thank you for installing GitLab!
GitLab should be available at http://gitlab.licensebox.cn

查看端口监听及服务进程

使用浏览器访问Gitlab首页,按照提示设置初始密码

使用设置的初始密码进行首次登录

查看GitLab默认首页

社区版的版本升级更新操作

备份数据(默认备份路径/var/opt/gitlab/backups)

sudo gitlab-rake gitlab:backup:create STRATEGY=copy

执行更新

sudo yum install -y gitlab-ce