1.1 前言

 

1.1.1 Jenkins功能

1.2 怎么理解持续集成、持续交付、持续部署呢?

1.2.1 持续集成

持续集成目的在产生以下效益如:

1.2.2 持续交付

1.2.3 持续部署

1.3 安装配置JENKINS

1.3.1 环境说明

推荐的硬件配置

系统环境

软件要求

1.3.2 安装Jenkins

软件下载

         下载相应的数据包即可,我这里使用的是jenkins-2.73.1-1.1.noarch.rpm

安装jenkins

启动jenkins

检查端口信息

RPM****包安装的内容

配置文件说明

1.3.3 web界面安装

         解锁Jenkins,密码从命令行中获取

 

         输入授权密码,然后点击下一步

         稍等一会来导安装插件选择的页面,将此页面关闭,在安装完成Jenkins后安装插件。

         关闭安装插件选择后,选择开始使用Jenkins

安装Jenkins****插件

         选择自己需要的插件进行安装即可,也可选择全部安装。

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong><span style="text-decoration: underline;"><span style="font-family: 等线; background: yellow;">至此</span><span style="background: yellow;">Jenkins</span></span></strong><strong><span style="text-decoration: underline;"><span style="font-family: 等线; background: yellow;">安装完成</span></span></strong>
</p>

<h3>
  <span id="134_Jenkins">1.3.4 Jenkins<span style="font-family: '微软雅黑',sans-serif;">配置</span></span>
</h3>

<p style="margin-left: 28.1pt; text-indent: -21.0pt;">
  1.&nbsp;<span style="font-family: '微软雅黑',sans-serif;">配置</span>jenkins<span style="font-family: '微软雅黑',sans-serif;">并发执行数量,提高执行效率</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192306823-988507252.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">系统管理</span> >> <span style="font-family: 等线;">系统设置</span> >> Maven<span style="font-family: 等线;">项目配置</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192315401-1452910755.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p style="margin-left: 28.1pt; text-indent: -21.0pt;">
  2.&nbsp;<span style="font-family: '微软雅黑',sans-serif;">设置邮件,能够在测试完成后,主动发邮件告知测试情况</span>
</p>

<p style="text-indent: 7.1pt;">
  <span style="font-family: 等线;">系统管理</span> >> <span style="font-family: 等线;">系统设置</span> >> Jenkins Location
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192328948-1079923173.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">向下拉,找到邮件通知,配置邮件的</span>smtp<span style="font-family: 等线;">信息</span>
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">配置完成后点击</span> Test configuration <span style="font-family: 等线;">进行测试,测试成功后,点击保存</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192337073-2130267234.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<h2>
  <span id="14_Jenkins">1.4 Jenkins<span style="font-family: '微软雅黑',sans-serif;">使用</span></span>
</h2>

<h3>
  <span id="141">1.4.1 <span style="font-family: '微软雅黑',sans-serif;">创建一个新的任务</span></span>
</h3>

<p style="margin-left: 21.0pt;">
  <span style="font-family: 等线;">创建一个新的任务</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192354042-830010134.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">输入项目的名称,选择构建只有分风格的软件</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192401401-883929242.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<h3>
  <span id="142_Jenkinsgitlab">1.4.2 <span style="font-family: '微软雅黑',sans-serif;">将</span>Jenkins<span style="font-family: '微软雅黑',sans-serif;">与</span>gitlab<span style="font-family: '微软雅黑',sans-serif;">联合</span></span>
</h3>

<p style="text-indent: 21.0pt;">
  gitlab<span style="font-family: 等线;">的详细安装方法参照:</span> http://www.cnblogs.com/clsn/p/7929958.html
</p>

<p>
  <span style="font-family: 等线;">创建公钥和私钥</span>
</p>

<div class="cnblogs_code">
  <pre>[root@Jenkins ~]<span style="color: #008000;">#</span><span style="color: #008000;"> ssh-keygen </span>

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:5SGYye8oxCKFJjddb4W8JC0RAQhBWCvuG8aZL8eMJs4 root@Jenkins The key's randomart image is: +—[RSA 2048]—-+ |==….=* .. | |…o oo==. | |+.= . =++.o | |++ o o.+ . | |… o S . | |o.oo o | | B+ . . . | |++++ . | |+Eo. | +—-[SHA256]—–+ [root@Jenkins ~]# cat .ssh/id_rsa.pub [root@Jenkins ~]# cat .ssh/id_rsa

