关于jenkins:不背锅运维云原生下的CICD3件套快速搭建合集jenkinsharborgitlab

8次阅读

共计 9143 个字符,预计需要花费 23 分钟才能阅读完成。

  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?f…
  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/…

首次登录时,明码是随机的,上面解说如何查看初始的明码,默认的账号是 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 文件

本文转载于:https://mp.weixin.qq.com/s/D_…

正文完
 0