1. Deployment architecture diagram

2. Jenkins installation

2.1 Creating a Jenkins installation directory

mkdir -p /usr/local/docker/jenkins
cd /usr/local/docker/jenkins
touch install.sh
chmod 777 install.sh
Copy the code

2.2 Creating the install.sh script file

#! /bin/bashEcho "step 1 - > create Jenkins mounted directory -- -- -- -- -- -" the mkdir -p/usr/local/docker/Jenkins jenkins_home chmod 777 / usr/local/docker/Jenkins jenkins_home echo "step 2 - > create docker - compose. Yaml template file -- -- -- -- -- -" CD/usr/local/docker/Jenkins cat <<EOF > docker-compose.yaml version: '3' services: jenkins: image: 'jenkins/jenkins:lts' container_name: jenkins restart: always environment: - 'JAVA_OPTS=-Duser.timezone=Asia/Shanghai' volumes: - '/etc/localtime:/etc/localtime' ports: - '8081:8080' - '50000:50000' volumes: - '/ usr/local/docker/Jenkins/jenkins_home: / var/jenkins_home' EOF echo "step 3 - > docker - compose start run Jenkins container" docker-compose up -d sleep 1 docker ps -aCopy the code

2.3 Running the install.sh script file

bash install.sh
Copy the code

2.4 As shown in the figure below, it indicates that Jenkins has been successfully installed

Wait a moment

2.5 Jenkins Basic configuration

After the operation is successful, access this address to log in to Jenkins, and access Jenkins address http://ip:8081. You need to enter the administrator password for the first login

  • Method 1: Use the administrator password to log in. You can run the following command to obtain the administrator password from the container startup log
docker logs jenkins
Copy the code

  • Method 2: from mount the directory/usr/local/docker/Jenkins jenkins_home
cat /usr/local/docker/jenkins/jenkins_home/secrets/initialAdminPassword
Copy the code

  • Select the plug-in installation method, here we directly install the recommended plug-in

  • Enter the plug-in installation interface and wait for plug-in installation through networking:

  • After the installation is complete, create an administrator account:

  • Example configuration was performed to configure Jenkins URL

  • Click System Administration -> Plug-in Management to install some custom plug-ins:

Make sure the following plug-ins are installed correctly:

  1. Publish Over SSH: Publish Over SSH
  • Go to System Administration -> Global Tools Configuration to configure global tools, such as Maven:

  • New Maven installation configuration:

  • SSH Server management: If multiple SSH servers are required, click Add to add them. Note that if the password-free login is not configured, click Advanced, select Use Password Authentication, or Use a different key, and enter the VM remote login password in Passphrase/ password

3. Gitlab installation

3.1 Download Gitlab Docker image

docker pull gitlab/gitlab-ce
Copy the code

3.2 Creating a Gitlab installation directory

mkdir -p /usr/local/docker/gitlab
cd /usr/local/docker/gitlab
touch install.sh
chmod 777 install.sh
mkdir config
mkdir data
mkdir logs
Copy the code

3.3 Creating the install.sh script file

#! /bin/bashdocker run --detach \ --publish 10443:443 --publish 8082:80 --publish 1022:22 \ --name gitlab \ --restart always \ --volume /usr/local/docker/gitlab/config:/etc/gitlab \ --volume /usr/local/docker/gitlab/logs:/var/log/gitlab \ --volume  /usr/local/docker/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:latestCopy the code

It should be noted that the HTTP service of our Gitlab runs on port 8082 of the host machine. Here, we map the configuration, log and data directory of Gitlab to the designated folder of the host machine to prevent data loss after we recreate the container.

3.4 Running the install.sh script file

bash install.sh
Copy the code

3.5 Checking whether gitLab is successfully installed

docker ps -a
Copy the code

As shown in the figure below, it indicates success. Gitlab installation is a bit large, so it needs to wait for a period of time

3.6 Enabling a specified firewall port

#Enable port 1080
firewall-cmd --zone=public --add-port=1080/tcp --permanent 
#The firewall takes effect only after being restarted
systemctl restart firewalld
#View ports that have been opened
firewall-cmd --list-ports
Copy the code

On the cloud server, open the port number on the server management page

3.7 access Gitlab

  • Visit http://ip:8082/
  • Since Gitlab starts slowly, you need to wait patiently for about 10 minutes. If Gitlab is not started and access is completed, the following error will occur.

  • You can use the docker command to dynamically view the container startup log to know whether GitLab has been started

docker logs gitlab -f
Copy the code

3.8 Use of Gitlab

The first time you visit Gitlab after startup, you will be asked to reset the password of your root account

  • After the reset, enter the password to log in

  • Select Create project, Create organization, create account

  • Create a group

First we need to create an organization, and then create users and projects under this organization, so that users in the same organization can use projects under that organization

  • Create a user and change the password

  • Change the password

  • Create a project

  • Initialize the README file

  • Assign users to organizations

  • Git client installation and use
  1. Download the Git client and install it
  2. Download: github.com/git-for-win…
  3. Once the download is complete, click Next to install it.
  • Clone project

The rest is commonly used git submission code, pull code, here is not said, if you do not understand the use of baidu Git command

4. The harbor installation

4.1 Downloading the Harbor Installation File

Github.com/goharbor/ha…

  • The decompression is shown

4.2 modify harbor. Yml

Modify the places marked in the figure

4.3 run the install. Sh

./install.sh
Copy the code

If the installation information is displayed, the installation is successful

4.3 Visiting the Harbor page

The address is the domain address that you set up

  • Enter the user name and password. The account is admin and the password is harbor_admin_password as you just configured in the configuration file

4.4 Log in to the Harbor on another Server (Client)

5 concludes

Now Jenkins + Docker + GitLab + Harbor server has been successfully deployed. The next chapter will explain how to automate the deployment project