DEVOPS技术实践_01:jenkins集成平台
一、准备环境
准备三台机器
角色 | 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集成平台的更多相关文章
- DEVOPS技术实践_11:Jenkins集成Sonar
前言 前面已经有介绍sonar的安装,简单应用,下面在简答的研究一下sonar和jenkins集成的简单使用,对于sonar的安装不做介绍 一 sonar的简单介绍 持续检查避免了低质量的代码,比如S ...
- DEVOPS技术实践_18:Jenkins的Pinpeline对于参数的使用
因为最近使用Pipeline声明式语法构建项目,但是最近项目的参数设置较多,特地的来学习一下关于参数的调用和测试,主要式从一个大神那里学习的,结尾回贴上大神的博客链接 1 构建一个pipeline项目 ...
- DEVOPS技术实践_17:Jenkins使用扩展邮件功能发送邮件
一 环境准备 1.1 安装插件Email Extension 系统管理-管理插件-安装Email Extension插件 1.2 配置 配置jenkins邮箱的全局配置:系统管理-系统设置-完成邮箱配 ...
- DEVOPS技术实践_09:Jenkins多分支管道
简介 多分支的管道是在jenkins2.x中新增的功能 . 多分支管道允许你针对分布式的控制器的每个分支创建一个管道. 下图是对它的一个描述.使用jenkinsfile去创建多分支的管道,jenkin ...
- DEVOPS技术实践_07:Jenkins 管道工作
一 简介 由于在公司构建很多工作,都是使用的maven工作构建的,这种构建方式很大缺点就是所有的工作都需要一步一步的配置,当项目较多,需求变动时,需要很大的精力去修改配置,很费劲 Pipeline即为 ...
- DEVOPS技术实践_02:jenkins自动构建项目
一.用户名密码错误 打开jenkins发现用户名密码错误,解决 1.1 找到config.xml文件 [root@jenkins-master ~]# ll -a drwxr-xr-x. root r ...
- DEVOPS技术实践_10:安装部署Artifactory
需要一种机制去存储所有的二进制代码(build,packages,third-party plugins等)到类似于版本控制系统的系统. 像Git,SVN存储代码,它们存储的往往是源代码,不是二进制文 ...
- DEVOPS技术实践_06:sonar与Jenksin集成
代码质量管理平台 一.checkout和打包功能 1.1 gitlab在新建一个文件 后续在写入内容 1.2 Jenkins新建一个任务 两个参数 1.3 流水线配置 copy仓库地址: http:/ ...
- DEVOPS技术实践_13:使用Jenkins持续传送设计-CD基础
1. 分支策略 持续集成中使用的分支策略包括以下三个: The master branch The integration branch The feature branch 而CD只在Integra ...
随机推荐
- 2019-8-31-C#-将-Begin-和-End-异步方法转-task-异步
title author date CreateTime categories C# 将 Begin 和 End 异步方法转 task 异步 lindexi 2019-08-31 16:55:58 + ...
- Python 变量赋值
- qt开发ROS gui 遇到:global.h:1087:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. "......
具体错误如下: 一共出现38个错误 这个错误是在导入cmakelists.txt时产生的,其实不是工程本身的问题,是因为我卸载ros,再重新安装ros的过程中把qtcreator的部分包给删除了,导致 ...
- 走近科学,探究阿里闲鱼团队通过数据提升Flutter体验的真相
背景 闲鱼客户端的flutter页面已经服务上亿级用户,这个时候Flutter页面的用户体验尤其重要,完善Flutter性能稳定性监控体系,可以及早发现线上性能问题,也可以作为用户体验提升的衡量标准. ...
- oracle函数 nls_charset_name(n1)
[功能]返回字符集名称参应id值 [参数]n1,数值型 [返回]字符型 sql> select nls_charset_name(852) from dual; nls_char ------- ...
- Python深入:Distutils发布Python模块
Distutils可以用来在Python环境中构建和安装额外的模块.新的模块可以是纯Python的,也可以是用C/C++写的扩展模块,或者可以是Python包,包中包含了由C和Python编写的模块. ...
- iOS开发那些事-响应内存警告
好的应用应该在系统内存警告情况下释放一些可以重新创建的资源.在iOS中我们可以在应用程序委托对象.视图控制器以及其它类中获得系统内存警告消息. 1.应用程序委托对象 在应用程序委托对象中接收内存警告消 ...
- 注意 Laravel 清除缓存 php artisan cache:clear 的一个坑
Laravel 的命令 php artisan cache:clear 用来清除各种缓存,如页面,Redis,配置文件等缓存,它会清空 Redis 数据库的全部数据,比如默认使用的 Redis 的 数 ...
- poj 2442 Sequence (Priority Queue)
2442 -- Sequence 真郁闷,明明方法是对的,为什么我的代码老是那么的慢._(:з」∠)_ 这题要想考虑两列的情况,然后逐列拓展. 代码如下: #include <cstdio> ...
- Python--day19--random模块
random模块 >>> import random #随机小数 >>> random.random() # 大于0且小于1之间的小数 0.766433866365 ...