- 使用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请确保存在,或请确保路径是正确的
- 解锁Jenkins 对应宿主机上的数据路径是/data/secrets/initialAdminPassword
[root@svr-jenkins ~]# cat /data/secrets/initialAdminPassword bb7b64bf187048f1b7850208e9a2d9a4
将bb7b64bf187048f1b7850208e9a2d9a4复制到解锁页面进行解锁,然后下一步
- 首次插件安装
- 安装建议的插件:安装推荐的一组插件,这些插件基于最常见的用例.
- 选择要安装的插件:选择安装的插件集。当你第一次访问插件选择页面时,默认选择建议的插件。
小白可以选择安装建议的插件,老司机可以选择选择要安装的插件
如果总是有安装失败的插件,可先点击继续跳过,后续再切换下载源地址,再进行安装
- 继续接下来的步骤 创建管理账号
然后选择保存并完成继续
实例配置,可以保持默认
然后选择保存并完成继续
最后选择重启
点击了重启后,发现容器停止了,拉起即可。
- 拉起容器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的方式安装)
开始离线安装
- 下载harbor离线包
wget https://github.com/goharbor/harbor/releases/download/v2.6.2/harbor-offline-installer-v2.6.2.tgz
- 安装最新版本的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/
- 解压
[root@svr-harbor ~]# tar -zxf harbor-offline-installer-v2.6.2.tgz [root@svr-harbor ~]# cd harbor [root@svr-harbor harbor]#
- 修改下面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
数据目录请选择容量足够、性能好的文件系统
- 注释掉harbor.yml中和https有关的配置(内网就不配置https了)
#https: # port: 443 # certificate: /your/certificate/path # private_key: /your/private/key/path
- 开始初始化
[root@svr-harbor harbor]# ./prepare
- 执行安装脚本
[root@svr-harbor harbor]# ./install.sh
注意:亲测,请确保防火墙是打开的状态,因为在install的过程中会自动配置防火墙策略,如果防火墙是停止的,将会install失败。安装成功后,最后会提示:Harbor has been installed and started successfully.----
- 查看数据目录
[root@svr-harbor ~]# cd /data/ [root@svr-harbor data]# ls ca_download database job_logs redis registry scandata_exports secret [root@svr-harbor data]#
安装完成后,已经在指定的数据目录下自动创建了所需的目录,这就是保存任何数据的目录
- 查看运行的容器
[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命令
- 访问
访问80端口即可访问到UI,默认的账号是admin,默认的密码是Harbor12345
- 常用管理
# 停止 [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
- 设置环境变量
[root@svr-gitlab ~]# echo "export GITLAB_HOME=/data" >> .bash_profile [root@svr-gitlab ~]# source .bash_profile
/data目录将会作为gitlab的数据目录,请选择容量足够、性能好的文件系统
- 创建和配置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位于同一目录中
- 首次启动需做各种初始化的动作,需多等待一会再访问
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文件