<p>
  <strong><em><span style="font-family: 等线;">在</span>gitlab</em></strong><strong><em><span style="font-family: 等线;">中添加公钥</span>id_rsa.pub</em></strong>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192426354-684435689.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  <strong><em><span style="font-family: 等线;">在</span>jenkins</em></strong><strong><em><span style="font-family: 等线;">中添加私钥</span>id_rsa</em></strong>
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">在首页中,点击项目名称的下拉监听</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192438933-1952523900.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">选择源码管理,先将</span>gitlab<span style="font-family: 等线;">的项目地址复制过来</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192448667-1624864487.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">选择</span>SSH<span style="font-family: 等线;">密钥和证书,然后选择直接输入,将私钥复制到下框中即可</span>
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">添加完成后,点击保存</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192456448-898723804.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">选择刚才创建的证书,完成后,选择构建</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192504808-1018752536.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  <strong><em><span style="text-decoration: underline;"><span style="font-family: 等线;">选择构建</span></span></em></strong>
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">拉到最底部,选择使用</span>shell<span style="font-family: 等线;">脚本</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192512214-519514729.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">脚本内容</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192518948-2060407751.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">创建测试环境</span>
</p>

<div class="cnblogs_code">
  <pre>[root@Jenkins ~]<span style="color: #008000;">#</span><span style="color: #008000;"> mkdir  -p /data/www</span>

[root@Jenkins ~]# chown -R jenkins.jenkins /data/

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">选择构建后的操作,让每次构建完成后都将结果发送给管理员</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192536214-662773016.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<h3>
  <span id="143">1.4.3 <span style="font-family: '微软雅黑',sans-serif;">测试手动集成</span></span>
</h3>

<p style="text-indent: 21.0pt;">
  <span style="font-family: 等线;">回到主页,点击右侧的按钮进行测试</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192552839-1669748311.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p style="text-indent: 21.0pt;">
  <span style="font-family: 等线;">部署完成</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192558886-1289295614.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p style="text-align: justify; text-justify: inter-ideograph;">
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">查看部署日志</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192606261-1352544543.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p style="text-align: justify; text-justify: inter-ideograph; text-indent: 21.0pt;">
  <span style="font-family: 等线;">查看部署结果</span>
</p>

<div class="cnblogs_code">
  <pre>[root@Jenkins ~]<span style="color: #008000;">#</span><span style="color: #008000;"> ll /data/www/</span>

总用量 4 -rw-r–r– 1 jenkins jenkins 4 11月 30 21:22 flag -rw-r–r– 1 jenkins jenkins 0 11月 30 21:22 README.md

<h3>
  <span id="144_gitlabJenkins">1.4.4 <span style="font-family: '微软雅黑',sans-serif;">自动测试(</span>gitlab<span style="font-family: '微软雅黑',sans-serif;">主动通知</span>Jenkins<span style="font-family: '微软雅黑',sans-serif;">测试)</span></span>
</h3>

<p style="text-indent: 7.1pt;">
  <span style="font-family: 等线;">该功能会使用到一个插件</span> <strong>gitlab plugin</strong>
</p>

<p style="text-indent: 7.1pt;">
  <span style="font-family: 等线;">配置</span>gitlab<span style="font-family: 等线;">认证</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192624433-157495203.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">添加一个新的凭证</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192631683-372513748.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">从</span>gitlab<span style="font-family: 等线;">的设置中将</span> token<span style="font-family: 等线;">复制过来</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192639495-710452368.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">将复制的</span>token<span style="font-family: 等线;">粘贴到</span>api token<span style="font-family: 等线;">中,点</span>ok
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192651667-606045732.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">在系统配置中找到</span><strong>Gitlab</strong>&nbsp;<span style="font-family: 等线;">将信息进行填写,</span>Credentials <span style="font-family: 等线;">选择刚刚创建对的即可</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192700729-449236192.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p style="text-indent: 21.0pt;">
  <span style="font-family: 等线;">打开项目,编辑项目的构建触发器</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192710183-1810385177.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p style="text-indent: 21.0pt;">
  <span style="font-family: 等线;">在</span>gitlab<span style="font-family: 等线;">上配置连接</span>jenkins <span style="font-family: 等线;">,将</span>Jenkins<span style="font-family: 等线;">的</span>Secret token <span style="font-family: 等线;">与</span>Build URL <span style="font-family: 等线;">复制到</span>gitlab<span style="font-family: 等线;">中</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192718448-1860661215.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">保存之前先进程测试,测试成功后进行保存</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192726448-895582851.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="font-family: 等线;">在</span>gitlab<span style="font-family: 等线;">进行上传文件,可以测试。</span>
