目前只部署了ci 部分
如果没有包可以联系本文作者
发布k8s还没有做 已发布了到harbor上
还差一个k8s的jenkinsfile的脚本

IP地址划分

10.10.2.74 gitlab
10.10.2.75 jenkins maven
10.10.2.36 nexus
10.10.2.107 harbor

k8s 集群ip没有记录

1、搭建gitlab

  1. 下载gitlab rpm包
    https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.2.3-ce.0.el7.x86_64.rpm

  2. rpm安装
    [root@nec-test-gitlab ~]# yum localinstall -y ./gitlab-ce-13.2.3-ce.0.el7.x86_64.rpm
    如果提示有依赖,还请自行百度下载通过rpm包安装依赖

  3. 配置访问
    [root@nec-test-gitlab ~]# mkdir -p /data/git-data
    [root@nec-test-gitlab ~]# vi /etc/gitlab/gitlab.rb

external_url ‘http://10.10.2.74’
git_data_dirs({
“default” => {
“path” => “/data/git-data”
}
})
在这里插入图片描述

  1. 重载配置文件
    [root@nec-test-gitlab ~]# gitlab-ctl reconfigure

  2. 启动访问
    [root@nec-test-gitlab ~]# gitlab-ctl start

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
git客户端设置
1)全局设置
[root@nec-test-gitlab ~]# git config --global user.name “Administrator”
[root@nec-test-gitlab ~]# git config --global user.email “admin@example.com”

2)拉取仓库,并创建文件上传
[root@nec-test-gitlab ~]# git clone http://10.10.2.74/admina/test-wjh.git
(我这里为了方便做的http的形式 这里也可以做git免密的形式)

这里写的测试
[root@nec-test-gitlab ~]# cd git-test/
[root@nec-test-gitlab git-test]# echo “This is Test.” > README.md
[root@nec-test-gitlab git-test]# echo “This is Test.” > Test.file
[root@nec-test-gitlab git-test]# git add ./
[root@nec-test-gitlab git-test]# git commit -m “add README.md and Test.file”
[root@nec-test-gitlab git-test]# git push -u origin master
Username for ‘http://10.10.2.74’:
Password for ‘http://root@10.10.2.74’:

2、jenkins+maven

包需要:apache-maven-3.6.3-bin.tar.gz
apache-tomcat-8.5.59.tar.gz
jenkins.war
jdk-8u201-linux-x64.tar.gz

1、首先添加jdk环境解压jdk

vim /etc/profile  #添加
export PATG=$PATH:/opt/jdk1.8.0_201/bin
export JAVA_HOME=/opt/jdk1.8.0_201
export PATH=$PATH:/opt/apache-maven-3.6.3/bin
export PATH=$PATH:$MAVEN_HOME/bin
export JAVA_HOME PATH

2、把jenkins.war 包 放在tomcat下

tar zxf apache-tomcat-8.5.59.tar.gz -C /opt
[root@jenkins /]# cd /opt/apache-tomcat-8.5.59/bin/
[root@jenkins bin]# ./startup.sh

在这里插入图片描述
cp jenkins.war /opt/apache-tomcat-8.5.59/webapps/

重启tomcat
我的已经做了流水线直接出现了登录界面

详细安装请百度特别简单 点点点
在这里插入图片描述

3、配置maven
maven下载链接 https://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

[root@jenkins ~]# tar zxf apache-maven-3.6.3-bin.tar.gz
[root@jenkins ~]# mv apache-maven-3.6.3 /usr/local/maven-3.6.3
[root@jenkins ~]# source /etc/profile
[root@jenkins ~]# mvn --version
[root@jenkins bin]# mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /opt/jdk1.8.0_201/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: “linux”, version: “3.10.0-957.el7.x86_64”, arch: “amd64”, family: “unix”

4、下面是jenkins配置

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

以上是添加Jenkins中的组件

5、安装nexus

  1. 下载安装包
    下载过程可能会很慢
    http://www.sonatype.org/nexus/go

  2. 安装启动Nexus
    [root@nec-test-jenkins ~]# tar zxf nexus-3.27.0-03-unix.tar.gz
    [root@nec-test-jenkins ~]# mv nexus-3.27.0-03 /usr/local/
    [root@nec-test-jenkins ~]# /usr/local/nexus-3.27.0-03/bin/nexus start

  3. 访问,默认8081端口
    顺便写一下
    默认用户admin
    密码admin123
    在这里插入图片描述
    6、修改jenkins 的maven配置文件,使其能从Nexus中拉取镜像

这里我直接把我整个配置文件复制下来了,访问配置错误
我下面加了注释可以看一下

cat settings.xml


<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>     # 这里添加

    <server>
      <id>public</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

  </servers> #到这里

<!--
         <activeProfile>maven-aliyun</activeProfile>
-->


    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->





  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>     #这里添加或者更改
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://10.10.2.36:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>     #到这

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
  </profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->

</settings>

7、准备测试项目

[root@nec-test-jenkins ~]# git config --global user.name “Administrator”
[root@nec-test-jenkins ~]# git config --global user.email “admin@example.com”
[root@nec-test-jenkins ~]# git clone http://10.10.2.74/admina/test-wjh.git
##这个是我事先做好的demo,也可以去github上面找个简单的java程序进行打包测试
[root@nec-test-jenkins ~]# cd test-wjh

