Install the Docker

  1. Download the repO of Docker-CE
curl https://download.docker.com/linux/centos/docker-ce.repo -o /etc/yum.repos.d/docker-ce.repo

Copy the code
  1. Install dependencies
Yum install https://download.docker.com/linux/fedora/30/x86_64/stable/Packages/containerd.io-1.2.6-3.3.fc30.x86_64.rpm

Copy the code

Ps: Containerd version is too late to install Containerd docker

  1. Install the docker – ce
yum install docker-ce

Copy the code
  1. Start the docker
systemctl start docker

Copy the code
  1. Setting domestic source
"registry-mirrors": [

 "https://1nj0zren.mirror.aliyuncs.com"."https://docker.mirrors.ustc.edu.cn".

    "http://f1361db2.m.daocloud.io"."https://registry.docker-cn.com"]

Copy the code
  1. restart
sudo systemctl daemon-reload

sudo systemctl restart docker

Copy the code

Install the Portainer

Introduction of a docker visual interface Portainer, you can easily view the start delete stop container, also can manage images

docker pull portainer/portainer

docker run -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -d portainer/portainer

Copy the code
Portainer interface. PNG

Install Jenkins

docker pull jenkinsci/blueocean



docker run -d --name jenkins -p 9001:8080 -p 50000:50000 --env PATH = / usr/share/maven/bin: / usr/local/sbin, / usr/local/bin: / usr/sbin, / usr/bin, / sbin, / bin: / usr/lib/JVM/Java - 1.8 - its/jre / bin: / usr/lib/JVM/Java - 1.8 - its/bin - v/var/run/docker. The sock: / var/run/docker. The sock - v /dockerworkspace/jenkins:/var/jenkins_home -v /opt/maven:/usr/share/maven -v /etc/localtime:/etc/localtime jenkinsci/blueocean

Copy the code

Ps:

  1. Jenkins plug-in mirror address https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json, tsinghua university

  2. May appear java.net.UnknownHostException, troubled me for a long time, baidu search out answers are unreliable. I read an article that said it might be the firewall. Turn off the firewall and restart immediately. The pit!

Systemctl Status firewalld.service Displays the firewall status

Systemctl stop firewalld. Service Run the command to stop running the firewall

Systemctl disable firewalld.service Disables automatic firewall startup

Copy the code

Firewall start and start commands:

A. start:

systemctl start firewalld.service

Copy the code

B. The firewall starts with the system:

systemctl enable firewalld.service

Copy the code
  1. Error:
Touch: cannot touch '/var/jenkins_home/copy_reference_file.log' : Permission denied

Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

Copy the code

You need to change the directory permissions, because when mapping local data volumes, the owner of the /home/docker-Jenkins directory is user root, and the UID of Jenkins user in the container is 1000

sudo chown -R 1000:1000 /dockerworkspace/jenkins

Copy the code
  1. Port 8080 is the Jenkins port, and port 5000 is the master and slave communication port
  2. Jenkin calls Docker without permission
chmod 666 /var/run/docker.sock

Copy the code
  1. clock of the subversion server appears to be out of sync. This can result in inconsistent check out behavior. svn Add @HEAD to the end of the URL

Install Maven

  1. download
Wget HTTP: / / http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

Copy the code
  1. Unpack the
tar xf /tmp/apache-maven-*.tar.gz -C /opt

Copy the code
  1. Set the environment variable (Jenkins of DockerHub is used here, so it can be omitted)
nano /etc/profile.d/maven.sh

Copy the code

Paste the following code:

Export JAVA_HOME = / usr/lib/JVM/Java - 1.8 - its



export MAVEN_HOME=/usr/opt/maven



export PATH=${MAVEN_HOME}/bin:${PATH}

Copy the code

For better control of Maven versions and updates, we will create a symbolic link, Maven, that points to the Maven installation directory:

Ln -s/opt/apache maven - 3.6.3 / opt/maven

Copy the code

Make the script executable by running the following chmod command

chmod +x /etc/profile.d/maven.sh

Copy the code

Load environment variables using the following source command:

source /etc/profile.d/maven.sh

Copy the code
  1. Build the Maven multi-module project

    Configure a Maven-style project and then configure it

    The root POM points to the top-level pom.xml

mvn clean install -pl ETECSA-SERVER/ETECSA-SERVER-EUREKA -am -amd -Dmaven.test.skip=true

Copy the code

This way, the Etecsa-server-Eureka jar is built separately, and the dependencies are built without having to put them into maven’s repository ahead of time

According to the information:

parameter The full name paraphrase instructions
-pl –projects Build specified reactor projects instead of all projects Options can be followed by {groupId}:{artifactId} or the relative path of the selected module (multiple modules separated by commas)
-am –also-make If project list is specified, also build projects required by the list Represents the module on which the selected module depends
– amd –also-make-dependents If project list is specified, also build projects that depend on projects on the list Represents simultaneous processing of modules that depend on the selected module
-N –Non-recursive Build projects without recursive Represents a non-recursive submodule
-rf –resume-from Resume reactor from specified project Indicates that processing continues from the specified module