</p>

<p style="text-indent: 21.0pt;">
  <span style="font-family: 等线;">在日志中显示是</span> <span style="font-size: 10.5pt;">Started </span><span style="font-size: 10.5pt; font-family: 'Cambria Math',serif;">​</span><span style="font-size: 10.5pt;">by </span><span style="font-size: 10.5pt; font-family: 'Cambria Math',serif;">​</span><span style="font-size: 10.5pt;">GitLab </span><span style="font-size: 10.5pt; font-family: 'Cambria Math',serif;">​</span><span style="font-size: 10.5pt;">push </span><span style="font-size: 10.5pt; font-family: 'Cambria Math',serif;">​</span><span style="font-size: 10.5pt;">by </span><span style="font-size: 10.5pt; font-family: 'Cambria Math',serif;">​</span><span style="font-size: 10.5pt;">Administrator</span>&nbsp;<span style="font-family: 等线;">即表示自动集成成功</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192733104-716903443.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<h2>
  <span id="15">1.5 <span style="font-family: '微软雅黑',sans-serif;">代码上线方案</span></span>
</h2>

<h3>
  <span id="151">1.5.1 <span style="font-family: '微软雅黑',sans-serif;">早期手动部署代码</span></span>
</h3>

<p style="margin-left: 19.25pt;">
  <span style="font-family: 等线;">纯手动</span>scp<span style="font-family: 等线;">上传代码。</span>
</p>

<p style="margin-left: 19.25pt;">
  <span style="font-family: 等线;">纯手动登陆,</span>Git pull <span style="font-family: 等线;">或者</span>SVN update<span style="font-family: 等线;">。</span>
</p>

<p style="margin-left: 19.25pt;">
  <span style="font-family: 等线;">纯手动</span>xftp<span style="font-family: 等线;">上传代码。</span>
</p>

<p style="margin-left: 19.25pt;">
  <span style="font-family: 等线;">开发发送压缩包,</span>rz<span style="font-family: 等线;">上传,解压部署代码。</span>
</p>

<p style="margin-left: 19.25pt;">
  <strong><span style="text-decoration: underline;"><span style="font-family: 等线; background: yellow;">缺点:</span></span></strong>
</p>

<p style="margin-left: 38.5pt;">
  <span style="font-family: 等线;">全程运维参与,占用大量时间。</span>
</p>

<p style="margin-left: 38.5pt;">
  <span style="font-family: 等线;">如果节点多,上线速度慢。</span>
</p>

<p style="margin-left: 38.5pt;">
  <span style="font-family: 等线;">人为失误多,目录管理混乱。</span>
</p>

<p style="margin-left: 38.5pt;">
  <span style="font-family: 等线;">回滚不及时,或者难以回退。</span>
</p>

<p style="text-indent: 21.0pt;">
  <strong><span style="text-decoration: underline;"><span style="font-family: 等线; background: yellow;">上线方案示意图:</span></span></strong>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192743261-564020995.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<h3>
  <span id="152">1.5.2 <span style="font-family: '微软雅黑',sans-serif;">合理化上线方案</span></span>
</h3>

<p style="text-indent: 7.1pt;">
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<span style="font-family: 等线;">、开发人员需在个人电脑搭建</span>LAMP<span style="font-family: 等线;">环境测试开发好的网站代码,并且在办公室或</span> IDC<span style="font-family: 等线;">机房的测试环境测试通过,最好有专职测试人员。</span>
</p>

