docker-compose部署Jenkins+Gitlab CICD

docker-compose 搭建CICD-jenkins+gitlab
1.修改yum源
(1)备份原来的yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
(2)下载阿里的yum源
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
(3)安装相关插件
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
(4)添加docker-ce源
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2.安装docker-ce,配置docker仓库
yum install -y docker
tee /etc/docker/daemon.json <<-‘EOF’
{
“insecure-registries” : [“0.0.0.0/0”],
“registry-mirrors”: [“https://bytkgxyr.mirror.aliyuncs.com”,“https://registry.docker-cn.com”,“http://hub-mirror.c.163.com”]
}
EOF
systemctl restart docker
systemctl enable docker
3.安装docker-compose
sudo curl -L https://get.daocloud.io/docker/compose/releases/download/1.29.2/docker-compose-uname -s-uname -m > /usr/local/bin/docker-compose
chmod 777 /usr/local/bin/docker-compose

docker-compose --version

4.拉取jenkins镜像和gitlab镜像:

docker pull docker.io/jenkins/jenkins

docker pull registry.gitlab.cn/omnibus/gitlab-jh:latest

5.部署CICD: 先部署jenkins:

mkdir /root/CICD && cd /root/CICD

vi jenkins.yaml

version: "3"
services:
  jnekins:
    container_name: jenkins
    image: docker.io/jenkins/jenkins
    ports:
      - 8080:8080  #按需修改
    user: root
    privileged: true
    volumes:
      - ./jenkins_home:/var/jenkins_home
      - /usr/bin/docker:/usr/bin/docker                  #1容器内使用docker
      - /var/run/docker.sock:/var/run/docker.sock       #2
      - /usr/bin/kubectl:/usr/local/bin/kubectl         #3容器内使用K8S
      - /root/.kube:/root/.kube                         #4 1-4为jenkins部署流水线所需,本文只搭建。不涉及流水线发布
    restart: always

docker-compose -f jenkins.yaml up -d
在这里插入图片描述

游览器访问http://IP:8080

docker-compose部署Jenkins+Gitlab CICD_第1张图片

查看密码:cat jenkins_home/secrets/initialAdminPassword

根据自己需求安装,本文选择第2个:

docker-compose部署Jenkins+Gitlab CICD_第2张图片

添加一个gitlab

docker-compose部署Jenkins+Gitlab CICD_第3张图片

创建用户根据自己所需,本文以admin管理用户登录。游览器直接URL即可。

点击admin-设置-下方即可设置admin密码:

docker-compose部署Jenkins+Gitlab CICD_第4张图片

jenkins到这里就先可以了,后续把gitlab安装好再配置:

gitlab安装过程:(gitlab启动时间会相对长点,可用docker logs查看)

vi /root/CICD/gitlab.yaml

version: "3"
services:
  gitlab:
    container_name: gitlab
    image: registry.gitlab.cn/omnibus/gitlab-jh:latest
    ports:
      - '1022:22'
      - '88:80'
      - '443:443'  #按需修改
    restart: always
    user: root
    volumes:
      - ./gitlab/config:/etc/gitlab
      - ./gitlab/data:/var/opt/gitlab
      - ./gitlab/logs:/var/log/gitlab

docker-compose -f gitlab.yaml up -d

在这里插入图片描述

游览器 http://IP:88 访问( 这个管理员账号的账号名为 root,而密码在一个自动生成的文件 /etc/gitlab/initial_root_password 中(密码不会含空格),且会在 24 小时后自动被删除。)
cat gitlab/config/initial_root_password

修改root密码:

docker-compose部署Jenkins+Gitlab CICD_第5张图片

设置jenkins访问秘钥:(先创建项目,这里不创建,自行创建,演示通过公共的)进入项目:

docker-compose部署Jenkins+Gitlab CICD_第6张图片

docker-compose部署Jenkins+Gitlab CICD_第7张图片
复制代码

进入jenkins:Manage Jenkins→Configure Ststem→Gitlab

docker-compose部署Jenkins+Gitlab CICD_第8张图片

Test Connection 显示Success即可

Credentials 采用
docker-compose部署Jenkins+Gitlab CICD_第9张图片

保存即可!

你可能感兴趣的:(jenkins,docker,运维)