Ps:

Permission denied exceptions

Solutions:

Add Jenkins user to docker group and restart Jenkins service

sudo gpasswd -a jenkins docker

sudo systemctl jenkins restart

Copy the code

Build a private mirror warehouse Harbor

  1. download
wget -P /workspace/harbor/     https://github.com/vmware/harbor/releases/download/v1.10.2/harbor-online-installer-v1.10.2.tgz

Copy the code
  1. Unpack the
Tar ZXF harbor - online - installer - v1.10.2. TGZ

Copy the code
  1. Example Modify the configuration file to harbor. Yml

  2. Enter the harbor directory and run the script

./install.sh

Copy the code
  1. Install the docker – compose
The curl - L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname - s) - $(uname -m)" - o /usr/local/bin/docker-compose

Copy the code
  1. For docker-compose, run the following command:
chmod +x /usr/local/bin/docker-compose

Copy the code
  1. Test uploading and downloading images and modify the configuration of each Docker Client
nano /etc/docker/daemon.json

Copy the code
"insecure-registries": ["10.1.20.16:9002"]

Copy the code

Example Jenkins Pipe script (pull SVN code build image push to image repository)

def getHost(){

   def remote = [:]

    remote.name = 'test'

    remote.host = '10.1.20.16'

    remote.user = 'root'

    remote.password = '* * * * * *'

    remote.allowAnyHosts = true

    return remote

}



def imageName="10.1.20.16:9002 / hn/demo: v1.0.0"

def prjName="demo"



pipeline {

    agent any

    

    environment{

        def server = ' '

    }   



    stages {

        stage('init-server') {

            steps {

                script {                 

                   server = getHost()                                   

                }

            }

        }

        

        stage('Build') {

         steps {

               echo 'Pull code'

               checkout([$class: 'SubversionSCM'.additionalCredentials:[].excludedCommitMessages: ' '.excludedRegions: ' '.excludedRevprop: ' '.excludedUsers: ' '.filterChangelog: false.ignoreDirPropChanges: false.includedRegions: ' '.locations: [[cancelProcessOnExternalsFail: true.credentialsId: '2d3c4a0b-1bba-4690-b208-3a511fc4f415'.depthOption: 'infinity'.ignoreExternalsOption: true.local: '. '.remote: 'SVN: / / 10.1.80.111 / ETECSA - SERVER']], quietOperation: true.workspaceUpdater: [$class: 'UpdateUpdater']])

               withMaven(maven: 'maven'.mavenSettingsConfig: '3f3f6844-0644-48a3-8c4f-cef8f4e75196') {

                   sh label: ' '.script: 'mvn clean install -pl ETECSA-SERVER-EUREKA -amd -Dmaven.test.skip=true'

                }

            }

        }



        stage('DockerBuild') {

            steps {

                dir ("ETECSA-SERVER-EUREKA/") {

                    script {

                        def image = docker.build("Hn/demo: v1.0.0")

                            docker.withRegistry("http://10.1.20.16:9002".'67bbae3e-a0da-4c30-9357-eec4a146cc2e') {

                            image.push()

                        }  

                    }

                }

            }

        }

        

        stage('use') {

            steps {

                script {

                  sshCommand remote: server, command: "" "

                    if [ \$(docker ps -a | grep -i $imageName | wc -l) -eq 1 ]; then 

                        sudo docker stop $prjName 

                        sudo docker rm -v -f $prjName

                    fi 

                    if [ \$(docker images | grep -i $imageName | wc -l) -eq 1 ]; then

                        sudo docker rmi -f $imageName

                    else 

                        sudo docker run -p 8761:8761 --name $prjName -d $imageName

                    fi

"" "


                }

            }

        }

        

       stage('clean') {

            steps{

               sh label: ' '.script: ' ' '

echo \' >>> [INFO] cleaning ... \ '

Docker rmi -f hn/demo: v1.0.0

Docker rmi -f 10.1.20.16:9002 / hn/demo: v1.0.0 ' ' '


            }

            

        }

    }

}

Copy the code

The Jenkins build log is as follows

jenkin-build.png

Other manual deployment modes

  1. Docker-compose deployment service

There are three ways: webEditor, upload docker-compose file, git repository to get docker-compose

portainer-stack.png

Click the deployment

  1. Docker container deployment
portainer-containers.png
  1. Command line deployment
Docker run - p - 8761-8761 the name demo - d 10.1.20.16:9002 / hn/demo: v1.0.0

Copy the code

Solution to VM IP address change

Into the/etc/sysconfig/network – scripts

Change BOOTPROTO= DHCP to static in the ifcfg-ens33 ifcfg-ENO16777736 file

And add at the end:

DNS1 = 114.114.114.114 - DNS address



IPADDR=192.168.49.128 -- Specifies the IP address to be set



NETMASK=255.255.255.0 indicates the subnet mask



GATEWAY = 192.168.49.1 - a GATEWAY



nmcli c reload

Copy the code