<p style="text-indent: 21.0pt;">
  2<span style="font-family: 等线;">、程序代码上线要规定时间,例如:三天上线一次,如网站需经常更新可每天下午</span> 17<span style="font-family: 等线;">点上线,这个看网站业务性质而定,原则就是影响用户体验最小。</span>
</p>

<p style="text-indent: 21.0pt;">
  3<span style="font-family: 等线;">、代码上线之前需备份,网站程序出了问题方便回退,另外,从上线技巧上讲,上传代码时尽可能先传到服务器网站临时目录,传完整后一步</span>mv<span style="font-family: 等线;">过去,或者通过</span>In<span style="font-family: 等线;">做软链接</span>&mdash; <span style="font-family: 等线;">线上更新代码的思路。如果严格更新,把应用服务器从集群节点平滑下线,然后更新。</span>
</p>

<p style="text-indent: 21.0pt;">
  4<span style="font-family: 等线;">、尽量由运维人员管理上线,对于代码的功能性,开发人员更在意,而对于代码的性</span> <span style="font-family: 等线;">能优化和上线后服务器的稳定,运维更在意服务器的稳定,因此,如果网站宕机问题归运维管,就要让运维上线,这样更规范科学。否则,开发随意更新,出了问题运维负责,这样就错了,运维永远无法抬头。</span>
</p>

<p style="text-align: center;" align="center">
  <img data-original="https://clsn.io/wp-content/uploads/2018/03/1190037-20171201192752386-122301749.png" src="/wp-content/themes/clsn-003/img/blank.gif" alt="Jenkins与网站代码上线解决方案" alt="" />
</p>

<p style="text-align: center;" align="center">
  <strong><span style="font-family: 等线;">图&middot;</span>web</strong><strong><span style="font-family: 等线;">代码规范化上线流程图</span></strong>
</p>

<h3>
  <span id="153">1.5.3 <span style="font-family: '微软雅黑',sans-serif;">大型企业上线制度和流程</span></span>
</h3>

<p style="text-indent: 19.25pt;">
  <strong><span style="background: yellow;">JAVA</span></strong><strong><span style="font-family: 等线; background: yellow;">代码环境</span></strong><strong><span style="font-family: 等线;">,</span></strong><span style="font-family: 等线;">上线时,有数台机器同时需要更新或者分批更新</span> <span style="font-family: 等线;">&darr;</span>
</p>

<p style="text-indent: 19.25pt;">
  &nbsp;
</p>

<div class="cnblogs_code">
  <pre>1<span style="color: #000000;">).本地开发人员取svn代码。当天上线提交到trunk,否则,长期项目单开分支开发,然后在合并主线(trunk)

2).办公内网开发测试时,由开发人员或配置管理员通过部署平台jenkins实现统一部署,(即在部署平台上控制开发机器从svn取代码,编译,打包,发布到开发机,包名如idc_dep.war). 3).开发人员通知或和测试人员一起测试程序,没有问题后,由配置管理员打上新的tag标记。这里要注意,不同环境的配置文件是随代码同时发布的。 4).配置管理员,根据上一步的tag标记,checkout出上线代码,并配置好IDC测试环境的所有配置,执行编译,打包(mvn,ant)(php不需要打包),然后发布到IDC内的统一分发服务器。 5).配置管理员或SA上线人员,把分发的程序代码内容推送到相关测试服务器(包名如idc_test.war),然后通知开发及测试人员进行测试。如果有问题向上回退,继续修改。 6).如果IDC测试没有问题,继续打好tag标记,此时,配置管理员,根据上步的tag标记,checkout出测试好的代码,并配置好IDC正式环境的所有配置,执行编译,打包(mvn,ant)(php不需要打包),然后发布到IDC内的统一分发服务器主机,准备批量发布。 7).配置管理员或SA上线人员,把分发的内容推送到相关正式服务器(包名如idc_product.war),然后通知开发及测试人员进行测试。如果有问题直接发布回滚指令。  

