Gitlab basic usage and backup recovery upgrade

Posted by sdi126 on Tue, 08 Mar 2022 03:54:43 +0100

1. Create a group



2. Create an item and configure the item to belong to a group



3. Create users, set passwords, and assign groups to users




4. Other users log in to Gitlab


Turn off the registration function


5. The administrator assigns items to other users



6. View fzmyw user items



7. Basic use of gitlab


HTTP push code (root user)

[root@Gitlab ~]# yum -y install git    #Install git command

[root@Gitlab ~]# git config --global user.name "lss"

[root@Gitlab ~]# git config --global user.email "lss@yw.com"

[root@Gitlab ~]# echo 192.168.1.31 gitlab.fzmyw.com >> /etc/hosts

[root@Gitlab ~]# cat /etc/hosts      #Configure domain name resolution, otherwise this domain name cannot be resolved
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.31 gitlab.fzmyw.com

[root@Gitlab ~]# git clone http://gitlab.fzmyw.com/devops/my-web.git
 Cloning to 'my-web'...
Username for 'http://gitlab.fzmyw.com': root
Password for 'http://root@gitlab.fzmyw.com':
warning: You seem to have cloned an empty version library.

[root@Gitlab ~]# cd my-web/

[root@Gitlab my-web]# touch README.md

[root@Gitlab my-web]# echo my web project > readme md

[root@Gitlab my-web]# cat README.md
 my web project

[root@Gitlab my-web]# git add .

[root@Gitlab my-web]# git commit -m "add README.md"
[master(Root submission) c2ff023] add README.md
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
 
[root@Gitlab my-web]# git push -u origin master
Username for 'http://gitlab.fzmyw.com': root # needs to enter the account password
Password for 'http://root@gitlab.fzmyw.com':
Counting objects: 3, done.
Writing objects: 100% (3/3), 225 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://gitlab.fzmyw.com/devops/my-web.git
 * [new branch]      master -> master
 branch master Set to track from origin Remote branch of master. 

Question:

You need to enter the account password every time you push the code using http, so it is recommended to use ssh to push the code and add ssh key in Gitlab!

SSH push code (root user)

Because the previously used code is pushed by http, the locally specified http remote push address should be deleted first.

[root@Gitlab my-web]# 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:PW9VyLlEC3L4SN3O/wOb/qCWJ5CKrzOCjBmYeznV6XQ root@Gitlab
The key's randomart image is:
+---[RSA 2048]----+
|          .oo..  |
|          oo.+.+ |
|         . o o* .|
|         .. ..oo |
|..   . .S +   o. |
|+   . + Eo o o  .|
|o+.o o... . +.+ .|
|+o+. +..   =.+...|
| . ...=.  ..+....|
+----[SHA256]-----+

[root@Gitlab my-web]# cat /root/.ssh/id_rsa.pub   #View the public key of root user
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5oXFpKl4zDUgp9H5JDLK8k3kLd4Ti9K/2NU61ZkLcNbJ4VSTQyqGhWSoR2yVznv6fm4Lzu+ge1h51V0GYu22kabAG7xdisx9w7y2HM78QpuUXTqxZ4oRT6s8e3fhzqKxuKCiI7xF13FHRuVaKhi928NJnEX3D5YhCk5Lzh/cuiAzrR5OZ4w8mFeKV1CSgFDIgRgxzE8vltPDrXeGGXSRLgKgbpj0TtA+blkPvVsM7V5m+SZv4Yk3TWCfK3YPOvV40cI+QKoeWAqvJ5sUT4udlmN0eY/LVbPgxes8U26rLmEUBfXNtibEsWVsqwH2jElY7Y/PRaqrOzApEa1YzXSn1 root@Gitlab

[root@Gitlab my-web]# echo hello world >> file1

[root@Gitlab my-web]# git add .

[root@Gitlab my-web]# git commit -m "hello world"
[master 89ed69a] hello world
 1 file changed, 1 insertion(+)
 create mode 100644 file1
 
[root@Gitlab my-web]# git remote remove origin    #Delete locally specified remote push address

[root@Gitlab my-web]# git remote -v    #See which remote addresses have been added locally

[root@Gitlab my-web]# git remote add origin git@gitlab.fzmyw.com:devops/my-web.git   #Add a new remote push address in SSH mode

[root@Gitlab my-web]# git remote -v
origin  git@gitlab.fzmyw.com:devops/my-web.git (fetch)
origin  git@gitlab.fzmyw.com:devops/my-web.git (push)

[root@Gitlab my-web]# git push origin master
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 272 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitlab.fzmyw.com:devops/my-web.git
   c2ff023..89ed69a  master -> master

be careful:

