Continuously Integrated Gitlab Installation and Application

Keywords: Linux git GitLab RPM Nginx

Preface:

Gitlab is an open source application developed using Ruby on Rails that implements a self-hosted repository of Git projects that can be accessed through the Web interface from public or private projects. Gitlab has Github-like capabilities to browse source code, manage defects and comments.Can manage team access to the repository, he is very easy to browse submitted versions and provides a file history library.He also provides a code snippet collection function that makes code reuse easy to find when needed in the future

Blog Outline:
1. Environmental Preparation
2. Install and deploy gitlab
3. Basic operation of remote repository
4. Reset gitlab administrator password

1. Environmental Preparation

If it is a test environment, its memory recommendation is 2G or more, you can go to Tsinghua Open Source Mirror Station Download the required gitlab version, and after installation, nginx will automatically be installed to provide the web interface, so avoid port 80 usage.

2. Install and deploy gitlab

1. Install gitlab

[root@git src]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.9.8-ce.0.el7.x86_64.rpm
[root@git ~]# rpm -ivh gitlab-ce-11.9.8-ce.0.el7.x86_64.rpm   #Install rpm package
[root@git ~]# gitlab-ctl reconfigure    #Reconfigure gitlab
#Since I am not going to do domain name resolution, I need to modify its configuration file
[root@git ~]# vim /etc/gitlab/gitlab.rb 
external_url 'http://192.168.20.2'#Change the original domain name to local IP
[root@git ~]# gitlab-ctl reconfigure    #Reconfigure gitlab again
[root@git ~]# netstat -anpt | grep -w 80      #Determine nginx is listening on port 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3872/nginx: master  

2. Configure gitlab

Client access to the IP address of the server, you can see the following interface (configure the password and log on):

Upload the server's public key (much the same as on github), first generate the key pair on the server:

[root@git ~]# ssh-keygen -t rsa -C "916551516@qq.com"
#Execute the above command to generate a secret key pair and return all the way, followed by your own mailbox
[root@git ~]# cat ~/.ssh/id_rsa.pub     #View the generated public key and copy its contents
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCVUbmw+PC2plXMviNBA6YKgWx+1419uMPJhJNGeZ8Mi7njBlAyhfzWQsCFamQqU4nwSMWua3oEJZEiT6ZRgLQQyYwZ+DESQCyhAJYdtOgwtRh3XaIgAASzlqZ0hIjhhwi+pD/GjktySiW/UvaiqkkBgfdXCuXlSH7R8T4PoRCpYZ92OwQmMV/blGd/SXLDCaqHlgz1K8As8HFoaFAkrmS+jSio616+w2o8ly2PBbVoZa129BD8SQ81KAs5drGTD2OsKHFx08rS5izSc2MKLjet7+00CXJebwZQLB1LS/TUXwrPAHLQO8ZN8AYCsoIv6coEYRhW93BoBZ8Swetys/KD 916551516@qq.com

Then back to the web interface:

Add it as follows:

Create a library:

Go back to the server and clone the library you just created:

[root@git ~]# git clone git@192.168.20.2:root/test01.git   #Clone
[root@git ~]# cd test01/      #Enter cloned Library
[root@git test01]# ls    #This directory is the same as what you just created when your web page created its library
README.md
#Self-report home
[root@git test01]# git config --global user.name "test"
[root@git test01]# git config --global user.email "test@test.com"
#Upload files to remote library for testing
[root@git test01]# echo "aaaaaaaaa" > test.txt
[root@git test01]# git add test.txt
[root@git test01]# git commit -m "alter from 192.168.20.2"
[root@git test01]# git push origin master    #Push to remote repository

Refresh the library page of the web interface:

3. Basic operation of remote repository

When you clone from a remote repository, git actually automatically maps the local master branch to the remote master branch, and the default name of the remote repository is origin.

To view information about remote libraries, use the following commands:

[root@git test01]# git remote    #Brief Information
origin
[root@git test01]# git remote -v    #detailed information
origin  git@192.168.20.2:root/test01.git (fetch)
origin  git@192.168.20.2:root/test01.git (push)

Push Branch:

[root@git test01]# git push origin master    #Push local master branch
[root@git test01]# git push origin dev    #Push the local dev branch, which is automatically created if there is no dev branch at the remote end

Grab Branches:

[root@git test01]# git pull origin dev      #Grab the remote dev branch as prompted