[root@jenkins web-test-pipeline]# cat pom.xml
注意这里的pom 文件一定不要写错 最好是直接复制

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.vorb</groupId>
    <artifactId>code-test</artifactId>
    <version>0.0.5-SNAPSHOT</version>
    <packaging>war</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.2.8.RELEASE</version>
        <relativePath/>
    </parent>

    <licenses>
        <license>
            <name>MIT License</name>
            <url>http://www.opensource.org/licenses/mit-license.php</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <url>https://github.com/pvorb/wildfly-spring-boot-sample</url>
        <connection>scm:git:git://github.com/pvorb/wildfly-spring-boot-sample.git</connection>
        <developerConnection>scm:git:git@github.com:pvorb/wildfly-spring-boot-sample.git</developerConnection>
    </scm>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.16</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
<distributionManagement>
        <repository>
            <id>releases</id>     #注意这个id,要和maven配置文件中的 serverid一致
            <name>Nexus Release Repository</name>
            <url>http://10.10.2.36:8082/repository/aliyun-releases/</url>
        </repository>
        <snapshotRepository>
                <id>snapshots</id>  #注意这个id,要和maven配置文件中的 serverid一致
                <url>http://10.10.2.36:8082/repository/aliyun-snapshots/</url>
        </snapshotRepository>
 </distributionManagement>

</project>

[root@jenkins test]# git add ./pom.xml
[root@jenkins test]# git commit -m “Edit pox.xml”
[root@jenkins test]# git push

8、下载java所需依赖包并上传到 Nexus 的私有仓库中创建一个仓库
登录nexus

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

因为我这里已经添加所以是灰色的
在这里插入图片描述
修改这三个库的安全策略
在这里插入图片描述

在这里插入图片描述

这里只是做一个介绍

可以去阿里云的maven仓库下载jar包
https://repo.maven.apache.org/maven2
或https://maven.aliyun.com/mvn/search

所需依赖包在 项目代买的pod.xml中,类似如下

org.springframework.boot
spring-boot-starter

继续操作

在这里插入图片描述
在这里插入图片描述

9、打包测试
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

10、通过Jenkins发布harbor 镜像

编写构建脚本

在这里插入图片描述
在这里插入图片描述
以下是脚本内容

#!/bin/bash
 
##应用名称
APP_NAME=test-web
 
##镜像标签
Dcoerk_tag=$(date +%Y%m%d%H)
 
##Harbor地址
Registry=ops.demo.com
 
##构建镜像

cd  /root/test-wjh/
cp target/code-test-0.0.5-SNAPSHOT.war kubernetes/
cd kubernetes
docker build -t=$Registry/test/$APP_NAME:$Dcoerk_tag .
 
##推送镜像
docker login ops.demo.com  -uadmin -p123
docker push $Registry/test/$APP_NAME:$Dcoerk_tag
if [ $? != 0 ];then


echo "推送镜像失败"
docker rmi $Registry/test/$APP_NAME:$Dcoerk_tag
exit 10
fi
 
##删除本地镜像,节省空间
docker rmi $Registry/test/$APP_NAME:$Dcoerk_tag
 

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
到harbor查看一下
我们推送的镜像
在这里插入图片描述

这里是用shell发布的我还写了一个pipejenkis发布的镜像

感觉整个比较好看一点
脚本如下

在这里插入图片描述

pipeline {
    agent any

    stages {
        stage('git demo') {
            steps {
               checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '1988bed3-baa4-4eae-bb7d-2fad3dd76659', url: 'http://10.10.2.74/admina/test-wjh.git']]])
            }
        }
        stage('mvn install') {
            steps {
               sh '''
               printenv
               source /etc/profile
               cd ${WORKSPACE}
               mvn install
               mvn clean package
               '''
            }  
        }
         stage('build demo') {
            steps {
               sh '''
               cd ${WORKSPACE}
               cp target/code-test-0.0.5-SNAPSHOT.war kubernetes/
               cd kubernetes
               DOCKER_TAG=`date +%Y-%m-%d-%H`
               docker build -t ops.demo.com/test/$JOB_NAME:$DOCKER_TAG .
               
               '''
            }  
        }
        
        stage('push demo') {
            steps {
               sh '''
               DOCKER_TAG=`date +%Y-%m-%d-%H`
               docker login ops.demo.com  -uadmin -p123
               docker push ops.demo.com/test/$JOB_NAME:$DOCKER_TAG
               if [ $? != 0 ];then
               echo "推送镜像失败"
               docker rmi ops.demo.com/test/$JOB_NAME:$DOCKER_TAG
               exit 10
               fi
               docker rmi ops.demo.com/test/$JOB_NAME:$DOCKER_TAG
               
               '''
            }  
        }
    }
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

GitHub 加速计划 / ha / harbor
23.24 K
4.68 K
下载
Harbor 是一个开源的容器镜像仓库,用于存储和管理 Docker 镜像和其他容器镜像。 * 容器镜像仓库、存储和管理 Docker 镜像和其他容器镜像 * 有什么特点:支持多种镜像格式、易于使用、安全性和访问控制
最近提交(Master分支:2 个月前 )
9e55afbb pull image from registry.goharbor.io instead of dockerhub Update testcase to support Docker Image Can Be Pulled With Credential Change gitlab project name when user changed. Update permissions count and permission count total Change webhook_endpoint_ui Signed-off-by: stonezdj <stone.zhang@broadcom.com> Co-authored-by: Wang Yan <wangyan@vmware.com> 6 天前
3dbfd422 Signed-off-by: wang yan <wangyan@vmware.com> 7 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