When using different Gitlab user code cloning links (i.e. using different Gitlab users), you need to add the SSH public key of the current end user to the SSH key configuration of the Gitlab to realize code cloning and push encryption free.



SSH push code (fzmyw user)

Example: use the fzmyw user on Gitlab to develop the code on the windows system, and use ssh to clone and submit the code.


That is, you need to add the SSH public key of the Administrator user on the Windows system to fzmyw the SSH key of the system settings on Gitlab.


Retest using fzmyw user clone to push code to Gitlab on Windows terminal


Successfully used fzmyw user password free to submit code to Gitlab on Windows!

Question:

Above, we use fzmyw users to modify and submit new codes to Gitlab on Windows, but the root user's local warehouse does not know that other users have submitted new codes. How can all users synchronously update the latest codes to the local warehouse?

The root user obtains the latest code to the local warehouse

[root@Gitlab ~]# cd my-web/

[root@Gitlab my-web]# ls
file1  README.md

[root@Gitlab my-web]# cat README.md
 my web project

[root@Gitlab my-web]# git pull origin master     #Get the latest code to the local warehouse
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
come from gitlab.fzmyw.com:devops/my-web
 * branch            master     -> FETCH_HEAD
 Update 89 ed69a..04bbcc6
Fast-forward
 README.md | 1 +
 1 file changed, 1 insertion(+)

[root@Gitlab my-web]# cat README.md
 my web project
fzmyw The user modified the code and submitted it

8.Gitlab new branch and merged branch

New branch

[root@Gitlab my-web]# pwd
/root/my-web

[root@Gitlab my-web]# ls
file1  README.md

[root@Gitlab my-web]# git branch   #List branches
* master

[root@Gitlab my-web]# git branch new_fenzhi   #Create new_fenzhi branch

[root@Gitlab my-web]# git branch   #List all branches
* master
  new_fenzhi
  
[root@Gitlab my-web]# git checkout new_fenzhi    #Switch branch to new_ On Fenzhi branch
 Switch to branch 'new_fenzhi'

[root@Gitlab my-web]# ls
file1  README.md

[root@Gitlab my-web]# echo This is a new branch >> newfile   #In New_ Creating files on the Fenzhi branch

[root@Gitlab my-web]# ls
file1  newfile  README.md

[root@Gitlab my-web]# git add .    #Submit code to staging area

[root@Gitlab my-web]# git commit -m "New branch file newfile"   #Submit staging area code to local warehouse
[new_fenzhi dd6071e] New branch file newfile
 1 file changed, 1 insertion(+)
 create mode 100644 newfile
 
[root@Gitlab my-web]# git push origin master   #Push the code to the master branch (because you just created a new branch and switched to the new branch, the locally submitted code files are all in the new branch and need to be pushed to the remote new branch instead of the master branch)
Everything up-to-date    #It's already the latest

[root@Gitlab my-web]# git push origin new_fenzhi   #Push new_ All code on the Fenzhi branch to remote New_ On branch
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 348 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: To create a merge request for new_fenzhi, visit:
remote:   http://gitlab.fzmyw.com/devops/my-web/merge_requests/new?merge_request%5Bsource_branch%5D=new_fenzhi
remote:
To git@gitlab.fzmyw.com:devops/my-web.git
 * [new branch]      new_fenzhi -> new_fenzhi


Merge branch

We created a new branch new on it_ Fenzhi, and the code file is created in the new branch and submitted to the remote warehouse, but the code submitted above only belongs to new_ In the Fenzhi branch, if new_ Should the code on the Fenzhi branch be merged into the master branch

[root@Gitlab my-web]# git branch   #List branches
  master
* new_fenzhi

[root@Gitlab my-web]# ls
file1  newfile  README.md

[root@Gitlab my-web]# git merge master    #In New_ Merge master on Fenzhi branch
Already up-to-date.

[root@Gitlab my-web]# git checkout master   #Switch to the master branch
 Switch to branch 'master'

[root@Gitlab my-web]# git branch
* master
  new_fenzhi
  
[root@Gitlab my-web]# git merge new_fenzhi   #New_ Merge Fenzhi branch to master branch
 Update 04 bbcc6..dd6071e
Fast-forward
 newfile | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 newfile
 
[root@Gitlab my-web]# git push origin master    #Push code to remote master branch
Total 0 (delta 0), reused 0 (delta 0)
To git@gitlab.fzmyw.com:devops/my-web.git
   04bbcc6..dd6071e  master -> master


9. Use of gitlab's Tag tag (version)

[root@Gitlab my-web]# git branch
* master
  new_fenzhi
  
[root@Gitlab my-web]# ls
file1  newfile  README.md

[root@Gitlab my-web]# git tag -a "v1.0" -m "new tag"   #Label all codes on the current master branch as v1 0 (can be regarded as a version)

