Devops环境准备
系统准备
https://mirrors.aliyun.com/centos/7/isos/x86_64/
安装Minimal 版本即可 root/root
安装ifconfig
yum install net-tools.x86_64
安装JDK
Linux上卸载自己安装的JDK https://blog.csdn.net/wang_luwei/article/details/124794852
下载JDK https://www.oracle.com/cn/java/technologies/downloads/#java17
yum install fontconfig java-11-openjdk
安装maven
https://blog.csdn.net/wsjzzcbq/article/details/123902173
maven 官网地址:https://maven.apache.org/download.cgi
mkdir -p /m2/repository
mkdir -p /usr/local/maven
tar -zxvf apache-maven-3.8.8-bin.tar.gz -C /usr/local/maven
配置阿里云私服
vim /usr/local/maven/apache-maven-3.8.8/conf/settings.xml
新增配置
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
安装Docker
下载Docker依赖组件
yum -y install yum-utils device-mapper-persistent-data lvm2
设置下载Docker的镜像源为阿里云
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装Docker服务
yum -y install docker-ce
安装成功后,启动Docker并设置开机自启
# 启动Docker服务
systemctl start docker
# 设置开机自动启动
systemctl enable docker
测试安装成功
docker version
设置阿里云镜像
您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://xxx.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
加速地址根据这个去获取 https://blog.csdn.net/wxy2020915/article/details/127866692
Docker 基础命令 https://blog.csdn.net/weixin_44280843/article/details/126858358
Docker-Compose安装
下载Docker/Compose:https://github.com/docker/compose
将下载好的docker-compose-Linux-x86_64文件移动到Linux操作系统:……
设置docker-compose-Linux-x86_64文件权限,并移动到$PATH目录中
设置文件权限
chmod a+x docker-compose-linux-x86_64
# 移动到/usr/bin目录下,并重命名为docker-compose
mv docker-compose-linux-x86_64 /usr/bin/docker-compose
测试安装成功
docker-compose version
Docker安装Jenkins
jenkins 官网 https://www.jenkins.io/zh/download/
docker pull jenkins/jenkins:2.346.3-2-lts-jdk11
创建目录,编写docker-compose.yml,脚本如下:
mkdir /usr/local/docker/jenkins
mkdir /usr/local/docker/jenkins/data
chmod -R a+w /usr/local/docker/jenkins/data
# 编写docker-compose.yml文件
tee /usr/local/docker/jenkins/docker-compose.yml <<-'EOF'
version: "3.1"
services:
jenkins:
image: jenkins/jenkins:2.346.3-2-lts-jdk11
container_name: jenkins
ports:
- 8080:8080
- 50000:50000
volumes:
# 将jenkins的工作目录映射到宿主机的data目录
- ./data/:/var/jenkins_home/
EOF
# 启动容器
cd /usr/local/docker/jenkins
docker-compose up -d
查看容器日志
docker logs -f jenkins
进入到容器
docker exec -it jenkins bash
安装插件
Git Parameter
Publish Over SSH
image.png
image.png
配置全局maven&jdk
容器关联宿主机maven&jdk
mv /usr/local/maven/ /usr/local/docker/jenkins/data/
mv jdk1.8.0_361/ /usr/local/docker/jenkins/data/jdk
配置maven和jdk
image.png image.png