zoukankan      html  css  js  c++  java
  • Jenkins介绍和安装及配合GitLab代码自动部署

    Jenkins是什么?

    1. 基于JAVA的开源的自动化系统平台
    2. 加速自动化CI,CD任务及流水线,所有类型的任务:构建,测试,部署等
    3. 丰富的插件生态系统支持功能扩展,1400+插件和SCM,测试,通知,报告,Artfact,触发,外部集成等
    4. 基于Web的管理和使用界面
    5. 源于Hudson
    6. 官网文档:https://jenkins.io/doc/
    Jenkins系统架构图

    用docker环境部署Jenkins

    一,安装docker-ce版本

    1.1 删除之前版本的Docker

    sudo yum remove docker docker-common docker-selinux docker-engine

    1.2 安装一些依赖

    sudo yum install -y yum-utils device-mapper-persistent-data lvm2

    1.3 下载repo文件

    wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo

    1.4 把软件仓管地址替换为 TUNA:

    sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

    1.5 安装

    sudo yum makecache fast
    sudo yum install docker-ce

    参考文档:https://mirrors.tuna.tsinghua.edu.cn/help/docker-ce/

    1.6 安装完成后可以使用:dock version 命令查看docker信息

    [root@linux-node1 ~]# docker version
    Client:
     Version:      17.09.0-ce
     API version:  1.32
     Go version:   go1.8.3
     Git commit:   afdb6d4
     Built:        Tue Sep 26 22:41:23 2017
     OS/Arch:      linux/amd64
    
    Server:
     Version:      17.09.0-ce
     API version:  1.32 (minimum version 1.12)
     Go version:   go1.8.3
     Git commit:   afdb6d4
     Built:        Tue Sep 26 22:42:49 2017
     OS/Arch:      linux/amd64
     Experimental: false
    二,安装docker-compose

    2.1 先确认完成docker环境安装,再执行此步骤

    2.2 参考文档:

    https://docs.docker.com/compose/install/

    2.3 以linux为例:

           2.3.1下载docker compose执行文件 

    sudo curl -L https://github.com/docker/compose/releases/download/1.17.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

          2.3.2 添加执行权限

    sudo chmod +x /usr/local/bin/docker-compose

         2.3.3 验证结果

    docker-compose --version
    docker-compose version 1.17.0, build 1719ceb
    三,下载镜像文件

    3.1 配置国内docker镜像加速,国内拉取官方docker镜像速度较慢

    [root@linux-node1 data]# more /etc/docker/daemon.json 
    {"registry-mirrors": ["http://4c7d9402.m.daocloud.io"]}

    3.2 下载docker的Jenkins镜像

    docker pull jenkins:latest

    3.3 下载gitlab-ce(如果需要可以下载,可选择)

    docker pull gitlab/gitlab-ce:latest

    3.4 下载daoker的sonarqube(如果需要可以下载,可选择)

    docker pull sonarqube:latest

    3.5 验证docker镜像下载结果

    [root@linux-node1 data]# docker images
    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
    gitlab/gitlab-ce    latest              733cc235d0c0        3 days ago          1.38GB
    sonarqube           latest              c1637bd4502f        12 days ago         934MB
    jenkins             latest              3f08dc4f3f5d        3 weeks ago         809MB

    3.6 启动jenkins的docker镜像

    docker run -it --name jenkinsci0001 -v $HOME/jenkins:/var/  -p 8888:8080 -p 55000:50000 -p 45000:45000 jenkins:latest 

    在控制台显示信息如下

    ...
    org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@6b4ba523]: org.springframework.beans.factory.support.DefaultListableBeanFactory@ed6a5eb
    Nov 26, 2017 5:29:44 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@ed6a5eb: defining beans [authenticationManager]; root of factory hierarchy
    Nov 26, 2017 5:29:45 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
    INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@6fd126d1: display name [Root WebApplicationContext]; startup date [Sun Nov 26 05:29:45 UTC 2017]; root of context hierarchy
    Nov 26, 2017 5:29:45 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@6fd126d1]: org.springframework.beans.factory.support.DefaultListableBeanFactory@62e4ea3c
    Nov 26, 2017 5:29:45 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@62e4ea3c: defining beans [filter,legacy]; root of factory hierarchy
    Nov 26, 2017 5:29:46 AM jenkins.install.SetupWizard init
    INFO: 
    
    *************************************************************
    *************************************************************
    *************************************************************
    
    Jenkins initial setup is required. An admin user has been created and a password generated.
    Please use the following password to proceed to installation:
    
    da4d937a40144c53a05e4383273c902b
    
    This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
    
    *************************************************************
    *************************************************************
    *************************************************************
    
    --> setting agent port for jnlp
    --> setting agent port for jnlp... done
    Nov 26, 2017 5:30:15 AM hudson.model.UpdateSite updateData
    INFO: Obtained the latest update center data file for UpdateSource default
    Nov 26, 2017 5:30:17 AM hudson.model.DownloadService$Downloadable load
    INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
    Nov 26, 2017 5:30:21 AM hudson.model.DownloadService$Downloadable load
    INFO: Obtained the updated data file for hudson.tools.JDKInstaller
    Nov 26, 2017 5:30:21 AM hudson.model.AsyncPeriodicWork$1 run
    INFO: Finished Download metadata. 42,015 ms
    Nov 26, 2017 5:30:48 AM hudson.model.UpdateSite updateData
    INFO: Obtained the latest update center data file for UpdateSource default
    Nov 26, 2017 5:30:48 AM hudson.WebAppMain$3 run
    INFO: Jenkins is fully up and running
    View Code

    3.7 打开登陆界面,根据提示输入上面的显示的密码

    3.8 选择默认推荐安装的插件

    3.9 等待插件安装

    3.10 设置账户密码

    ....

    3.11 进入页面

    四,使用yum安装部署Jenkins

    4.1 添加源

    wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo 

    4.2 导入key

     rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

    4.3 yum安装 jenkins

    yum install jenkins -y

    为什么要使用Jenkins?


    在2015年前我们公司上线流程是:

    1.测试环境权限开发给开发人员,开发调试看日志拉代码都是开发自己登陆到测试机上面操作

    2.开发提测,QA通过后,开发人员发邮件到ops抄送其他相关部门申请上线,需要开发主管确认等,ops再登服务器拉取发布代码到生产环境(就是说项目定在几点上或者延迟上ops都得苦逼的等着)

    3.ops发布完成回复邮件(每星期都会收到大量的上线邮件)

    4.QA回滚测试

    在2016年ops和其他同行聊天抱怨的时候,人家说你们怎么不用Jenkins。那时候因为年少无知Jenkins是什么鬼啊,然后回来就开始研究,直到下半年就开始慢慢都用上了,现在是:

    测试环境:收回开发人员登录系统权限,代码自动触发更新,日志通过ELK实时查看

    生产环境:ops基本不参与上线项目,和开发负责人确认哪些开发人员可以有哪些项目的上线权限,ops授权开发人员上线,服务器上面有代码更新会脚本自动发邮件到ops。

                     具体开发内部怎么上线由开发负责人决定,当业务有问题的时候ops再根据Jenkis的上线记录排查问题,ops可以节省大量时间去其它维护工作。

    配置参考图片


    相关的项目:php  java .net

    版本库有:svn gitlab

    服务器系统:CentOS Windows


     Jenkins系统设置:需要在Jenkins服务器上安装一些工具软件,然后再web界面添加环境变量等信息,这里用的ssh秘钥和服务器同步代码

     

     

    配置Jenkins账号和Gitlab账号信息有关联

     设置Jenkins专有用户数据库

    Androids apk打包配置

    Java编译发布配置

     

    项目构建情况,测试环境在Gitlab的trunk分钟,开发人员提交代码到trunk就会触发Jenkins拉取代码发布到业务服务器上面

    php正式环境需要开发主管自己登陆到Jenkins进行点击发布

    用户权限管理

    用户分组及项目创建

    用户项目权限分配

    测试环境,自动构建

    正式环境master分支,开发主管点击构建发布

    GitLab8.9  Webhooks设置

    使用Jenkins的里面授权的账号,GitLab的只读权限就可以

     Windows配置Jenkins让.NET项目自动编译发布

    定时自动发版工具
    插件
    MSBuild Plugin
    subversion.hpi
    Global Tool Configuration
          MSBuild
              v4.0.30319
              C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe
    任务
      byexx
      SVN
         svn://192.168.xx.xx/boxx/Byexx.BOxx.Serxx@HEAD  
      Build periodically
      Poll SCM
         * * * * *
      
      v4.0.30319
      Byexxx.BOxx.API.sln
      /m /t:Rebuild /property:Configuration=Release;TargetFrameworkVersion=v3.5;OutputPath=D:xx_sitesxx.comin
    
    1.编译完的路径
    2.svn://192.168.xx.xx/boxx/Byexx.BOxx.Serxx@HEAD
    View Code

    插件安装,subversion或者git取决根据代码服务器实际情况选择安装即可

    Global Tool Configuration添加MSBuild工具

    配置项目

     测试环境代码拉取及日程表

    构建及代码发布目录配置

    每分钟轮询如测试环境有新代码提前就触发代码拉取编译发

     来自网络

  • 相关阅读:
    Static了解和复习继承。
    复习篇1.对象和封装
    第一章笔记
    A + B Problem II
    Number Sequence
    Fibonacci Again
    8615 快乐
    8635 气球
    大牛之路II
    8617 阶乘数字和
  • 原文地址:https://www.cnblogs.com/xiewenming/p/7490828.html
Copyright © 2011-2022 走看看