<p>
  &nbsp;   IDC<span style="font-family: 等线;">正式上线的过程对于</span>JAVA<span style="font-family: 等线;">程序,可以是</span><span style="text-decoration: underline;"><span style="background: yellow;">AB</span></span><span style="text-decoration: underline;"><span style="font-family: 等线; background: yellow;">组分组上线</span></span><span style="font-family: 等线;">的思路,即平滑下线一半的服务器,然后发布更新代码,重启测试,无问题后,挂上更新后的服务器,同时再平滑下线另一半的服务器,然后发布更新代码测试(或者直接发布后,重启,挂上线)</span>
</p>

<h3>
  <span id="154_php">1.5.4 php<span style="font-family: '微软雅黑',sans-serif;">程序代码上线的具体方案</span></span>
</h3>

<p>
  &nbsp;  <span style="font-family: 等线;">对于</span>PHP<span style="font-family: 等线;">上线方法:发布代码时(也需要测试流程)可以直接发布到正式线临时目录</span> <span style="font-family: 等线;">,然后</span>mv<span style="font-family: 等线;">或更改</span>link<span style="font-family: 等线;">的方式发布到正式上线目录</span> <span style="font-family: 等线;">,不需要重启</span>http<span style="font-family: 等线;">服务。这是新朗,赶集的上线方案。</span>
</p>

<h3>
  <span id="155_JAVA">1.5.5 JAVA<span style="font-family: '微软雅黑',sans-serif;">程序代码上线的具体方案</span></span>
</h3>

<p style="text-indent: 21.0pt;">
  <span style="font-family: 等线;">对于</span>java<span style="font-family: 等线;">上线方法</span>:<span style="font-family: 等线;">较大公司需要分组平滑上线(如从负载均衡器上摘掉一半的服务器),发布代码后,重启服务器测试,没问题后,挂上上好线的一半,再下另外一半。如果前端有</span>DNS<span style="font-family: 等线;">智能解析,上线还可以分地区上线若干服务器,逐渐普及到全国的服务器,这个被称为&ldquo;灰度发布&rdquo;,在后面门户网站上线的知识里我们在讲解。</span>
</p>

<h3>
  <span id="156">1.5.6 <span style="font-family: '微软雅黑',sans-serif;">代码上线解决方案注意事项</span></span>
</h3>

<div class="cnblogs_Highlighter">
  <pre class="brush:fsharp;gutter:false;"> 1).上线的流程里,办公室测试环境-->IDC测试环境-->正式生产环境,所有环境中的所有软件均应版本统一,其次尽量单一,否则将后患无穷,开发测试成功,IDC测试就可能有问题(如:操作系统,web服务器,jdk,php,tomcat,resin等版本)

2).开发团队小组办公内部测试环境测试(该测试环境属于开发小组维护,或定时自动更新代码),代码有问题返回给某开发人员重新开发。 3).有专门的测试工程师,程序有问题直接返回给开发人员(此时返回的一般为程序的BUG,称为BUG库),无问题进行IDC测试 4).IDC测试由测试人员和运维人员参与,叫IDCtest,进行程序的压力测试,有问题直接返回给开发人员,无问题进行线上环境上线。 5).数台服务器代码分发上线方案举例(JAVA程序)    A:假设同业务服务器有6台,将服务器分为A,B两组,A组三台,B组三台,先对A组进行从负载均衡器上平滑下线,B组正常提供服务,避免服务器因上线影响业务。    B:下线过程是通过脚本将A组服务器从RS池(LVS,NGINX,HAPROXY,F5等均有平滑方案)中踢出,避免负裁均衡器将请求发送给A组服务器(此时的时间应该为网站流量少时,一般为晚上)    C:将代码分发到A组服务器的站点目录下,对A组服务器上线并重启服务,并由专业的测试人员进行访问测试,测试成功后,挂上A组的服务器,同时下线B组服务器,B组代码上线操作测试等和A组相同,期间也要观察上线提供服务的服务器状况,有问题及时回滚。 6).特别说明:如果是PHP程序,则上线可以简单化,直接将上线代码(最好全量)发布到所有上线服务器的特定目录后,分发完成后,一次性mv或ln到站点目录,当然测试也是少不了的。测试除了人员测试外,还有各种测试脚本测试各个相关业务接口。 7).大多数门户公司的前端页面都已经静态化或者cache了,因此,动态的部分访问平时就不会特别多,流量低谷时就更少了。再加上是平滑上下线,因此基本上

