写点什么

基于 docker 部署 jenkins(一)

用户头像
李日盛
关注
发布于: 2021 年 03 月 30 日

1. 安装 docker 和 docker-compose

首先是安装 docker:

# 在ubuntu内sudo apt install docker.io
复制代码

执行`sudo docker version`,查看 docker 的版本信息

Client: Version:           19.03.6 API version:       1.40 Go version:        go1.12.17 Git commit:        369ce74a3c Built:             Fri Dec 18 12:21:44 2020 OS/Arch:           linux/amd64 Experimental:      false
Server: Engine: Version: 19.03.6 API version: 1.40 (minimum version 1.12) Go version: go1.12.17 Git commit: 369ce74a3c Built: Thu Dec 10 13:23:49 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.3.3-0ubuntu1~18.04.4 GitCommit: runc: Version: spec: 1.0.1-dev GitCommit: docker-init: Version: 0.18.0 GitCommit:
复制代码

然后配置 docker 的镜像源为国内,加速镜像下载。我这边用的是腾讯云内部的镜像源:

执行`sudo vim /etc/docker/daemon.json`,内容如下:

{   "registry-mirrors": [       "https://mirror.ccs.tencentyun.com"  ]}
复制代码

保存,然后重启 docker:

sudo systemctl daemon-reloadsudo systemctl restart dockersudo docker info
复制代码


然后安装 docker-compose:

sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-composesudo chmod +x /usr/local/bin/docker-composesudo docker-compose version
复制代码

如果看到如下的返回,说明安装成功

docker-compose version 1.25.4, build 8d51620adocker-py version: 4.1.0CPython version: 3.7.5OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019
复制代码


下一步是将当前用户加入到 docker 用户组里面,方便后续操作:

sudo gpasswd -a ${USER} docker
复制代码

退出当前连接,重新登录系统,执行`docker info`。如果能够正常输出,说明当前用户加入 docker 用户组成功。

Client: Debug Mode: false
Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.6 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true ......
复制代码


2. 启动 jenkins

首先是创建好 jenkins 的目录

mkdir app/jenkins/jenkins-data -pcd app/jenkins
复制代码

创建`docker-compose.yml`这个文件,内容如下:

version: '3'services:  jenkins-master:    #privileged: true    container_name: jenkins-master    image: jenkinsci/blueocean:1.23.0    restart: always    user: root    ports:      - '8080:8080'      - '50000:50000'    volumes:      - $PWD/jenkins-data:/var/jenkins_home      - /var/run/docker.sock:/var/run/docker.sock      - /etc/localtime:/etc/localtime:ro
复制代码

执行`docker-compose up -d`

Creating network "jenkins_default" with the default driverPulling jenkins-master (jenkinsci/blueocean:1.23.0)...1.23.0: Pulling from jenkinsci/blueoceane7c96db7181b: Pull completef910a506b6cb: Pull completec2274a1a0e27: Pull completead6179c1f162: Pull complete8948507790d8: Pull complete7f023dd8e094: Pull complete015f995a850b: Downloading [==========================>                        ]  34.34MB/66.02MB2ed134814058: Download completeefd571beed1e: Download completee077c85d8ab4: Download completeb9d3f0bd0869: Download completed573fc03ec9e: Download complete38bf486c8db9: Download complete13185491d573: Pulling fs layer3950108948fd: Waiting
复制代码


查看进程是否正常`docker ps`

CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                              NAMES1ff69690f759        jenkinsci/blueocean:1.23.0   "/sbin/tini -- /usr/…"   27 seconds ago      Up 22 seconds       0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp   jenkins-master
复制代码

此时,执行`docker logs -f jenkins-master`,查看 jenkins 私钥:

......2021-03-30 11:05:24.377+0000 [id=27]    INFO    o.s.b.f.s.DefaultListableBeanFactory#preInstantiateSingletons: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@16b0724b: defining beans [filter,legacy]; root of factory hierarchy2021-03-30 11:05:24.654+0000 [id=27]    INFO    jenkins.install.SetupWizard#init: 
***************************************************************************************************************************************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.Please use the following password to proceed to installation:
88143346b06642698113c2xxxxxxxxxx
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
***************************************************************************************************************************************************************************************......
复制代码

将`88143346b06642698113c2xxxxxxxxxx`(我这边做了删改,以你那边为准)复制下来,打开浏览器,访问服务器的 IP:8080(云服务器的话请主要先打开防火墙端口),可以看到如下界面:

输入刚才复制的密码,然后点击下一步:

选择左边的安装推荐插件,进入安装界面


这段时间会有点长,请耐心等待

中间可能有插件安装失败,没关系,跳过到下一步:


输入你的用户名密码即可。我这边的用户名是 cicd。最后重启下系统:

刷新浏览器,登录系统,完成 jenkins 的初步安装。下一篇文章讲解 jenkins 的配置和 gitlab 打通


发布于: 2021 年 03 月 30 日阅读数: 9
用户头像

李日盛

关注

好架构=低成本+可实现 2018.01.22 加入

还未添加个人简介

评论

发布
暂无评论
基于docker部署jenkins(一)