GitLab
Gitlab is an open source application developed by Ruby on Rails, which implements a self-hosted Git project repository, which can access public or private projects through the web interface
Official website: https://about.gitlab.com
surroundings
CPU name | IP |
---|---|
gitlab | 192.168.1.20 |
client01 | 192.168.1.19 |
client02 | 192.168.1.11 |
Configure gitlab
1. Install the prerequisite software
[root@gitlab ~]# yum -y install curl policycoreutils openssh-server openssh-clients postfix
2. Download the gitlab installation package
[root@gitlab ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm(清华源)
[root@gitlab ~]# yum -y install gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm
3. Modify the configuration file, specify the ip address
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
修改:
external_url 'http://192.168.1.20‘
5. Configure to start gitlab
[root@gitlab ~]# gitlab-ctl reconfigure //配置启动gitlab
[root@gitlab ~]# gitlab-ctl status //查看状态
run: gitaly: (pid 19378) 14878s; run: log: (pid 18940) 14914s
run: gitlab-monitor: (pid 19395) 14878s; run: log: (pid 19113) 14906s
run: gitlab-workhorse: (pid 19366) 14879s; run: log: (pid 18708) 14932s
run: logrotate: (pid 89443) 520s; run: log: (pid 18869) 14920s
run: nginx: (pid 18789) 14926s; run: log: (pid 18788) 14926s
run: node-exporter: (pid 19064) 14908s; run: log: (pid 19063) 14908s
run: postgres-exporter: (pid 19426) 14877s; run: log: (pid 19282) 14892s
run: postgresql: (pid 18318) 14970s; run: log: (pid 18317) 14970s
run: prometheus: (pid 19413) 14877s; run: log: (pid 19220) 14898s
run: redis: (pid 18195) 14977s; run: log: (pid 18194) 14977s
run: redis-exporter: (pid 19169) 14900s; run: log: (pid 19168) 14900s
run: sidekiq: (pid 18648) 14938s; run: log: (pid 18647) 14938s
run: unicorn: (pid 18578) 14944s; run: log: (pid 18577) 14944s
[root@gitlab ~]# gitlab-ctl start/stop/restart //gitlab服务管理命令(开启/关闭/重启)
Gitlab web management
1. Log in to gitlab
Set the password first, 12345678, and reconfirm 12345678
Username: root
Password: 12345678
2. Cancel the login page registration function
Log in to gitlab >> admin area (small wrench diagram on the top menu bar >> Settings on the left panel >> Sign-up Restrictions >> Uncheck sign-up enabled >> Drop down and select save
3. Modify the login welcome page
Log in to gitlab >> admin area >> Appearance >> fill in the administrator’s contact information and logo >> save
Effect picture after setting:
Case
Project creation
1. Project creation process
(1) Create a group (group)
登录gitlab >> admin area >> new group
(2) Create user (user)
Log in to gitlab >> admin area >> new user >> add username, email >> create >> edit >> modify password
(3) Create a project
Log in to gitlab >> admin area >> new project >> pay attention to select group
Groups in Gitlab have three access rights to projects:
Authority | Explanation |
---|---|
Private | Only group members can see |
Internal | As long as the logged in user can see |
Public | Everyone can see |
(4) Add members to the group
Add wangwu to accp,
Gitlab users have five permissions in the group:
Authority | Explanation |
---|---|
Guest | Can create issues, post comments, and cannot read and write the repository |
Reporter | Code can be cloned but not submitted. Test and product manager can grant this permission |
Developer | Can clone code, develop, submit, push, developers can give this permission |
Master | You can create projects, add tags, protect branches, add project members, and edit projects. The core RD leader can grant this permission |
Owner | You can set project access permissions-Visibility Level, delete projects, migrate projects, management team members, and the development team leader can grant this permission |
Core developers update code process (administrator)
[root@client01 mengya]# git config --global user.name "client01"
[root@client01 mengya]# git config --global user.email "[email protected]"
[root@localhost ~]# ssh-keygen -t rsa //创建密钥
[root@client01 ~]# cat /root/.ssh/id_rsa.pub //复制公钥
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDlwRgAZVenUMB7r0GTsYBpMdtM2RPMF19I9nSOihMSZz5p5N0OZg3QdN4uEcv0CFV5/SZCu3bAB3xfUkOSr9vzaO5mPW+3582f4YCSkNX+x5Nt0NoakUDNgqtZzWbbCsbL5jFrI+Rvi/RMWq+QGrpl3RIoNSQr0EPYt6sf4ay9U54sw0jivvsZ772Z9xdM5viV0DIy2vs1uWbG5knb3VkN7RYwgVbTrv4tYCRxTX47BX7wRSTFfb4G87JXN2YxB/pVLXxOmWqhJ4CjAUu+hgcHVhnPlX2goSNgWsOp968+yyngR8KPtwSiB0TfknAAxsAsJyL1PHptYaVfiTNZ6Qm1 root@client01
[root@client01 ~]# git clone [email protected]:accp/mengya.git //克隆下载项目
正克隆到 'mengya'...
The authenticity of host '192.168.1.20 (192.168.1.20)' can't be established.
ECDSA key fingerprint is SHA256:MnsIsq7n/9t5QHT4m95cWHJRxBrBQH5PUQ8YjcFJkfs.
ECDSA key fingerprint is MD5:24:5a:1e:0b:3a:20:32:a8:c0:5d:1a:03:da:26:e6:65.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.20' (ECDSA) to the list of known hosts.
warning: 您似乎克隆了一个空版本库。
[root@client01 ~]# cd mengya/
[root@client01 mengya]# echo 123123 > new.txt
[root@client01 mengya]# echo 123123 > new1.txt
[root@client01 mengya]# echo 123123 > new2.txt
[root@client01 mengya]# git add .
[root@client01 mengya]# git commit -m "add new.txt"
[root@client01 mengya]# git commit -m "add new.txt"
[master(根提交) 1a09815] add new.txt
3 files changed, 3 insertions(+)
create mode 100644 new.txt
create mode 100644 new1.txt
create mode 100644 new2.txt
[root@client01 mengya]# git push -u origin master
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 221 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:accp/mengya.git
* [new branch] master -> master
分支 master 设置为跟踪来自 origin 的远程分支 master。
Ordinary developers update code process (wangwu)
Change the permissions of wangwu in the group
[root@client02 data]# git config --global user.name "wangwu"
[root@client02 data]# git config --global user.email "[email protected]"
[root@client02 ~]# ssh-keygen -t rsa // 创建本地秘钥
[root@client02 ~]# cat /root/.ssh/id_rsa.pub //复制公钥
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC99Y7Rd5ipdBJyql8xnHwrn+UMuyFqmTWjZhpY9JITowjutW3wt1THvBGh+8r7XRnuf2/3Pu02tnDhe3Nr/LE6B7GHNvjInGgJtXwIHlJxgO79z1xxv8YSEZiRS9JvJ0bMN4h0PJqclbnx52BC3cdycl75efx28wMczX3/Vb5r3iYXVLRaz141xhtKuy24qBjo6WJdlMNUhyT4vf73vmZRTBrDLCFXq+XVfoqJYIr54IVJkKFyfopm0kRlfINMUJPOjoLWzl+cj3Tfd30AvrhuSpO1UPA0ty46u59RsVYb4pcMNE+nZtDr7IL3OPxwGM90xPPPmkNgsdGKHxHVavPD root@client02
Switch wangwu login, paste the public key
关联远程仓库
[root@client02 ~]# mkdir /data
[root@client02 ~]# cd /data
[root@client02 data]# git init
Initialized empty Git repository in /data/.git/
[root@client02 data]# git remote add origin [email protected]:accp/mengya.git //关联远程仓库
[root@client02 data]# git pull origin master //下载同步代码
The authenticity of host '192.168.1.20 (192.168.1.20)' can't be established.
ECDSA key fingerprint is SHA256:MnsIsq7n/9t5QHT4m95cWHJRxBrBQH5PUQ8YjcFJkfs.
ECDSA key fingerprint is MD5:24:5a:1e:0b:3a:20:32:a8:c0:5d:1a:03:da:26:e6:65.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.20' (ECDSA) to the list of known hosts.
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 8 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (8/8), done.
From 192.168.1.20:accp/mengya
* branch master -> FETCH_HEAD
创建分支,修改代码
[root@clien02 data]# git checkout -b wang
Switched to a new branch 'wang'
[root@clien02 data]# echo 222 > aa.txt
[root@clien02 data]# git add aa.txt
[root@clien02 data]# git commit -m "add aa.txt"
[wang c68b837] add aa.txt
1 file changed, 1 insertion(+)
create mode 100644 aa.txt
推送dev分支 (普通用户无权推送master)
[root@client02 data]# git push -u origin wang
[root@clien02 data]# git push -u origin wang
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 260 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote:
remote: To create a merge request for wang, visit:
remote: http://192.168.1.20/accp/mengya/merge_requests/new?merge_request%5Bsource_branch%5D=wang
remote:
To [email protected]:accp/mengya.git
* [new branch] wang -> wang
Branch wang set up to track remote branch wang from origin.
wangwu creates a merge request on the web interface
Switch back to the administrator account and agree to the merge request