<h2>
  <span id="16">1.6 <span style="font-family: '微软雅黑',sans-serif;">参考文献</span></span>
</h2>

<div style="border: solid windowtext 2.0pt; padding: 1.0pt 4.0pt 1.0pt 4.0pt; background: #F2F2F2;">
  <p style="margin-left: 21pt; text-indent: -21pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">
    1.<span style="font-variant-numeric: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';">&nbsp;&nbsp; </span>https://zh.wikipedia.org/wiki/<span style="font-family: '微软雅黑',sans-serif;">持續整合</span>
  </p>
  
  <p style="margin-left: 21pt; text-indent: -21pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">
    2.<span style="font-variant-numeric: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';">&nbsp;&nbsp; </span>https://www.zhihu.com/question/23444990/answer/89426003
  </p>
  
  <p style="margin-left: 21pt; text-indent: -21pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">
    3.<span style="font-variant-numeric: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';">&nbsp;&nbsp; </span>https://www.mindtheproduct.com/2016/02/what-the-hell-are-ci-cd-and-devops-a-cheatsheet-for-the-rest-of-us/
  </p>
  
  <p style="margin-left: 21pt; text-indent: -21pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">
    4.<span style="font-variant-numeric: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';">&nbsp;&nbsp; </span>http://t.cn/RYKgMtc&nbsp;自动化部署
  </p>
  
  <p style="margin-left: 21pt; text-indent: -21pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">
    5.<span style="font-variant-numeric: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';">&nbsp;&nbsp; </span>http://www.cnblogs.com/can-H/articles/7346724.html
  </p>
  
  <p style="margin-left: 21pt; text-indent: -21pt; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;">
    6.<span style="font-variant-numeric: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman';">&nbsp;&nbsp; </span>https://www.abcdocker.com/abcdocker/2041
  </p>
</div>

<p>
  &nbsp;
</p>

<div id="toc_container" class="toc_white have_bullets">
  <ul class="toc_list">
    <li>
      <a href="#11">1.1 前言</a><ul>
        <li>
          <a href="#111_Jenkins">1.1.1 Jenkins功能</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#12">1.2 怎么理解持续集成、持续交付、持续部署呢?</a><ul>
        <li>
          <a href="#121">1.2.1 持续集成</a>
        </li>
        <li>
          <a href="#122">1.2.2 持续交付</a>
        </li>
        <li>
          <a href="#123">1.2.3 持续部署</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#13_JENKINS">1.3 安装配置JENKINS</a><ul>
        <li>
          <a href="#131">1.3.1 环境说明</a>
        </li>
        <li>
          <a href="#132_Jenkins">1.3.2 安装Jenkins</a>
        </li>
        <li>
          <a href="#133_web">1.3.3 web界面安装</a>
        </li>
        <li>
          <a href="#134_Jenkins">1.3.4 Jenkins配置</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#14_Jenkins">1.4 Jenkins使用</a><ul>
        <li>
          <a href="#141">1.4.1 创建一个新的任务</a>
        </li>
        <li>
          <a href="#142_Jenkinsgitlab">1.4.2 将Jenkins与gitlab联合</a>
        </li>
        <li>
          <a href="#143">1.4.3 测试手动集成</a>
        </li>
        <li>
          <a href="#144_gitlabJenkins">1.4.4 自动测试(gitlab主动通知Jenkins测试)</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#15">1.5 代码上线方案</a><ul>
        <li>
          <a href="#151">1.5.1 早期手动部署代码</a>
        </li>
        <li>
          <a href="#152">1.5.2 合理化上线方案</a>
        </li>
        <li>
          <a href="#153">1.5.3 大型企业上线制度和流程</a>
        </li>
        <li>
          <a href="#154_php">1.5.4 php程序代码上线的具体方案</a>
        </li>
        <li>
          <a href="#155_JAVA">1.5.5 JAVA程序代码上线的具体方案</a>
        </li>
        <li>
          <a href="#156">1.5.6 代码上线解决方案注意事项</a>
        </li>
      </ul>
    </li>
    
    <li>
      <a href="#16">1.6 参考文献</a>
    </li>
  </ul>
</div>