jenkins部署java项目
#########################################jenkins部署#################################3
一、jenkins是什么?
Jenkins 是一个可扩展的持续集成引擎。
主要用于:
- l 持续、自动地构建/测试软件项目。
- l 监控一些定时执行的任务。
Jenkins拥有的特性包括:
- l 易于安装-只要把jenkins.war部署到servlet容器,不需要数据库支持。
- l 易于配置-所有配置都是通过其提供的web界面实现。
- l 集成RSS/E-mail通过RSS发布构建结果或当构建完成时通过e-mail通知。
- l 生成JUnit/TestNG测试报告。
- l 分布式构建支持Jenkins能够让多台计算机一起构建/测试。
- l 文件识别:Jenkins能够跟踪哪次构建生成哪些jar,哪次构建使用哪个版本的jar等。
- l 插件支持:支持扩展插件,你可以开发适合自己团队使用的工具
部署规划
环境部署
jenkins安装:
登陆172.16.204.130
安装JDK
脚本安装:
JDK.sh (JDK安装路径需要知道,后期jenkins后台配置会用到)
#!/bin/bash
###一键安装jdk1.###
#安装jdk
mkdir -p /usr/local/java
cat <<EOF >> /etc/profile
export JAVA_HOME=/usr/local/java/jdk1..0_171
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:/usr/local/java/jdk1..0_171/bin
EOF
tar -zxvf jdk-8u171-linux-x64.tar.gz -C /usr/local/java
source /etc/profile
java -version
if [ $? -ne ]; then
echo "安装失败并退出"
exit
else
echo "***jdk安装完成***"
fi
source /etc/profile
GIT安装
yum -y install git
maven安装
cd /opt
wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz
tar -zxvf apache-maven-3.6.1-bin.tar.gz
cd /opt/apache-maven-3.6.1/conf
vi /etc/profile
MAVEN_HOME=/opt/apache-maven-3.6.1
vim 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:
|
| . 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
|
| . 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>
-->
<localRepository>/opt/repository</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></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
| Specifies the authentication information to use when connecting to a particular server, identified by
| a unique name within the system (referred to by the 'id' attribute below).
|
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
| used together.
|
<server>
<id>deploymentRepo</id>
<username>repouser</username>
<password>repopwd</password>
</server>
--> <!-- 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>
-->
</servers> <!-- 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
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus repository</id>
<name>intranet public groups</name>
<url>http://172.16.66.34:8081/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</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>
配置文件需要添加的部分
nexus相关配置
本地库路径
jenkins服务部署
安装tomcat
下载tomcat安装包
tar -zxvf apache-tomcat-8.5.31.tar.gz -C /opt
mv apache-tomcat-8.5.31 tomcat
cd /opt/tomcat/webapps
rm -rf *
将jenkins.war放到webapps中,jenkins安装包去官网自己下载
mv jenkins.war /opt/tomcat/webapps
启动tomcat服务
cd /opt/tomcat/bin
./startup.sh
##关闭selinux和firewalld防火墙
这个时候就可以通过浏览器访问jenkins页面了
http://172.16.204.130/jenkins/
第一次进入Jenkins会让你走几个步骤
- 输入管理员密码,密码可以从页面提示的文件中看到
- 下载默认插件,点击官方推荐的按钮继续往下走
- 设置账号密码和邮箱地址
- 登入
一顿操作,我们就来到了Jenkins的Dashboard页面
########################################Jenkins部署完成#######################################################
Gitlab安装配置及旧git项目的导入
172.16.204.131部署gitlab
官网centos7 gitlab的安装方法:https://about.gitlab.com/install/#centos-7
gitlab使用方法:https://www.centos.bz/2018/05/gitlab%E6%90%AD%E5%BB%BA%E4%B8%8E%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/
1. 安装GitLab
有的教程还会安装postfix来发送通知邮件,不过这得需要你有服务器的外部DNS名称,我试了3次都没设置成功,所有建议你别安装了,等后面再配置外部SMTP服务器,这个操作成功率比较高。
1.1 添加GitLab包库
这里屏幕上也会输出一堆东西,最后看到 The repository is setup! You can now install packages. 就说明成功了
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
1.2 安装GitLab
这里也会输出一堆东西,你会看到有下载进度,和安装进度,最后安装完成后屏幕上会输出 GitLab 的 logo
sudo yum install -y gitlab-ee
3. 配置并启动GitLab
如果服务器配置垃圾的话,这里会花费大量时间,可能会等半个小时左右吧,所以耐心等待,不要以为它坏了。最后输出 gitlab Reconfigured! 就代表成功了。
sudo gitlab-ctl reconfigure
4. 可以使用啦
打开一个浏览器,输入你安装GitLab的服务器IP地址,就会打开一个网页。
第一次进入会让你设置密码
3. Gitlab管理
我需要实现的目标是
因为是内部团队使用,所以取消注册功能
image.png新用户缺省不允许创建Project
image.pngAPI创建用户,
可能需要创建的用户比较多,同时需要取消邮件确认和创建group权限。可以考虑通过API来创建,命令如下:
//如果在win10的powershell下运行,需要先运行这句
Remove-item alias:curl
curl --header "PRIVATE-TOKEN: XtgossbudeEerKMbhy" --data "password=badfe@12312&email=xxx@qq.com&username=cengh&name=%E7%8E%8B%E8%80%81%E4%BA%8C&can_create_group=false&skip_confirmation=true" "http://外网ip:8888/api/v4/users"
PRIVATE-TOKEN参数是指有权限创建用户的管理员账号的一个token,在自己的账号setting上能创建和获取到。
image.png- password最好复杂一下,不能太简单。否则会有错误
name如果是中文,需要转码,否则也有错误
image.png- can_create_group=false:表示禁止创建组
- skip_confirmation=true:表示跳过邮件确认
更多参数可以参考Gitlab的API文档
4. 导出旧项目然后导入到Gitlab
如果只把源码导出再导入,那么所有分支包括分支的所有历史记录都没有了。可以通过以下命令来实现把项目respository完全镜像clone下来,包括所有分支和记录。
git clone --bare git://github.com/username/project.git
下载下来的目录不是源代码,而是类似以下的目录结构:
最后在gitlbab上先创建一个新的respository,然后命令行进入到以上的目录下,执行git push命令把旧的镜像推送到新的gitlab上的respository里。
cd project.git
git push --mirror git@你的gitlab的ip/newproject.git
作者:voxer
链接:https://www.jianshu.com/p/0cd62d826114
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
172.16.204.131安装tomcat
下载tomcat安装包
tar -zxvf apache-tomcat-8.5.31.tar.gz -C /opt
mv apache-tomcat-8.5.31 tomcat
cd /opt/tomcat/webapps
rm -rf *
将jenkins.war放到webapps中,jenkins安装包去官网自己下载
mv jenkins.war /opt/tomcat/webapps
启动tomcat服务
cd /opt/tomcat/bin
./startup.sh
##关闭selinux和firewalld防火墙
##################################tomcat部署完成###############################
基础环境已就位,开始配置jenkins页面喽
jenkins部署项目到远程服务器
配置jenkins服务器到远程服务器的免秘钥登陆,这里可以网上看下,so easy!
配置jenkins页面:
系统管理---插件管理(第一次登陆的时候可以默认安装所有插件,根据需求在安装相应的插件)
系统管理 ---系统设置
系统管理---全局工具配置
基础配置完成:开始构建一个新的java项目并远程发布到服务器
ok 基本部署完成,测试部署
注意:例如有多套环境,测试 开发 生产,他们对应的中间件和数据库有可能不是同一个,这时候就需要在部署的时候修改配置文件,修改方法:可以将配置文件保存到某个目录,
使用脚本jenkins放到远程服务器的jar包或者war包解压,将配置文件覆盖,最后发包部署来实现配置文件的修改
粗糙脚本参考:(根据自己的实际情况来修改脚本)
#!/bin/bash
export JAVA_HOME=/usr/local/java/jdk1..0_171
BaseDir=/opt/tomcat/webapps
FaBan=/opt/tomcat/faban
Remotedirectory=/opt/dianelian
PackageName=purchase_mall.war
BackUp="/opt/backup/`date +'%Y%m%d%H%M%S'`"
PID=`ps -ef |grep tomcat |grep -v grep |awk '{print $2}'`
num=`ps -ef |grep tomcat |grep -v grep |awk '{print $2}'|wc -l`
if [ $num -ge "" ]
then
kill - $PID
fi
if [ ! -d "$BackUp" ]
then
mkdir -p "$BackUp"
fi
mv $BaseDir/* $BackUp
mv $FaBan/* $BaseDir
sh /opt/tomcat/bin/startup.sh
jenkins部署java项目的更多相关文章
- jenkins部署java项目,脚本文件放在远程仓库中 和jar一起打包(六)
jenkins部署java项目到远程linux上,脚本文件和项目一起上传到gogs上,直接执行gogs上的脚本文件来执行项目 (1)新建maven项目 pom.xml的配置 <project x ...
- 通过Jenkins部署java项目
部署java项目-创建私有仓库 Jenkins大多数情况下都是用来部署Java项目,Java项目有一个特点是需要编译和打包的,一般情况下编译和打包都是用maven完成,所以系统环境中需要安装maven ...
- git jenkins 部署java项目
1.Java项目部署基本概述: 1.什么是Java项目? 2.为什么Java项目需要使用Maven编译? 3.手动实现Java项目构建? 4.手动实现Java项目架构图? 源码包 jar包 ...
- Win10搭建Jenkins部署Java项目(本机和远程Win10部署)
目录 一.前言&背景 二.环境准备 三.插件安装 四.全局配置 Maven JDK Git Maven 五.新建项目并配置 新建项目 配置 1.Discard old builds 2.Thi ...
- Docker使用jenkins部署java项目到远程linux(三)
实现功能:从本地提交代码到gogs上,本地的代码会被检测一遍 如果检测通过才能commit成功 然后可以继续执行push命令 .push后在gogs上使用web钩子自动推送到jenkins触发构建,j ...
- jenkins部署java项目到远程linux(四)
(1)新建java项目(maven构建) pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:x ...
- jenkins部署java项目在本地(三)
(1)新建maven构建的java项目 pom.xml的配置 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...
- jenkins部署java项目(五)
一.web server安装jdk+tomcat其中jdk可以为openjdk,版本1.8 1.1 安装jdk环境 方式一:直接使用yum安装openjdk # * 方式二:本地安装在oracle官网 ...
- jenkins部署web项目到webogic
注: Docker容器里安装的jenkins,Docker容易里安装的weblogic 在jenkins里面直接将打包好的 war 包通过 Publish over SSH插件 放入 weblogic ...
随机推荐
- 【Lucene】小谈lucene的BooleanQuery查询对象
BooleanQuery用于逻辑查询,即所谓的组合查询,具体的逻辑关系如下: 一个具体的使用测试,如下:
- Uncaught SyntaxError: Unexpected identifier
$.ajax({ //请求头 type:"POST", contentType:"application/x-www-form-urlencoded", url ...
- IT技术网站博客推荐
CSDN 全球最大中文IT社区,为IT专业技术人员提供最全面的信息传播和服务平台. 51CTO 技术成就梦想 - 中国领先的IT技术网站 itEye Java编程 Spring框架 Ajax技术 ag ...
- Nginx做代理路由时,不转发http的header问题
从header里面拿不到 TX_XID这种类型的字段, Nginx 会默认忽略含有 “_” 的 header 参数,而 TX_XID值的参数名恰好含有 “_” 符号,需要手动开启转发. 在 nginx ...
- 安全专家发现GE Multilin SR的一个关键漏洞对全球电网构成严重威胁。
A team of researchers from New York University has found a serious vulnerability in some of GE Multi ...
- tar.xz压缩工具使用(转)
XZ压缩最新压缩率之王 xz这个压缩可能很多都很陌生,不过您可知道xz是绝大数linux默认就带的一个压缩工具. 我是在下载phpmyadmin的时候看到这种压缩格式的,phpmyadmin压缩包xz ...
- 牛客练习赛46 A 华华教奕奕写几何 (简单数学)
链接:https://ac.nowcoder.com/acm/contest/894/A 来源:牛客网 华华教奕奕写几何 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 524288K ...
- 多态(Polymorphism)的实现机制
1. 我理解的广义的 override 是指抛开各种访问权限,子类重定义(redefine)父类的函数(即函数签名相同). 2. C++中的三个所谓的原则:never redefine base cl ...
- PHP的函数获取图片的宽高等信息
PHP的函数getimagesize可以得到图片的宽高等信息 array getimagesize ( string $filename [, array &$imageinfo ] ) ...
- poj1015 Jury Compromise[背包]
每一件物品有两个属性.朴素思想是把这两种属性都设计到状态里,但空间爆炸.又因为这两个属性相互间存在制约关系(差的绝对值最小),不妨把答案设计入状态中,设$f[i][j]$选$i$个人,两者之差$j$. ...