云原生下的CICD-3件套快速搭建合集:jenkins+harbor+gitlab

本文涉及的产品
云原生内存数据库 Tair,内存型 2GB
云数据库 Redis 版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: 云原生下的CICD-3件套快速搭建合集:jenkins+harbor+gitlab
  1. 使用docker容器启动jenkins
docker run -d -u root --name jenkins-ser01 --restart=always -p 80:8080 -p 50000:50000 -v /data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean

需要注意:

  • /data 是宿主机的数据目录,请选用容量足够、性能好的文件系统
  • 必须显示声明-u root,使用root启动容器,否则容器不能正常启动
  • 宿主机的/var/run/docker.sock请确保存在,或请确保路径是正确的
  1. 访问 http://192.168.11.252/login?from=%2F

  1. 解锁Jenkins 对应宿主机上的数据路径是/data/secrets/initialAdminPassword
[root@svr-jenkins ~]# cat /data/secrets/initialAdminPassword 
bb7b64bf187048f1b7850208e9a2d9a4

将bb7b64bf187048f1b7850208e9a2d9a4复制到解锁页面进行解锁,然后下一步

  1. 首次插件安装

  • 安装建议的插件:安装推荐的一组插件,这些插件基于最常见的用例.
  • 选择要安装的插件:选择安装的插件集。当你第一次访问插件选择页面时,默认选择建议的插件。

小白可以选择安装建议的插件,老司机可以选择选择要安装的插件

如果总是有安装失败的插件,可先点击继续跳过,后续再切换下载源地址,再进行安装

  1. 继续接下来的步骤 创建管理账号

然后选择保存并完成继续

实例配置,可以保持默认

然后选择保存并完成继续

最后选择重启

点击了重启后,发现容器停止了,拉起即可。

  1. 拉起容器jenkins-ser01
[root@svr-jenkins ~]# docker start jenkins-ser01
jenkins-ser01
[root@svr-jenkins ~]#

提示!启动容器时,可以加上 --restart=always,当容器stop掉的时候会自动拉起容器

最后,即可成功进入到登录页面!用创建好的第一个管理员账号登录即可


Harbor官方网站:http://vmware.github.io/harbor/ Harbor

源码地址:https://github.com/vmware/harbor

硬件要求:

  • 最低要求 2c/4m/40g
  • 推荐 4c/8m/160g

Harbor所需软件:

  • vmware harbor (镜像仓库)
  • docker ce (docker容器引擎,社区版)
  • docker compose (批量管理容器,高效管理主机上的docker容器)

安装方式

  • 在线安装
  • 离线安装(本文主要简单讲解离线安装的全过程,使用docker-compose的方式安装)

开始离线安装

  1. 下载harbor离线包
wget https://github.com/goharbor/harbor/releases/download/v2.6.2/harbor-offline-installer-v2.6.2.tgz
  1. 安装最新版本的Docker Engine、containerd和Docker Compose
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
yum makecache fast
yum install docker-ce docker-compose-plugin -y
ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin/
  1. 解压
[root@svr-harbor ~]# tar -zxf harbor-offline-installer-v2.6.2.tgz
[root@svr-harbor ~]# cd harbor
[root@svr-harbor harbor]#
  1. 修改下面2处配置,在这里,为了简单方便,其他配置保持默认
[root@svr-harbor ~]# cd harbor
[root@svr-harbor harbor]# cp -a harbor.yml.tmpl harbor.yml
[root@svr-harbor harbor]# egrep -v "#|^$" harbor.yml
# 内容如下:
hostname: 192.168.11.250
http:
  port: 80
data_volume: /data

数据目录请选择容量足够、性能好的文件系统

  1. 注释掉harbor.yml中和https有关的配置(内网就不配置https了)
#https:
#  port: 443
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path
  1. 开始初始化
[root@svr-harbor harbor]# ./prepare
  1. 执行安装脚本
[root@svr-harbor harbor]# ./install.sh

注意:亲测,请确保防火墙是打开的状态,因为在install的过程中会自动配置防火墙策略,如果防火墙是停止的,将会install失败。安装成功后,最后会提示:Harbor has been installed and started successfully.----

  1. 查看数据目录
[root@svr-harbor ~]# cd /data/
[root@svr-harbor data]# ls
ca_download  database  job_logs  redis  registry  scandata_exports  secret
[root@svr-harbor data]#

