容器化部署gitlab、jenkins,jenkins应用示例

一、容器化部署docker和docker conpose安装

Docker&Docker-compose的安装及部署_docker 20 使用什么版本docker-compose-CSDN博客

1.docker 安装脚本

cat >01_docker.sh<<EOF
#!/bin/bash 
yum remove docker \
     docker-client \
     docker-client-latest \
     docker-common \
     docker-latest \
     docker-latest-logrotate \
     docker-logrotate \
     docker-engine

yum install -y yum-utils device-mapper-persistent-data lvm2
yum install -y gcc gcc-c++
yum-config-manager --add-repo  http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce docker-ce-cli containerd.io
systemctl enable --now docker
ps -ef | grep docker
<<EOF
chmod +x 01_docker.sh
./01_docker.sh

2.docker compose安装脚本

cat >02_docker-compose.sh<<EOF
#!/bin/bash
curl -L "https://get.daocloud.io/docker/compose/releases/download/v2.2.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod -R 777 /usr/local/bin/docker-compose
docker compose  version
EOF
chmod +x 02_docker-compose.sh
./02_docker-compose.sh

二、gitlab容器化部署安装

注意:http://192.168.88.120:8929 ,更改文件里面ip,即自己服务器的IP,ip addr 查看即可

vim 03_gitlab-ce.sh

#!/bin/bash
mkdir -p /usr/local/docker/gitlab_docker
cd /usr/local/docker/gitlab_docker
#docker search gitlab 
docker images | grep gitlab-ce
[ $? -eq 0 ]  && echo 'gitlab-ce镜像已下载' || docker pull gitlab/gitlab-ce
cat >/usr/local/docker/gitlab_docker/docker-compose.yaml<<EOF
version: '3.1'
services:
  gitlab:
    image: "gitlab/gitlab-ce:latest"
    container_name: gitlab
    restart: always
    environment:
      GITLAB_OMNIBUS_CONFIG: |         
        external_url 'http://192.168.88.120:8929'
        gitlab_rails['gitlab_shell_port'] = 2224
    ports:
      - '8929:8929'
      - '2224:2224'
    volumes:
      - './config:/etc/gitlab'
      - './logs:/var/log/gitlab'
      - './data:/var/opt/gitlab'
EOF
docker compose -f docker-compose.yaml   up -d
# 浏览器查,用户名root,密码见下文,耐心等待http://192.168.88.120:8929/
#初始化密码文件
#cat  config/initial_root_password

chmod +x 03_gitlab-ce.sh

./03_gitlab-ce.sh

三、jenkins安装

vim 04-docker_jenkins.sh

#!bin/bash
docker images | grep jenkins:2.387.1
#[ $? -eq 0 ] || docker pull jenkins/jenkins:2.319.1-lts
[ $? -eq 0 ] || docker pull jenkins/jenkins:2.387.1-lts
mkdir -p /usr/local/docker/jenkins_docker
cd /usr/local/docker/jenkins_docker
cat >/usr/local/docker/jenkins_docker/docker-compose.yaml<<EOF
version: '3.1'
services:
  jenkins:
    image: "jenkins/jenkins:2.387.1-lts"
    container_name: jenkins
    restart: always
    ports:
      - '8080:8080'
      - '50000:50000'
    volumes:
      - './data:/var/jenkins_home/'
EOF
rm -rf ./data/
docker compose -f docker-compose.yaml   up -d
chmod -R  777 ./data
docker compose restart jenkins
#cat data/secrets/initialAdminPassword

chmod +x 04-docker_jenkins.sh

./04-docker_jenkins.sh

四、jdk,maven安装

jdk和maven安装部署到jenkins所在服务器

1、jdk1.8部署

#!/bin/bash
tar -xf jdk-8u161-linux-x64.tar.gz
rm -rf /usr/local/jdk1.8
mv jdk1.8.0_161  /usr/local/jdk1.8
sed -i '$aexport JAVA_HOME=/usr/local/jdk1.8' /etc/profile
sed -i '$aexport CLASSPATH=.:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar'  /etc/profile
sed -i '$aexport PATH=$JAVA_HOME/bin:$PATH'  /etc/profile
. /etc/profile

