Gitlab service deployment and application

Stage 4

Time: August 21, 2023

Participants: All members of the class

Contents:

Gitlab service deployment and application

Table of contents

1. Introduction to Gitlab

2. Gitlab working principle

3. Gitlab service composition

4. Advantages of Gitlab

5. Gitlab environment deployment

(1) Installation and deployment

(2) Web operations:

(3) Test:


1. Introduction to Gitlab

        Gitlab is a WEB code warehouse hosting software based on Git. You can use Gitlab to build a code warehouse similar to Github. Generally, using gitlab to build a private code warehouse is mainly used for the company's internal code management.

        The function of Gitlab is to review code submissions and track issues, which is crucial for the management of software engineering (code) quality.

        Gitlab is divided into Community Edition (CE) and Enterprise Edition (EE). Most companies will still choose the community version. Deployment of GitLab requires server configuration. It is recommended that the server has two cores and 4G of memory.

2. Working principle of Gitlab

The principle of gitlab is actually the working principle of git. GitHub is also implemented based on git.

 

Remote remote warehouse:

        The contents of the remote repository may be modified by local repositories in collaborative relationships distributed in multiple locations, so it may or may not be synchronized with the local repository, but its content is the oldest.

Repository local warehouse:

        Each version of the submitted code is saved here. Compared with the contents of the workspace and staging area, its content will be older. After git commit, the directory tree of the index is synchronized to the local warehouse, which is convenient for the next step to synchronize the local through git push. Synchronization of warehouse and remote warehouse.

index temporary storage area:

        For the index file in the git directory, the temporary storage area will record the relevant information (file name, size) of the file added by git add. The file entity will not be saved. The entity of each file is pointed to by id. You can use git status to view the status of the temporary storage area. , the staging area marks which content in your current workspace is managed by git. When you need to submit code after completing a certain requirement or function, the first step is to submit it to the staging area through git add.

workspace workspace:

        The place where programmers make development changes is what you see now, and the content is also the latest. Usually when we develop, we copy the branch in the remote warehouse and develop based on the branch. The development process is performed in the workspace.

Summarize:

Any object is born and modified in the workspace;

Any modifications are version controlled only after entering the index area;

Only by submitting the modified code to the local warehouse can the modification leave traces in the warehouse;

Share local modifications with facilitators and push them to remote repositories for sharing;

 

3. Gitlab service composition

Nginx: static web server

gitlab-shell: used to process Git commands and modify the authorized keys list

gitlab-workhorse: lightweight reverse proxy server (this is an agile reverse proxy, it will handle some large HTTP requests, such as file upload and download, and other requests will be reverse-proxyed to Gitlab Rails applications)

logrotate: log file management tool

postgresql: database

redis: cache database

sidekiq: used to execute queued tasks in the background

unicorn: Gitlab Rails application is hosted on this server

4. Advantages of Gitlab

git is distributed, svn is not

        You can use git distributed locally, and you can save various historical traces at will. You don't have to worry about contaminating the server. You can submit code and view logs even if you can't connect to the server.

GIT branches are different from SVN branches

        A branch in SVN is actually a copy of the repository, while a git warehouse is a snapshot, so operations such as git switching and merging branches are faster.

git has a powerful code warehouse management system – gitlab

You can easily manage permissions, code review, create and manage projects

5. Gitlab environment deployment

(1) Installation and deployment

1. Host name setting

[root@localhost ~]# hostname gitlab

[root@localhost ~]# bash

 

2. Install dependency packages

[root@gitlab ~]# yum -y install curl openssh-server openssh-clients postfix cronie policycoreutils-python

 

3. Start postfix and set it to start automatically at boot.

[root@gitlab ~]# systemctl start postfix

[root@gitlab ~]# systemctl enable postfix

 

 

4. Set up firewall

[root@gitlab ~]# systemctl stop firewalld

[root@gitlab ~]# iptables -F

[root@gitlab ~]# setenforce 0

 

5. Download and install the gitlab rpm package

Tsinghua Open Source Mirror Station: Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

[root@gitlab ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-11.11.3-ce.0.el7.x86_64.rpm

[root@gitlab ~]# rpm -ivh gitlab-ce-11.11.3-ce.0.el7.x86_64.rpm

 

6. Modify the configuration file /etc/gitlab/gitlab.rb. It can be modified as needed in a production environment.

[root@gitlab ~]# vim /etc/gitlab/gitlab.rb

  13 external_url 'http://192.168.200.111'

 

7. Reload the configuration file

[root@gitlab ~]# gitlab-ctl reconfigure

[root@gitlab ~]# gitlab-ctl restart

[root@gitlab ~]# netstat -lnpt | grep :80

Start: gitlib-ctl start Shut down: gitlab-ctl stop

Restart: gitlab-ctl restart

Reload configuration: gitlab-ctl reconfigure

View status: gitlab-ctl status

8. Check the gitlab version

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

 

(2) Web operations:

1. Log in to GitLab with a browser and enter http://192.168.100.131

enter password

 

2. The password requires eight digits

 

3. Login: root, 12345678

 

4. After successful login, you can enter the GitLab homepage

 

5. Create a new project

 

6. Create names and permissions

 

7. Add readme

 

8. Create test content: It's gitlab test, then click the green button to add

 

 

(3) Test:

1. Client test:

[root@localhost ~]# hostname jenkins

[root@localhost ~]# bash

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

[root@jenkins ~]# git config --global user.email "[email protected]"

[root@jenkins ~]# git config --global color.ui true

[root@jenkins ~]# git config --list

[root@jenkins ~]# git clone http://192.168.200.111/root/huyang.git

[root@jenkins ~]# ls huyang/

[root@jenkins ~]# cat huyang/README.md 

 

Add content testing:

 

Get: (delete the previous content and clone again)

 

2. Set up the email function

1) Modify configuration file

[root@gitlab ~]# vim /etc/gitlab/gitlab.rb

 

2) #Modify the sender of gitlab configuration

3) Reload the configuration and restart the service

[root@gitlab ~]# gitlab-ctl reconfigure

[root@gitlab ~]# gitlab-ctl restart

 

4) Test email:

[root@gitlab ~]# gitlab-rails console -e production

irb(main):001:0> Notify.test_email('[email protected]', 'Message Subject', 'Message Body').deliver_now

 

Email notification:

 

5) Set up email on the web and send email reminders!

 

Email notification

 

Guess you like

Origin blog.csdn.net/2302_77582029/article/details/132414869