gitlab + jenkins automated deployment

Based gitlab and automated deployment jenkins

 

Gitlab deployment tutorial is based on Jenkins automation:

https://blog.csdn.net/aaaaaab_/article/details/82012044

https://www.cnblogs.com/dengbingbing/p/10448185.html

 

GitLab is a code repository used to manage code.

Jenkins is an automated server, you can run a variety of automated build, test or deployment tasks. So these two together, you can achieve the developers submit code to GitLab, Jenkins to run automatically at a certain frequency test, build and deploy mission to help development teams more efficient integration and release code.

A, gitlab Introduction

GitLab: is a software-based online code repository hosted Git achieve, you can use gitlab built himself a similar Github same system, generally used in businesses, schools and other internal network build git PW.
Function: gitlab is to provide a code hosting, management platforms commit code review and issue tracking. Very important for the quality of software engineering management.
Version: gitlab into Community Edition (CE) and Enterprise Edition (EE).
Configuration: It is recommended CPU2 core, memory, 2G or more.

Two, gitlab service components:

Nginx: static web server.
gitlab-shell: Git commands for processing and modifying the list of authorized keys. (Ruby)
gitlab-Workhorse: lightweight reverse proxy server. (Go)

GitLab Workhorse is a quick reverse proxy. It will deal with a number of large HTTP requests, such as file upload, file download, Git push / pull and Git package download. Other requests to the reverse proxy GitLab Rails application, i.e., the rear end of the reverse proxy to unicorn.

logrotate: log file management tools.
postgresql: database.
redis: Cache database.
sidekiq: queue for execution tasks in the background (asynchronous execution). (Ruby)
Unicorn: An HTTP Server for Rack Applications, gitlab Rails applications are hosted on this server above. (Ruby Web Server, mainly written in Ruby)

Three, gitlab installation configuration

1, the installation-dependent:

yum install curl policycoreutils openssh-server openssh-clients postfix

 

2, check the service status to ensure open:

systemctl status postfix.service

 

3, mounting kit:

yum install -y net-tools

 

4, download and install gitlab:

gitlab open source software mirror sites:

https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

 

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.5.3-ce.0.el7.x86_64.rpm

 

 

rpm -ivh gitlab-ce-12.5.3-ce.0.el7.x86_64.rpm

 

yum install policycoreutils-python

 

The installation again: RPM -ivh gitlab-ce-12.5.3-ce.0.el7.x86_64.rpm

 

5, edit the configuration file is written to the current host IP (Note: The following can be edited together 8):

vim /etc/gitlab/gitlab.rb

 

6, initialization gitlab: gitlab-ctl reconfigure

 

7, heavy-duty service: gitlab-ctl restart

 

8, modify gitlab repository path:

Creating / data / gitlab directory

mkdir -p /data/gitlab

Modify gitlab profile

vim /etc/gitlab/gitlab.rb