[root@Gitlab my-web]# git tag   #View all labels
v1.0

[root@Gitlab my-web]# git push origin v1.0   #Push tag v1 0 to remote warehouse
Counting objects: 1, done.
Writing objects: 100% (1/1), 147 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@gitlab.fzmyw.com:devops/my-web.git
 * [new tag]         v1.0 -> v1.0


After modifying the code, submit a new version tag

[root@Gitlab my-web]# git branch
* master
  new_fenzhi
  
[root@Gitlab my-web]# ls
file1  newfile  README.md

[root@Gitlab my-web]# echo fixed some bug s and released a new version > > readme md

[root@Gitlab my-web]# cat README.md
 my web project
fzmyw The user modified the code and submitted it
 Modified some bug,And release a new version

[root@Gitlab my-web]# git add .

[root@Gitlab my-web]# git commit -m "fixed some bug s and released a new version"
[master e179435] Modified some bug,And release a new version
 1 file changed, 1 insertion(+)
 
[root@Gitlab my-web]# git push origin master
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 440 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@gitlab.fzmyw.com:devops/my-web.git
   dd6071e..e179435  master -> master
   
[root@Gitlab my-web]# git tag -a "v2.0" -m "v2.0 New version"   #Submit a new tag as v2 0

[root@Gitlab my-web]# git tag
v1.0
v2.0

[root@Gitlab my-web]# git push origin v2.0   #Push new label (version) v2 0 to remote warehouse
Counting objects: 1, done.
Writing objects: 100% (1/1), 161 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To git@gitlab.fzmyw.com:devops/my-web.git
 * [new tag]         v2.0 -> v2.0


10. Backup, recovery and upgrade of gitlab

Gitlab backup

1. Modify the directory of the default backup site, and then reload the configuration file.

[root@Gitlab ~]# vim /etc/gitlab/gitlab.rb
...
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups"   #Backup path modification (the space of the path should be large enough)
...
gitlab_rails['backup_keep_time'] = 604800    #Backup retention for 7 days
...

[root@Gitlab ~]# gitlab-ctl reconfigure    #Reload gitlab configuration file

2. Manually executing the backup command will store the backup results in the / data/gitlab/backups directory.

[root@Gitlab ~]# gitLab-rake gitlab:backup:create

3. Of course, you can also write the backup command to the scheduled task for automatic backup every day.

[root@Gitlab ~]# crontab -l
00 02 * * * /usr/bin/gitlab-rake gitlab:backup:create

4. View backup files

[ root@Gitlab ~]# ls /data/gitlab/backups/
1566120123_2022_03_07_12.0.3_gitlab_backup.tar

Gitlab recovery

1. Stop data writing service

[root@Gitlab ~]# gitlab-ctl stop unicorn
[root@Gitlab ~]# gitlab-ctL stop sidekiq

2. Restore through gitlab rake command. When restoring, you need to specify the name of the previous backup (the file only needs to be written to the timestamp (1566120123_2022_03_07_12.0.3), and there is no need to write_ gitlab_backup and tar suffix)

[root@Gitlab ~]# gitlab-rake gitlab:backup:restore BACKUP=1566120123_2022_03_07_12.0.3
Before restoring the detabase, we will remove all existing tables to avoid future: upgrade problems. Be aware that if you have custom tables in the 6itLab database these tables and all data will beremoved.

Do you want to continue (yes/no) ?  yes #Enter yes

3. Restart gitlab and check whether it is restored

[root@Gitlab ~]# gitlab-ctL restart

Gitlab upgrade

1. Close gitlab service

[root@Gitlab ~]# gitlab-ctl stop unicorn

[root@Gitlab ~]# gitlab-ctl stop sidekiq

[root@Gitlab ~]# gitlab-ctl stop nginx

2. Backup gitlab

[root@Gitlab ~]# gitlab-rake gitlab:backup:create

3. Download the RPM package of gitlab and upgrade it

Tsinghua University source (gitlab CE community centos7 download): https://mirror.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

Download all versions of the Chinese package (select the tag version at gitlab in the upper part): https://gitlab.com/xhang/gitlab/-/tree/12-0-stable-zh

[root@Gitlab ~]# yum localinstall gitlab-ce-15.0.0-ce.0.el7.x86_64.rpm

4. Start and view gitlab version information

[root@Gitlab ~]# gitlab-ctl reconfigure

[root@Gitlab ~]# gitlab-ctl restart

[root@Gitlab ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 15.0.0

↓↓↓↓↓↓

Recently, I have applied for a WeChat official account. I will share some knowledge of operation and maintenance. Original public number: non famous operation and maintenance welfare: official account reply to "official account", send and transport operation and maintenance materials, and self study materials!

Topics: git GitLab