安装完成后,已经在指定的数据目录下自动创建了所需的目录,这就是保存任何数据的目录

  1. 查看运行的容器
[root@svr-harbor ~]# cd harbor
[root@svr-harbor harbor]# docker-compose ps
NAME                COMMAND                  SERVICE             STATUS              PORTS
harbor-core         "/harbor/entrypoint.…"   core                running (healthy)   
harbor-db           "/docker-entrypoint.…"   postgresql          running (healthy)   
harbor-jobservice   "/harbor/entrypoint.…"   jobservice          running (healthy)   
harbor-log          "/bin/sh -c /usr/loc…"   log                 running (healthy)   127.0.0.1:1514->10514/tcp
harbor-portal       "nginx -g 'daemon of…"   portal              running (healthy)   
nginx               "nginx -g 'daemon of…"   proxy               running (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp
redis               "redis-server /etc/r…"   redis               running (healthy)   
registry            "/home/harbor/entryp…"   registry            running (healthy)   
registryctl         "/home/harbor/start.…"   registryctl         running (healthy)   
[root@svr-harbor harbor]#

注意要进去harbor目录下,需要在docker-compose.yml配置文件所在的目录下才能正确执行docker compose命令

  1. 访问

访问80端口即可访问到UI,默认的账号是admin,默认的密码是Harbor12345

  1. 常用管理
# 停止
[root@svr-harbor harbor]# docker-compose stop
# 查看运行的容器
[root@svr-harbor harbor]# docker-compose ps
# 启动
[root@svr-harbor harbor]# docker-compose up -d
# 或者这样启动
[root@svr-harbor harbor]# docker-compose start

镜像的推送和拉取

在另外一台安装有docker的主机上推送镜像到harbor仓库

在/etc/docker/daemon.json配置文件下增加insecure-registries配置,这个操作应该就是注册受信任的仓库地址,允许往这个仓库进行推送镜像,否则就会拒绝。

{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.11.250"] //这是增加的
}

注意,这是一个json格式的配置文件,现有的配置不要动,增加即可,如果需要注册多个,在数组里用逗号分隔添加就好。

重启docker服务

[root@test-a-docker01 ~]# systemctl daemon-reload
[root@test-a-docker01 ~]# systemctl restart docker

我本地有个nginx的镜像,将其打标签,它是通过标签的方式来得知属于哪个仓库、哪个项目

[root@test-a-docker01 ~]# docker tag nginx:latest 192.168.11.250/library/nginx:v1
  • 192.168.11.250是仓库服务器的IP地址
  • library是harbor服务器上的项目文件夹

登录

[root@test-a-docker01 ~]# docker login 192.168.11.250
Username: admin
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded

推送

[root@test-a-docker01 ~]# docker push 192.168.11.250/library/nginx:v1

拉取

# 先删除本地的(为了测试)
[root@test-a-docker01 ~]# docker rmi 192.168.11.250/library/nginx:v1
# 再拉取
[root@test-a-docker01 ~]# docker pull 192.168.11.250/library/nginx:v1
v1: Pulling from library/nginx
Digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3
Status: Downloaded newer image for 192.168.11.250/library/nginx:v1
192.168.11.250/library/nginx:v1
[root@test-a-docker01 ~]# docker images
REPOSITORY                     TAG       IMAGE ID       CREATED         SIZE
busybox                        latest    beae173ccac6   10 months ago   1.24MB
192.168.11.250/library/nginx   v1        605c77e624dd   10 months ago   141MB
nginx                          latest    605c77e624dd   10 months ago   141MB
golang                         latest    276895edf967   11 months ago   941MB
centos                         latest    5d0da3dc9764   14 months ago   231MB
[root@test-a-docker01 ~]#



Gitlab所需软件

  • docker ce
  • docker compose

在centos7上安装docker-ce(社区版),安装最新版本的Docker Engine、containerd和Docker Compose

# 安装所需的系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加软件源信息
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#更新并安装
yum makecache fast
[root@svr-harbor ~]# yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y
[root@svr-harbor ~]# ln -s /usr/libexec/docker/cli-plugins/docker-compose /usr/local/bin/
# 启动Docker服务
systemctl start docker
  1. 设置环境变量
[root@svr-gitlab ~]# echo "export GITLAB_HOME=/data" >> .bash_profile 
[root@svr-gitlab ~]# source .bash_profile

/data目录将会作为gitlab的数据目录,请选择容量足够、性能好的文件系统

  1. 创建和配置docker-compose.yml
[root@svr-gitlab ~]# mkdir gitlab
[root@svr-gitlab ~]# cd gitlab/
[root@svr-gitlab gitlab]# vi docker-compose.yml
  • docker-compose.yml的内容如下:
version: '3.6'
services:
  web:
    image: 'gitlab/gitlab-ce:latest'
    restart: always
    hostname: 'gitlab-ser'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://192.168.11.251'
        # Add any other gitlab.rb configuration here, each on its own line
    ports:
      - '443:443'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'
    shm_size: '256m'
[root@svr-gitlab gitlab]# docker compose up -d
[+] Running 7/9
 ⠼ web Pulling                                                                                                                     ...
 ...
 ...

确保启动的命令和docker-compose.yml位于同一目录中

  1. 首次启动需做各种初始化的动作,需多等待一会再访问

https://192.168.11.251/users/sign_in

首次登录时,密码是随机的,下面讲解如何查看初始的密码,默认的账号是root

# 查看容器
[root@svr-gitlab data]# docker ps
CONTAINER ID   IMAGE                     COMMAND             CREATED          STATUS                   PORTS                                                                                                             NAMES
1427ade162cb   gitlab/gitlab-ce:latest   "/assets/wrapper"   11 minutes ago   Up 9 minutes (healthy)   0.0.0.0:80->80/tcp, :::80->80/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp, 0.0.0.0:2222->22/tcp, :::2222->22/tcp   gitlab-web-1
# 进入容器
[root@svr-gitlab gitlab]# docker exec -it gitlab-web-1 bash
# 查看初始密码
root@gitlab-ser:/# cat /etc/gitlab/initial_root_password 
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: 1auf23re9a70Tikipx9edUzICyLPuYwkMoHmV+QY8cs=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

密码就是这个:1auf23re9a70Tikipx9edUzICyLPuYwkMoHmV+QY8cs=

警告!使用初始密码登录后,记得尽快重置root的密码,因为在24小时后,将会自动删除掉/etc/gitlab/initial_root_password文件

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
4月前
|
Kubernetes Cloud Native 应用服务中间件
云原生|kubernetes|kubernetes集群使用私有镜像仓库拉取镜像(harbor或者官方的registry私有镜像仓库)
云原生|kubernetes|kubernetes集群使用私有镜像仓库拉取镜像(harbor或者官方的registry私有镜像仓库)
752 0
|
15天前
|
数据可视化 jenkins 测试技术
GitLab CI/CD 和 Jenkins对比
8月更文挑战第25天
47 5
|
14天前
|
jenkins Devops Java
jenkins学习笔记之十:配置Gitlab提交流水线
jenkins学习笔记之十:配置Gitlab提交流水线
|
14天前
|
安全 jenkins 持续交付
jenkins学习笔记之八:jenkins认证集成gitlab
jenkins学习笔记之八:jenkins认证集成gitlab
|
28天前
|
存储 Ubuntu jenkins
CI/CD 工具比较:Jenkins、GitLab CI、Buildbot、Drone 和 Concourse
CI/CD 工具比较:Jenkins、GitLab CI、Buildbot、Drone 和 Concourse
49 0
|
3月前
|
jenkins Java 持续交付
蓝易云 - 从零开始配置Jenkins与GitLab集成:一步步实现持续集成
以上就是从零开始配置Jenkins与GitLab集成的步骤,希望对你有所帮助。
79 2
|
3月前
|
Kubernetes Cloud Native jenkins
云原生时代:从Jenkins到Argo Workflows,构建高效CI Pipeline
基于Argo Workflows可以构建大规模、高效率、低成本的CI流水线
|
4月前
|
jenkins 持续交付 API
上传gitlab代码后jenkins自动进行发布的配置
上传gitlab代码后jenkins自动进行发布的配置
56 1
|
4月前
|
存储 jenkins 持续交付
百度搜索:蓝易云【Docker+Rancher+Harbor+GitLab+Jenkins搭建CI/CD环境】
请注意,上述步骤仅为一个示例,实际搭建过程可能因环境和需求的不同而有所变化。因此,在实际操作中,请参考相应工具的官方文档和指南,以确保正确地配置和集成这些工具。
90 3
|
10月前
|
jenkins 应用服务中间件 持续交付
gitlab、jenkins、tomcat内存限制
gitlab、jenkins、tomcat内存限制
80 0