jenkins安装及使用
jenkins安装及使用
Jenkins原理:
自动化部署 自动化部署
“自动化”的具体体现:向版本库提交新的代码后,应用服务器上自动部署,用户
或测试人员使用的马上就是最新的应用程序。
![image.png](https://upload-images.jianshu.io/upload_images/7100414-75a7ca1d5724ece0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
搭建上述持续集成环境可以把整个构建、部署过程自动化,很大程度上减轻工作量。
对于程序员的日常开发来说不会造成任何额外负担——自己把代码提交上去之后,服务
器上运行的马上就是最新版本——一切都发生在无形中。
Jenkins使用步骤:
1. 下载jenkins.War 网址https://jenkins.io/download/
2. 把jenkins.war放到tomcat的webapps下面.运行该tomcat.在游览器输入ip:port/jenkins
![image.png](https://upload-images.jianshu.io/upload_images/7100414-acf92074ae16dcac.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
初始密码 /root/.jenkins/secrets/initialAdminPassword文本里面的值
3. 选择安装方式:安装推荐的插件
![image.png](https://upload-images.jianshu.io/upload_images/7100414-0eef22c8a5842db2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-80bfc94ddfe6360e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-99dbd03187748614.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
4. 系统初始化配置
![image.png](https://upload-images.jianshu.io/upload_images/7100414-477f3e1aaa650725.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-78f3de025612a5df.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-9c22c3bfff43e1a5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
5、安装插件.大部分默认安装好啦(publish over SSH、SSH插件)。安装 Maven Integration plugin插件
![image.png](https://upload-images.jianshu.io/upload_images/7100414-57e7d3223af2ed4b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
6. 全局工具配置
![image.png](https://upload-images.jianshu.io/upload_images/7100414-5766948595447736.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-f2a442f3a896b32e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-d91acea57f8c595d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-c9099809ae90422e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-b98806896345feb4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
7. 配置push ssh
配置 SSH免登陆
ssh的配置可使用密钥,也可以使用密码,这里我们使用密钥来配置,在配置之前先配置好jenkins服务器和应用服务器的密钥认证 jenkins服务器上生成密钥对,使用ssh-keygen -t rsa命令
输入下面命令 一直回车,一个矩形图形出现就说明成功,在~/.ssh/下会有私钥id_rsa和公钥id_rsa.pub
ssh-keygen -t rsa
将jenkins服务器的公钥id_rsa.pub
中的内容复制到应用服务器 的~/.ssh/下的 authorized_keys
文件
ssh-copy-id -i id_rsa.pub 192.168.0.xx
chmod 644 authorized_keys
在应用服务器上重启ssh服务,service sshd restart
现在jenkins服务器可免密码直接登陆应用服务器
之后在用ssh B尝试能否免密登录B服务器,如果还是提示需要输入密码,则有以下原因
a. 非root账户可能不支持ssh公钥认证(看服务器是否有限制)
b. 传过来的公钥文件权限不够,可以给这个文件授权下 chmod 644 authorized_keys
c. 使用root账户执行ssh-copy-id -i ~/.ssh/id_rsa.pub 这个指令的时候如果需要输入密码则要配置sshd_config
vi /etc/ssh/sshd_config
PermitRootLogin no
修改完后要重启sshd服务
service sshd restart
最后,如果可以SSH IP 免密登录成功说明SSH公钥认证成功。
![image.png](https://upload-images.jianshu.io/upload_images/7100414-d5c95293dc49bceb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
安装Publish over SSH插件
![image.png](https://upload-images.jianshu.io/upload_images/7100414-ddfce1184d824458.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
8,开始新项目
![image.png](https://upload-images.jianshu.io/upload_images/7100414-53dfd29700173390.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
前提是装好插件不然没有该选项
![image.png](https://upload-images.jianshu.io/upload_images/7100414-66c60a97c6214300.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-fe6d4cb441f082e5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-42c72a095f8fac6b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-18c90fe1ee940650.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-cf1fa61c70355b2d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-f7cca131a3d6af51.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-f1cba1bf9e1b4276.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![image.png](https://upload-images.jianshu.io/upload_images/7100414-068758a4f2ca2597.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
作者:RoES —— 执着于理想,纯粹与当下
出处:https://www.cnblogs.com/roes/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。