从零开始搭建系统2.4——Jenkins安装及配置
1.安装
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins
安装目录: /usr/lib/jenkins
工作目录: /var/lib/jenkins(对应于环境变量 JENKINS_HOME)
2.进入jenkins的系统配置文件并修改相关端口号(也可以不修改)
jenkins的默认JENKINS_PORT是8080,JENKINS_AJP_PORT默认端口是8009,这同tomcat的默认端口冲突。我这更改为8088和8089。
vi /etc/sysconfig/jenkins
3.启动、关闭jenkins服务
sudo service jenkins start/stop/restart
启动服务时可能为失败,这可能时因为jenkins启动脚本指定了JAVA路径,如果跟你的不一样,需要稍作调整
vim /etc/init.d/jenkins
由于我的JDK不是安装在这个路径下面的,我这边的处理方式是创建一个JAVA软连接至/usr/bin/ 下面
ln -s /opt/soft/java/jdk1.8.0_171/jre/bin/java /usr/bin/java
4.开启端口
6.配置git
1)安装git
yum install git
2)生产ssh秘钥
ssh-keygen -t rsa -C "your email address"
连续按3个回车(密码默认为空),得到 id_rsa 和 id_rsa.pub 文件,在/root/.ssh 下说明生成成功
3)配置ssh秘钥
将本地 id_rsa.pub 中的内容粘贴到 Key 文本框中,随意输入一个 title(不要有中文),点击 Add Key 即可
7.配置maven
1)安装maven
wget http://mirrors.hust.edu.cn/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz
tar zxf apache-maven-3.1.1-bin.tar.gz
2)配置环境变量
使用vim编辑/etc/profile文件
命令:vim /etc/profile(提示:vim使用方法)
在/etc/profile文件末尾增加以下配置:
#set maven
M2_HOME=/usr/maven/apache-maven-3.1.1
export PATH=${M2_HOME}/bin:${PATH}
重载/etc/profile这个文件
source /etc/profile
3)配置maven
MAVEN_HOME/conf目录下settings.xml文件是Maven的配置文件,我们在这里主要配置如下两个参数:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<pluginGroups>
<pluginGroup>org.sonatype.plugins</pluginGroup>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>Releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>Snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.0.200:8081/repository/nexus-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
8.配置jdk,git,maven
9.安装maven插件
如果在新建项目是没有maven选项,需要安装maven插件。点击“可选插件” 然后在右边的过滤输入框中输入搜索关键字: maven-plugin
,搜索到了以后 maven-plugin,点击直接安装,
安装完成后重启就好了。
10.安装Publish Over SSH 插件
配置ssh server
系统管理-》系统配置
Passphrase:SSH的密码
使用用户名/密码登录时为用户名的密码,使用私钥登录时为私钥的密码。
11.构建MAVEN项目
11.1发布web
配置git源码
设置pom路径
配置发布脚本
参数说明
- Name
“系统管理>系统设置”设置的SSH Sverver的名字列表。 - Source files
复制到运程机上的文件,相对workspace的路径,也支持表达式,如上图中的“**/*.war”。 - Remove prefix
文件复制时要过滤的目录,如上图中的target目录。Remove prefix可以把target/shop.war的target/去掉,这样上传到服务器上就是shop.war,否则它会创建target目录 - Remote directory
文件得到到远程机上的目录,此目录是相对于“SSH Server”中的“Remote directory”的,如果不存在将会自动创建。
启动脚本
base_dir=/WebRoot/MicroServiceFrame-Eureka
archive=MicroServiceFrame-Eureka.jar
exc_file=exc.jar
jvmOption="-server -Xmx256m"
check_archive(){
echo "检查程序文件..."
if [ ! -f ${base_dir}/$archive ]
then
echo "程序文件 [${archive}] 不存在, 请检查!"
exit 1
fi
}
backup(){
echo "备份..."
cp -f ${base_dir}/${archive} ${base_dir}/${archive}-`date +%Y%m%d%H%M%S`
}
stop(){
echo "停止服务..."
echo "检查服务进程..."
pids=`ps -ef | grep ${base_dir}/$archive|grep -v grep`
if [ -n "${pids}" ]; then
pids=`echo ${pids} | awk '{print $2}'`
echo ${pids} | xargs kill -15
fi
sleep 10
pids=`ps -ef | grep ${base_dir}/$archive|grep -v grep`
if [ -n "${pids}" ]; then
echo "服务未正常停止, 强制杀死进程..."
pids=`echo ${pids} | awk '{print $2}'`
echo ${pids} | xargs kill -9
fi
}
start(){
if [ -f $base_dir/$exc_file ]
then
mv $base_dir/$exc_file $base_dir/$archive
fi
echo "启动服务..."
cd $base_dir
java ${jvmOption} -jar ${base_dir}/${archive} >/dev/null 2>&1 &
}
check_archive
stop
backup
start
给启动脚本添加执行权限
进入脚本所在目录
cd /WebRoot/MicroServiceFrame-Eureka
添加权限
chmod u+x *.sh
启动过程中如果报错 no main manifest attribute,则需要在pom中添加下面配置
<build> <finalName>${project.name}</finalName> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins></build>
11.2发布jar包同发布web唯一不同的是下面部分,其它一样
12.发布纯前端web项目
配置编译环境
在这个过程中,我们需要为应用配置基于node的编译环境。
关于安装node,一般可以下载执行文件安装或编译源码安装,而通过Jenkins,我们则可考虑使用其提供的插件进行自动安装
1、选择系统管理->管理插件
2.安装完毕后,选择系统管理->Global Tool Configuration,配置node下载及安装
3.新建任务
echo $PATH
node -v
npm -v
npm --registry https://registry.npm.taobao.org install express
npm install vue@2.5.16 --save
npm install
npm run build
cd dist
tar -zcvf online-web.tar.gz *
及
startup.sh脚本内容
base_dir=/opt/webroot/yushanfang/online-web
archive=online-web.tar.gz
check_archive(){
echo "检查程序文件..."
if [ ! -f ${base_dir}/$archive ]
then
echo "程序文件 [${archive}] 不存在, 请检查!"
exit 1
fi
}
start(){
echo "启动服务..."
tar -zxvf ${base_dir}/$archive -C ${base_dir}/web
}
check_archive
start
如果编译过程中报如下错,可以通过手工下载
/tmp/phantomjs/
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
13.卸载
sudo systemctl stop jenkins
sudo systemctl disable jenkins
sudo yum -y remove jenkins
sudo rm -rf /var/{lib,log,cache}/jenkins /usr/lib/jenkins /root/.jenkins
sudo rm -rf `sudo find /{etc,var,run} -name "jenkins*"`
问题:
在执行脚本的时候可能会遇到找不到自定义的命令,例如java
如何解决SSH远程执行命令找不到环境变量的问题
通过SSH执行远程主机的命令或脚本时,经常会出现找不到自定义环境变量的问题。但是,如果通过SSH登录远程主机,然后再执行相同的命令或脚本,那么此时执行又是成功的。两种相似的方法,得到的结果却截然不同,看起来很诡异的现象,根本原因在于这两种方式使用的bash模式不同!
1. 通过SSH登录后再执行命令和脚本
这种方式会使用Bash的interactive + login shell模式,这里面有两个概念需要解释:interactive和login。
login故名思义,即登陆,login shell是指用户以非图形化界面或者以ssh登陆到机器上时获得的第一个shell,简单些说就是需要输入用户名和密码的shell。因此通常不管以何种方式登陆机器后用户获得的第一个shell就是login shell。
interactive意为交互式,这也很好理解,interactive shell会有一个输入提示符,并且它的标准输入、输出和错误输出都会显示在控制台上。所以一般来说只要是需要用户交互的,即一个命令一个命令的输入的shell都是interactive shell。而如果无需用户交互,它便是non-interactive shell。通常来说如bash script.sh此类执行脚本的命令就会启动一个non-interactive shell,它不需要与用户进行交互,执行完后它便会退出创建的Shell。
在interactive + login shell模式中,Shell首先会加载/etc/profile文件,然后再尝试依次去加载下列三个配置文件之一,一旦找到其中一个便不再接着寻找:
~/.bash_profile
~/.bash_login
~/.profile
2. 通过SSH直接执行远程命令和脚本
这种方式会使用Bash的non-interactive + non-login shell模式,它会创建一个shell,执行完脚本之后便退出,不再需要与用户交互。
no-login shell,顾名思义就是不是在登录Linux系统时启动的(比如你在命令行提示符上输入bash启动)。它不会去执行/etc/profile文件,而会去用户的HOME目录检查.bashrc并加载。
系统执行Shell脚本的时候,就是属于这种non-interactive shell。Bash通过BASH_ENV环境变量来记录要加载的文件,默认情况下这个环境变量并没有设置。如果有指定文件,那么Shell会先去加载这个文件里面的内容,然后再开始执行Shell脚本。
3. 结论
由此可见,如果要解决SSH远程执行命令时找不到自定义环境变量的问题,那么可以在登录用户的HOME目录的.bashrc中添加需要的环境变量。
转自:http://ghoulich.xninja.org/2017/05/09/how-to-find-env-vars-with-ssh-remote-exec-commands/
转载于:https://www.cnblogs.com/provence666/p/8638567.html
从零开始搭建系统2.4——Jenkins安装及配置相关推荐
- 从零开始搭建系统2.1——Nexus安装及配置
在安装配置Nexus时,请先确定您已经配置好jdk 1.创建目录 2.下载安装包 [root@localhost usr]# cd nexus 下载地址:https://www.sonatype.co ...
- mysql 1.4安装步骤_从零开始搭建系统1.4——MySql安装及配置
安装环境:CentOS7 64位 ,安装MySQL5.7 1.创建mysql目录 # 下载mysql源安装包 shell> wget http://dev.mysql.com/get/mysql ...
- 从零开始搭建系统1.1——CentOs安装
本篇主要是记录安装CentOs的过程,为什么会选择CentOs,没有过多的原因,主要是出于CentOs相对来说安装的人比较多, 以后有问题了方便查资料.本次安装是安装在一台笔记本上,WIN7+Cent ...
- 从零开始搭建系统3.2——微服务注册中心开发及部署
从零开始搭建系统3.2--微服务注册中心开发及部署 转载于:https://www.cnblogs.com/provence666/p/8638586.html
- [独孤九剑]持续集成实践(三)- Jenkins安装与配置(Jenkins+MSBuild+GitHub)
本系列文章包含: [独孤九剑]持续集成实践(一)- 引子 [独孤九剑]持续集成实践(二)– MSBuild语法入门 [独孤九剑]持续集成实践(三)- Jenkins安装与配置(Jenkins+MSBu ...
- Jenkins安装与配置
Jenkins安装与配置 原文出处:http://www.cnblogs.com/yangxia-test/p/4354328.html 一.Windows环境中安装Jenkins 在最简单的情况下, ...
- jenkins 安装及配置部署操作 (jenkins+svn+tomcat and jenkins+git+maven+tomcat)
jenkins 安装及配置部署操作 jenkins+svn+tomcat and jenkins+git+maven+tomcat jenkins rpm软件包下载地址: https://pkg.je ...
- 软件配置 | ios系统Clion下载、安装、配置环境
软件配置 软件配置 | ios系统Clion下载.安装.配置环境 软件配置 下载.安装 g++ Clion 调试 参考链接 下载.安装 调试 本文总结ios系统下Clion下载.安装.配置环境过程和可 ...
- Window系统上的Nacos安装与配置
Window系统上的Nacos安装与配置 下载 nacos下载github地址:https://github.com/alibaba/nacos/releases 下拉找到Assets 解压 各文件夹 ...
最新文章
- CentOS Docker安装配置部署Golang web helloworld
- matlab中fill函数的使用方法
- 基于NVIDIA显卡的硬编解码的一点心得 (完结)
- 重磅 | Dragonfly 晋升成为 CNCF 孵化项目
- * 图形例子,函数实现体会地址传递
- Microsoft Visual Studio使用NodeJS
- Linux学习笔记---Cortex-A7 常用汇编指令
- Swift on Linux —— 从源码开始安装
- BarTender的集成小结
- 微信修改运动步数卡密源码 每日自助修改
- Android性能优化学习记录(二)稳定性与内存优化
- 研究War3编辑器(2):地图编辑器基本操作
- 如果你觉得累,这三个“高内耗”行为,一定要戒掉!
- 独家专访英特尔AI布道师 | 通信工程到人工智能的高质量转型
- TwinCAT3 设置断电保持变量
- 网易2016笔试(3)
- aria2c 的基本配置,附带傻瓜式源码
- 虚拟主机++iRedMail搭建邮箱服务器
- 基于casbin的ABAC/RBAC权限实践
- 【数据库】对不起navicat我投入了DataGrip的怀抱
热门文章
- 韩语在线翻译图片识别_一键截图识别屏幕文字,支持实时翻译还能朗读
- 让应用程序支持emoji字符 廖雪峰 / 编程 / 2017-4-20 22:01 / 阅读: 5051 什么是emoji?就是这些表情和符号:
- 一文看懂大数据领域的六年巨变
- 内核管理 之 内核管理概述
- 267. Palindrome Permutation II --back tracking 以及palindrome 的优化方法ing
- K近邻算法的kd树实现
- Kafka 分区备份实战
- Codeforces Gym 100187D D. Holidays 排列组合
- css3 翻转和旋转的区别
- 海园帮忙写的JQUERY功能,实现了我们想要的,我觉得有点屌哟~~