1、maven部署

#!/bin/bash
tar -xf apache-maven-3.9.6-bin.tar.gz
rm -rf  /usr/local/maven
mv apache-maven-3.9.6   /usr/local/maven

sed -i '$aexport MAVEN_HOME=/usr/local/maven' /etc/profile
sed -i '$aexport PATH=${MAVEN_HOME}/bin:$PATH' /etc/profile
. /etc/profile
#配置maven仓库地址
sed -i '161,165d' /usr/local/maven/conf/settings.xml
sed -i '160a\       <id>nexus-alimaven</id> '  /usr/local/maven/conf/settings.xml
sed -i '161a\       <mirrorOf>repositoryId</mirrorOf>  '  /usr/local/maven/conf/settings.xml
sed -i '162a\       <name>Human Readable for this Mirror</name>  '  /usr/local/maven/conf/settings.xml
sed -i '163a\       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>  '  /usr/local/maven/conf/settings.xml
#配置jdk8 插件

sed  -i '189a <profile>\n <id>jdk8</id>\n <activation>\n  <activeByDefault>true</activeByDefault>\n <jdk>1.8</jdk>\n 
</activation>\n 
<properties>\n 
<maven.compiler.source>1.8</maven.compiler.source>\n <maven.compiler.target>1.8</maven.compiler.target>\n <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>\n</properties>\n
</profile>  ' /usr/local/maven/conf/settings.xml

sed -i '275a <activeProfiles>\n<activeProfile>jdk8</activeProfile>\n</activeProfiles>' /usr/local/maven/conf/settings.xml

5、Jenkins应用

将jdk和maven移动到Jenkins目录下
mv /usr/local/jdk1.8 /usr/local/docker/jenkins_docker/data/
mv /usr/local/maven /usr/local/docker/jenkins_docker/data/

1.jenkins安装必要的插件

2.配置全局变量jdk和maven

3.配置系统管理远程服务器

4.新建项目

注意:docker目录内容

Dockerfile文件内容:提前在目标主机下载好镜像docker pull daocloud.io/library/java:8u40-jdk

FROM daocloud.io/library/java:8u40-jdk
COPY demo5-0.0.1-SNAPSHOT.jar  /usr/local/
WORKDIR /usr/local/
CMD java -jar demo5-0.0.1-SNAPSHOT.jar

docker-compose-yaml文件内容

version: '3.1'
services:
  mytest:
    build:
      context: ./
      dockerfile: Dockerfile
    image: mytest:v1.0.0
    container_name: mytest2
    ports:
      - 8081:8080

在目标主机执行的shell命令

cd /usr/local/test/docker/                   #在目标主机执行的目录
mv  ../target/demo5-0.0.1-SNAPSHOT.jar ./    #将打包的jar包放入docker 目录
docker compose  down                         #关闭之前打开的容器
docker compose up -d --build                 #重新创建容器
docker images prune -f                       #删除名称为none的镜像
相关推荐
lwprain3 分钟前
解决tomcat双击startup.bat乱码的几种方法
java·tomcat
小汤猿人类25 分钟前
nacos-gateway动态路由
java·前端·gateway
GraduationDesign30 分钟前
基于SpringBoot的在线文档管理系统的设计与实现
java·spring boot·后端
TANGLONG22236 分钟前
【初阶数据结构与算法】八大排序之非递归系列( 快排(使用栈或队列实现)、归并排序)
java·c语言·数据结构·c++·算法·蓝桥杯·排序算法
言之。42 分钟前
【Java】面试题 并发安全 (1)
java·开发语言
m0_7482345242 分钟前
2025最新版Java面试八股文大全
java·开发语言·面试
van叶~1 小时前
仓颉语言实战——2.名字、作用域、变量、修饰符
android·java·javascript·仓颉
张声录11 小时前
【ETCD】【实操篇(十九)】ETCD基准测试实战
java·数据库·etcd
HIT_Weston1 小时前
16、【ubuntu】【gitlab】【补充】服务器断电后,重启服务器,gitlab无法访问
服务器·ubuntu·gitlab
鱼香鱼香rose1 小时前
面经hwl
java·服务器·数据库