一、准备环境

准备三台机器

角色 IP地址 用户名 密码
jenkins-master   172.25.254.130    admin   meiyoumima
gitlab 172.25.254.131 tseter  meiyoumima
jenkins-slave(Maven 172.25.254.134 N/A N/A

二、jenkins-master安装

2.1 安装Java

[root@jenkins-master ~]# yum install java-1.8.0-openjdk-devel.x86_64

[root@jenkins-master ~]# vi /etc/profile

export JAVA_HOME=/usr/lib/jvm/usr/lib/jvm/java-1.8.-openjdk-1.8.0.201.b09-.el7_6.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

[root@jenkins-master ~]# source /etc/profile

[root@jenkins-master ~]# java -version

openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK -Bit Server VM (build 25.201-b09, mixed mode)
[root@jenkins-master ~]# vi /etc/profile

2.2 安装jenkins

[root@jenkins-master ~]# cd /usr/local/src/

[root@jenkins-master src]# wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war

[root@jenkins-master src]# nohup java -jar /usr/local/src/jenkins.war --httpPort=9000 &

[root@jenkins-master src]# tail -f nohup.out

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation: 5d3a5a8d50304bcf90845c6b55e4e280 This may also be found at: /root/.jenkins/secrets/initialAdminPassword

[root@jenkins-master ~]# cat /root/.jenkins/secrets/initialAdminPassword

5d3a5a8d50304bcf90845c6b55e4e280

安装插件

创建用户

三、安装gitlab

3.1 安装依赖

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

[root@gitlab ~]# systemctl enable sshd

[root@gitlab ~]# systemctl restart sshd

[root@gitlab ~]# yum install -y postfix

[root@gitlab ~]# firewall-cmd --add-service=ssh --permanent

[root@gitlab ~]# firewall-cmd --add-service=http --permanent

[root@gitlab ~]# firewall-cmd --reload

3.2 添加GitLab社区版Package

[root@gitlab ~]# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

[root@gitlab ~]#  yum install -y gitlab-ce

3.3 配置GitLab站点Url

GitLab默认的配置文件路径是/etc/gitlab/gitlab.rb

默认的站点Url配置项是:external_url 'http://gitlab.example.com'

这里我将GitLab站点Url修改external_url 'http://172.25.254.131'

3.4 启动gitlab

[root@gitlab ~]# gitlab-ctl reconfigure

Running handlers:
Running handlers complete
Chef Client finished, / resources updated in minutes seconds
gitlab Reconfigured!

四、jenkins配置slave

4.1 master端配置

点击系统管理------------------->全局安全配置----------------->设置TCP端口

系统管理-节点管理-新建节点:

店家slave1

4.2 配置slave

在slave节点上安装agent.jar

[root@node5 ~]# yum -y install java-1.8.0-openjdk-devel.x86_64

[root@node5 ~]# vim /etc/profile

export JAVA_HOME=/usr/lib/jvm/java-1.8.-openjdk-1.8.0.201.b09-.el7_6.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

[root@node5 ~]# java -version

openjdk version "1.8.0_201"
OpenJDK Runtime Environment (build 1.8.0_201-b09)
OpenJDK -Bit Server VM (build 25.201-b09, mixed mode)

[root@node5 ~]# mkdir /usr/local/jenkins-slave

[root@node5 ~]# cd /usr/local/jenkins-slave/

[root@node5 jenkins-slave]# ll

-rw-r--r--.  root root  Apr    agent.jar

根据提示执行

[root@node5 jenkins-slave]#  java -jar agent.jar -jnlpUrl http://172.25.254.130:9000/computer/slave1/slave-agent.jnlp -secret e8b183c671c0f5efa09380c04bc54dedd1299528d2fce5d358a4c7b7b5af437d -workDir "/var/jenkins"

放后台启动

[root@node5 jenkins-slave]#nohup java -jar agent.jar -jnlpUrl http://172.25.254.130:9000/computer/slave1/slave-agent.jnlp -secret e8b183c671c0f5efa09380c04bc54dedd1299528d2fce5d358a4c7b7b5af437d -workDir "/var/jenkins" &

[root@node5 jenkins-slave]# tail nohup.out

Apr ,  :: PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Handshaking
Apr , :: PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connecting to 172.25.254.130:
Apr , :: PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Trying protocol: JNLP4-connect
Apr , :: PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Remote identity confirmed: e7:b8:::e5::c4:3f:a2:ca:9d::::7a:ce
Apr , :: PM hudson.remoting.jnlp.Main$CuiListener status
INFO: Connected

刷新页面

成功连接

五、Jenkins构建maven项目

5.1安装maven

[root@node5 jenkins-slave]# mkdir /usr/local/maven

[root@node5 jenkins-slave]# cd /usr/local/maven

[root@node5 maven]# wget http://apache.communilink.net/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz

[root@node5 maven]# tar -xf apache-maven-3.6.1-bin.tar.gz

[root@node5 maven]# ll

total
drwxr-xr-x. root root Apr : apache-maven-3.6.
-rw-r--r--. root root Apr : apache-maven-3.6.-bin.tar.gz

[root@node5 maven]# cd apache-maven-3.6.1

[root@node5 apache-maven-3.6.1]# pwd

/usr/local/maven/apache-maven-3.6.

[root@node5 apache-maven-3.6.1]# vim /etc/profile

export M2_HOME=/usr/local/maven/apache-maven-3.6.
export PATH=$PATH:$M2_HOME/bin

[root@node5 apache-maven-3.6.1]# mvn -version

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

是因为Java的环境变量配置错误

修改

export JAVA_HOME=/usr/lib/jvm/java-1.8.-openjdk-1.8.0.201.b09-.el7_6.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export M2_HOME=/usr/local/maven/apache-maven-3.6.
export PATH=$PATH:$M2_HOME/bin

[root@node5 apache-maven-3.6.1]# source /etc/profile

[root@node5 apache-maven-3.6.1]# mvn -version

Apache Maven 3.6. (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; --05T03::+:)
Maven home: /usr/local/maven/apache-maven-3.6.
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.-openjdk-1.8.0.201.b09-.el7_6.x86_64/jre
Default locale: en_US, platform encoding: UTF-
OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"
[root@node5 apache-maven-3.6.]# vim /etc/profile

[root@node5 apache-maven-3.6.1]# mvn

[INFO] Finished at: --10T23::+:

5.2简单测试Maven项目

在github找一个maven项目

https://github.com/initcron/mvn-test

[root@node5 ~]# mkdir /git

[root@node5 ~]# cd /git

[root@node5 git]# git clone https://github.com/initcron/mvn-test

[root@node5 git]# ll

drwxr-xr-x.  root root  Apr  : mvn-test

[root@node5 git]# cd mvn-test/

[root@node5 mvn-test]# ll

所有的maven项目都有一个pom.xml的文件

5.3 maven简单用法

[root@node5 mvn-test]# mvn clean    #清除缓存数据

[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.527 s
[INFO] Finished at: --11T00::+:

[root@node5 mvn-test]# cat pom.xml

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.</modelVersion>
<groupId>com.example.app</groupId>
<artifactId>maven-app</artifactId>
<packaging>jar</packaging>
<version>1.3-SNAPSHOT</version>
<name>maven-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

打包

[root@node5 mvn-test]# mvn install

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: : min
[INFO] Finished at: --11T00::+:
[INFO] ------------------------------------------------------------------------

会生成一个target目录

5.4 测试

[root@node5 mvn-test]# mvn test

[root@node5 mvn-test]# ll

drwxr-xr-x.  root root  Apr  : target

[root@node5 mvn-test]# cd target/

[root@node5 target]# ll

drwxr-xr-x.  root root    Apr  : classes
-rw-r--r--. root root Apr : maven-app-1.3-SNAPSHOT.jar #生成一个可以直接运行的jar包
drwxr-xr-x. root root Apr : maven-archiver
drwxr-xr-x. root root Apr : maven-status
drwxr-xr-x. root root Apr : surefire-reports
drwxr-xr-x. root root Apr : test-classes

[root@node5 target]# java -jar maven-app-1.3-SNAPSHOT.jar

上传到自己本地的仓库

六、手动构建项目

6.1 创建一个新的project

6.2 把这个项目clone到本地

[root@node5 mvn-test01]# cd /git/

[root@node5 git]# git clone http://172.25.254.131/tester/mvn-test01.git

[root@node5 git]# ll

drwxr-xr-x.  root root  Apr  : mvn-test
drwxr-xr-x. root root Apr : mvn-test01

[root@node5 mvn-test01]# mv ../mvn-test/* ./
[root@node5 mvn-test01]# ll

-rw-r--r--.  root root  Apr  : pom.xml
drwxr-xr-x. root root Apr : src
drwxr-xr-x. root root Apr : target

6.3 提交

[root@node5 mvn-test01]# git add *

[root@node5 mvn-test01]# git commit -m 'test'

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
git config --global user.name "Your Name" to set your account's default identity.
Omit --global to set the identity only in this repository. fatal: unable to auto-detect email address (got 'root@node5.(none)')

[root@node5 mvn-test01]# git init

Reinitialized existing Git repository in /git/mvn-test01/.git/

[root@node5 mvn-test01]# git config user.name 'tester'

[root@node5 mvn-test01]# git config user.email joy04007@gmail.com

[root@node5 mvn-test01]# git add *

[root@node5 mvn-test01]# git commit -m 'test'

 create mode  pom.xml
create mode src/main/java/com/example/app/App.java
create mode src/test/java/com/example/app/AppTest.java
create mode target/classes/com/example/app/App.class
create mode target/maven-app-1.3-SNAPSHOT.jar
create mode target/maven-archiver/pom.properties
create mode target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
create mode target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
create mode target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst
create mode target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst
create mode target/surefire-reports/TEST-com.example.app.AppTest.xml
create mode target/surefire-reports/com.example.app.AppTest.txt
create mode target/test-classes/com/example/app/AppTest.class

[root@node5 mvn-test01]# git push

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git) Username for 'http://172.25.254.131': tester
Password for 'http://tester@172.25.254.131':
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
Everything up-to-date

[root@node5 mvn-test01]# git push origin  master

Username for 'http://172.25.254.131': tester
Password for 'http://tester@172.25.254.131':
Counting objects: , done.
Delta compression using up to threads.
Compressing objects: % (/), done.
Writing objects: % (/), 6.13 KiB | bytes/s, done.
Total (delta ), reused (delta )
To http://172.25.254.131/tester/mvn-test01.git
* [new branch] master -> master

6.4 打开gitlab验证

构建成功

DEVOPS技术实践_01:jenkins集成平台的更多相关文章

  1. DEVOPS技术实践_11:Jenkins集成Sonar

    前言 前面已经有介绍sonar的安装,简单应用,下面在简答的研究一下sonar和jenkins集成的简单使用,对于sonar的安装不做介绍 一 sonar的简单介绍 持续检查避免了低质量的代码,比如S ...

  2. DEVOPS技术实践_18:Jenkins的Pinpeline对于参数的使用

    因为最近使用Pipeline声明式语法构建项目,但是最近项目的参数设置较多,特地的来学习一下关于参数的调用和测试,主要式从一个大神那里学习的,结尾回贴上大神的博客链接 1 构建一个pipeline项目 ...

  3. DEVOPS技术实践_17:Jenkins使用扩展邮件功能发送邮件

    一 环境准备 1.1 安装插件Email Extension 系统管理-管理插件-安装Email Extension插件 1.2 配置 配置jenkins邮箱的全局配置:系统管理-系统设置-完成邮箱配 ...

  4. DEVOPS技术实践_09:Jenkins多分支管道

    简介 多分支的管道是在jenkins2.x中新增的功能 . 多分支管道允许你针对分布式的控制器的每个分支创建一个管道. 下图是对它的一个描述.使用jenkinsfile去创建多分支的管道,jenkin ...

  5. DEVOPS技术实践_07:Jenkins 管道工作

    一 简介 由于在公司构建很多工作,都是使用的maven工作构建的,这种构建方式很大缺点就是所有的工作都需要一步一步的配置,当项目较多,需求变动时,需要很大的精力去修改配置,很费劲 Pipeline即为 ...

  6. DEVOPS技术实践_02:jenkins自动构建项目

    一.用户名密码错误 打开jenkins发现用户名密码错误,解决 1.1 找到config.xml文件 [root@jenkins-master ~]# ll -a drwxr-xr-x. root r ...

  7. DEVOPS技术实践_10:安装部署Artifactory

    需要一种机制去存储所有的二进制代码(build,packages,third-party plugins等)到类似于版本控制系统的系统. 像Git,SVN存储代码,它们存储的往往是源代码,不是二进制文 ...

  8. DEVOPS技术实践_06:sonar与Jenksin集成

    代码质量管理平台 一.checkout和打包功能 1.1 gitlab在新建一个文件 后续在写入内容 1.2 Jenkins新建一个任务 两个参数 1.3 流水线配置 copy仓库地址: http:/ ...

  9. DEVOPS技术实践_13:使用Jenkins持续传送设计-CD基础

    1. 分支策略 持续集成中使用的分支策略包括以下三个: The master branch The integration branch The feature branch 而CD只在Integra ...

随机推荐

  1. H5页面在iOS网页中的数字被识别为电话号码,字体颜色变黑色,且颜色不可改变

    解决办法:在html中添加代码: <meta name="format-detection" content="telephone=no" />

  2. sum(),max(),avg(),RATIO_TO_REPORT()--分组统计

    select id,area, sum(1) over() as 总记录数, sum(1) over(partition by id) as 分组记录数, sum(score) over() as 总 ...

  3. 64位Linux编译C代码,crt1.o文件格式不对的问题

    今天在某台64位LInux下编译一个简单的hello world的C程序,报错: /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../crt1.o: cou ...

  4. Python学习(四)cPickle的用法

    python中有两个类似的:pickle与cPickle:两者的关系:“cPickle – A faster pickle” pickle模块中的两个主要函数是dump()和load().dump() ...

  5. behavior planning——12.example cost funtion -lane change penalty

      In the image above, the blue self driving car (bottom left) is trying to get to the goal (gold sta ...

  6. Project Euler Problem 21-Amicable numbers

    先说最暴力的算法,直接对一万内的每个数字暴力分解因子(对每个数字的时间复杂度是O(sqrt(n)的),然后,用个数组记录下来因子和,然后寻找 亲密数. 好一点:要先打个素数表,然后对每个数字,分解素因 ...

  7. jq实现超级简单的隔行变色

    文章地址:https://www.cnblogs.com/sandraryan/ <!DOCTYPE html> <html lang="en"> < ...

  8. GPU版TensorFlow怎么指定让CPU运行

    由于某些原因GPU版的TensorFlow运行起来会出现一些问题,比如内存溢出等情况.此时我们可以用CPU和系统内存来运行我们的程序. 代码如下: import osos.environ[" ...

  9. python进阶之异常处理

    异常处理 在代码运行时,会因为各种原因出现bug,而程序遇到bug就会中断运行,而在日常生产中程序是要长时间运行不能随意中断的.因此就需要我们提前做好异常处理. 异常 print(x) # 一般报错就 ...

  10. 21个项目玩转深度学习:基于TensorFlow的实践详解01—MNIST机器学习入门

    数据集 由Yann Le Cun建立,训练集55000,验证集5000,测试集10000,图片大小均为28*28 下载 # coding:utf-8 # 从tensorflow.examples.tu ...