In adding the path inside git_data_dir "/ data / gitlab" (Note: this removes the # sign)

 

Stop the current gitlab, reload the configuration

gitlab-ctl stop

 

gitlab-ctl reconfigure

 

After reload, you will find in the under / data / gitlab directory more than a directory repositories

 

Finally, start gitlab to

gitlab-ctl start

9, enter in your browser IP address to verify whether the installation is successful, another 8-digit password:

(I have here is admin123456 )

 

10, set user passwords: root, admin123456

 

Landed successfully:

 

11, create a new project:

 

 

12, the configuration gitlab Free tight connection:

( 1) Prerequisite: must have a code repository, and then create a branch in the warehouse and create a file that already exists here

( 2) Next, a configuration to obtain the public key to the ssh gitlab, in order to simulate the development of the code uploaded gitlab

Using ssh-keygen to generate private and public keys: (rsa encryption algorithm generation)

ssh-keygen -t rsa -C [email protected]

It should be: three carriage returns

 

 

View Public Key: CAT id_rsa.pub

 

The public key into the key column, so you can use ssh way to upload code:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDKt4gqFEGve5I9m7S+j5Rtd78h3EsaUkHEJcuVjVEQrMmmQbbHOX7ZVPcm6+oBiWi31tB7OMajNg+qSELg8fYECDePLLeBwrPUuMLt7k7nJZ/YmbZ241d2h8zTPZ+xyQ9NPfatWzr6NpjdCXjrMz9+8w4BiCAdXIC2lVr0Aef50gpgaRwy18CZrV8P/qynv8N2r/zGge6xKgbTr11AVCp2SEkEI5E1NpyxBEyrj32/LWOODZ84NSLF8SYlbMIE12xwo+ueVmhhQSB6XryrsF5AYGcESICHmvzMO76JSGnQPwmxyPZa2d44cOMOj2HNB0m2I2P7dDTJ37eFWzZzSU8h

 

 

 

13, clone code repository, and then test whether you can upload code to the gitlab:

git clone [email protected]: root / wyl.git

 

 

Modify text, submitted to the gitlab point of view can sync up:

 

git add README.md  submitted to the staging area

git commit -m "add README.md"  submitted directly

 

git config --global user.email [email protected]

git config --global user.name root

git commit -m "add README.md"

git push

Here is submitted to gitlab a text prepared by the shell:

echo 123456 > rc.txt

git add .

git commit -m "rc.txt"

git push

 

 

 

 

Here gitlab on configuration.

 

Four, Jenkins introduced

1. What Jenkins that?   

 Jenkins is a scalable continuous integration engine.

2, is mainly used for:    

Continuous, automatic build / testing software projects.     

Some of the tasks performed by regular monitoring.

3, Jenkins has features include:    

Easy to install - just jenkins.war deployed to a servlet container, no database support.     

Easy to configure - all its configurations are achieved by providing a web interface.     

Integrated RSS / E-mail or publish RSS construct results when the build is complete notification by e-mail.     

Generate JUnit / TestNG test report.     

Distributed build support for Jenkins to allow multiple computers to build / test together.     

File identification : Jenkins can keep track of which build times which generated jar, which once constructed which version of the jar and so on.     

Plug-in support : supports extensions, you can develop the tools for their own teams.

4, Jenkins install deployment (four ways follow-up will be written):    

(1) Download war package jenkins.war deployed to the servlet container, such as tomcat, Download https://jenkins.io/download    

(2) Download war package using the command directly run the war package, java -jar jenkins.war    

(3) windows download extract the zip package can be installed to run jenkins.exe windows service    

(4) Download rpm package and configure the service in linux

Five, Jenkins installation configuration

Tutorial: https://blog.csdn.net/xishaoguo/article/details/88577459

1. Download Jenkins package: https://jenkins.io/zh/download/

 

 

wget https://pkg.jenkins.io/redhat-stable/jenkins-2.190.3-1.1.noarch.rpm

 

If the download speed is too slow here, you can also use direct upload rz locally.

2, installation Jenkins:

sudo rpm -ih jenkins-2.190.3-1.1.noarch.rpm

 

After completion of the automatic installation:

/usr/lib/jenkins/jenkins.war WAR package

/ Etc / sysconfig / jenkins profile

/ Var / lib / jenkins / default directory JENKINS_HOME

/var/log/jenkins/jenkins.log Jenkins log file

3、启动Jenkins:sudo service jenkins start

 

Solution: Modify java path to

find / -name jenkins

 

cd /etc/rc.d/init.d/

 

vim jenkins

 

The figure is the default path, modifying native java path, one step to the following diagram:

 

sudo service jenkins start

systemctl daemon-reload            prompted to: be re new loading unit

 

service jenkins start

service jenkins stop service to stop Jenkins

service jenkins restart    to restart Jenkins services

 

Here, if a firewall is not turned off, you must first shut down, restart jenkins: systemctl stop firewalld.service

Check whether Jenkins normal operation, the following figure represents is not running: systemctl status jenkins

 

Modify Jenkins port number: vim / etc / sysconfig / jenkins

 

service jenkins start

systemctl status jenkins

 

Browser validation fails, as shown below:

 

Many people say gitlab is accounted for memory, 2G memory do I have occupied all? Then use the free command looked at :

free -h

 

I found my memory got left to run 77M, so he stopped gitlab:

gitlab-ctl  stop

 

Check the memory is available again: as Free -h

 

You should then start again Jenkins:

service jenkins start

systemctl status jenkins

 

Again in the browser to verify, as shown for success: 192.168.5.11:8082

 

4, page layouts Jenkins:

Get tips initialization code in a virtual machine based on: CAT / var / lib / Jenkins / Secrets / initialAdminPassword

 

Copy and paste into it, the next step:

52b6aedc282f4e2ea322a2d563c95a16

 

 

Here automatically install the plugin, click to retry the installation fails, but sometimes because the network reasons can skip this step:

 

Create an administrator user, saving is complete:

 

 

 

Here Jenkins installation is complete it.

5, due to the above plug-in fails to load, you need to log back in here, and then install the required plug Jenkins:

 

My Jenkins plugins above is not successfully installed, reinstall here, click on the System Management - Plugin Manager - Search - check the installation can be:

You need to install plug-ins: gitlab Hook, Build the Authorization Token Root, Publish Over SSH, gitlab Authentication, gitlab, the Parameter Git , Maven Integration plugin

 

 

 

 

Plug-in installation fails, there are two reasons:

1, request times out, the network can re-install the normal time;

2, no dependency installation package installation.

If Jenkins multiple installations will not need another way to solve:

https://blog.csdn.net/KingBoyWorld/article/details/77923615

Jenkins plug-Download:

http://updates.jenkins-ci.org/download/plugins/

Below, have the desired plug-in installed:

 

6, add up the plugin restart jenkins, start adding to deploy the host code, notice must be able to pass user ssh landing .

Add a host: System Management - the system settings to find settings for Free Publish over SSH density can, as shown below:

 

After setting up the test error:

 

This is due to the server sshd service is not due to open, log on to execute commands on the server :

sudo service sshd start // open sshd service

Copy the public key to the authorized_keys file , the user earlier findings [email protected] is added to it, as shown below:

cat id_rsa.pub >> authorized_keys

 chmod 600 authorized_keys

 

 

7, system management ---> Global Configuration Tool

Modify maven default settings.xml file, configure git, jdk, after saving tool maven (uncheck automatic installation)

 

Git pressed down configuration shown in FIG Environment:

 

8, Jenkins created a job:

 

Enter a project name, project to build a free style:

 

The following is a Git configuration:

 

 

 

Construction of triggers:

http://192.168.5.11:8082/project/testwyl

The URL will be arranged gitlab will be used, as shown by a regular expression WebBook security token generated gitlab ef04574b270a8be397af2c7789493f8d (each new generation of both)

 

 

 

The current code is deployed to the directory, and then restart the service, as shown below:

 

 

Configuration gitlab:

 

Cancel ssl check, because we did not configure https in Jenkins, and finally click increase web hook

 

 

Error here because of the use of the latest version of gitlab, because the new version of gitlab for security is disabled by default LAN address local calls web hook, we allow on the line in the settings, follow these steps:

 

Add again web hook, and then test, the following figure shows the configuration is successful:

 

 

Below, a recording test were 3:

 

9, test whether the code will be submitted to deploy to the remote host:

git clone [email protected]: root / wyl.git

festival cd /

echo 'Test Jenkins'> index.html

git add .

git commit -m 'add index.html'

git push

After submitting to jenkins page to see #

 

The following figure is to build a successful project:

Guess you like

Origin www.cnblogs.com/wyl-520/p/12149758.html