When we clone from a remote library, by default, only the master branch is visible and can be confirmed using the GIT branch command.

Solve problems that can arise when multiple people collaborate

When our entire team develops the same branch, if your colleague has modified the content of the branch and pushed it to a remote repository before you submitted it, and you happen to have made changes to the same file and tried to push it, the push will fail because your colleague's latest submitted data conflicts with the data you are trying to submit (your local content is farther away than your local content)End warehouse is old). The solution will be given in the return message that prompts you to fail the push. Here we will simulate this process.

#Enter another directory, clone a remote warehouse, simulate collaboration between multiple people
[root@git test01]# cd /tmp
[root@git tmp]# git clone git@192.168.20.2:root/test01.git
[root@git test01]# git checkout -b dev     #Create a branch dev and enter
[root@git test01]# echo "aaaaaaaaa" > tmp.txt
[root@git test01]# git add tmp.txt
[root@git test01]# git commit -m "commmit from /tmp"
[root@git test01]# git push origin dev        #Push newly modified content to remote

Return to the web interface and refresh to see the newly submitted branches:

If the above operation was performed in the / tmp directory, then now operate the remote warehouse in the / root directory:

#Enter the remote warehouse under the root directory and create dev branches to push content to the remote warehouse
[root@git test01]# cd /root/test01/
[root@git test01]# git checkout -b dev
[root@git test01]# echo "bbbbbbbbbb" > root.txt
[root@git test01]# git add root.txt
[root@git test01]# git commit -m "commit from /root"
[root@git test01]# git push origin dev        #At this point when we push, the following error will be prompted
To git@192.168.20.2:root/test01.git
 ! [rejected]        dev -> dev (fetch first)
error: Unable to push some references to 'git@192.168.20.2:root/test01.git'
//Tip: The update was rejected because the remote version library contains submissions that do not exist locally.This is usually due to the addition of
//Tip: A version library has already pushed the same reference.You may need to merge remote changes before pushing again
//Tip: (e.g.'git pull').
//Tip: See the'Note about fast-forwards'section in'git push--help' for details.
#Prompt that the remote repository has submissions that our local repository does not have, so we need to pull the remote repository down before submitting it

[root@git test01]# git pull origin dev      #pull down the remote dev branch as prompted
[root@git test01]# ls      #The files we submit in the / tmp directory already exist
README.md  root.txt  test.txt  tmp.txt
[root@git test01]# git push origin dev         #Then push the local dev branch to gitlab again to succeed

At this point, the dev branch of the web interface has everything we submit in the / tmp directory and / root directory, as follows:

But the master branch is still the original file, as follows:

Now branch merge the remote version libraries as follows:

[root@git test01]# git checkout master   #Switch to master branch
[root@git test01]# git merge dev     #Merge dev branches
[root@git test01]# ls    #View the contents under the merged branch
README.md  root.txt  test.txt  tmp.txt
#Submit to Local Version Library
[root@git test01]# git pull    #Download Remote Version Library
[root@git test01]# git add *
[root@git test01]# Git commit-m "submit"
[master 3717c1c] Submit
[root@git test01]# git push origin master     #Push to remote repository

Now the master branch of the remote version library is as follows:

Now that you have all the contents of the dev branch, let's show you how to delete the dev branch from a remote version library:

[root@git test01]# git branch -d dev   #Delete local dev branch
[root@git test01]# git branch -r -d origin/dev     #Delete the specified remote branch 
[root@git test01]# git push origin :dev         #Submit deleted branches to a remote version Library

At this point, the dev branch in the remote repository has been deleted, as follows:

4. Reset gitlab administrator password

[root@git ~]# gitlab-rails console production     #To execute the command, only the first command word can be tab bed out
-------------------------------------------------------------------------------------
 GitLab:       11.9.8 (48528bc)
 GitLab Shell: 8.7.1
 postgresql:   9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.1)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):003:0> user.password='test1234'
=> "test1234"
irb(main):004:0> user.password_confirmation='test1234'
=> "test1234"
irb(main):005:0> user.save
Enqueued ActionMailer::DeliveryJob (Job ID: 17d6f678-3cae-4de2-be59-b19a6d22b9fa) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f895034e280 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
irb(main):006:0> true
=> true
irb(main):007:0> exit

At this point, to log in again, you need to log in with the new password test1234.

Posted by Alphamonkey on Thu, 14 Nov 2019 11:33:31 -0800