文章目录
- 前言
- 一、版本信息
- 二、环境准备
-
- [2.1 切换源](#2.1 切换源)
- [2.2 安装docker](#2.2 安装docker)
- [2.3 安装ntp](#2.3 安装ntp)
- [2.4 关闭selinux](#2.4 关闭selinux)
- [2.5 安装docker-compose](#2.5 安装docker-compose)
- 三、jenkins安装
-
- [3.1 镜像准备](#3.1 镜像准备)
- [3.2 maven环境安装](#3.2 maven环境安装)
- [3.3 jdk环境安装](#3.3 jdk环境安装)
- [3.4 nodejs环境安装](#3.4 nodejs环境安装)
- [3.5 yaml文件准备](#3.5 yaml文件准备)
- [3.6 进行启动](#3.6 进行启动)
- [3.7 查看密码](#3.7 查看密码)
- 总结
前言
记录在centos7.6安装部署jenkins平台的操作步骤
一、版本信息
- 操作系统版本:centos7.6
- jenkins版本:2.462.2
- maven版本:3.9.9
- jdk版本:jdk1.8.0_202
- nodejs版本:v16.20.2
二、环境准备
2.1 切换源
shell
# 切换源
mkdir -p /etc/yum.repos.d/CentOS-Base.repo.backup;
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup;
# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo;
# 没有wget命令的时候,可以用curl命令下载文件
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache;
yum install wget -y;
wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo;
yum -y install epel-release;
2.2 安装docker
shell
# 安装docker
yum install yum-utils -y;
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo;
#安装服务
yum install docker-ce docker-ce-cli -y;
systemctl restart docker ;
systemctl enable docker ;
2.3 安装ntp
shell
yum install -y ntp;
#修改配置文件
sudo sed -i 's/^server /#server /' /etc/ntp.conf;
sed -i '/3.centos.pool.ntp.org iburst/a server time1.aliyun.com prefer\nserver time2.aliyun.com\nserver time3.aliyun.com\nserver time4.aliyun.com\nserver time5.aliyun.com\nserver time6.aliyun.com\nserver time7.aliyun.com' /etc/ntp.conf;
#重启并加入自启
systemctl enable ntpd;
systemctl restart ntpd;
timedatectl set-timezone "Asia/Shanghai";
ntpq -p;
hwclock;
2.4 关闭selinux
shell
#关闭selinux
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux;
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config;
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/sysconfig/selinux;
sed -i 's/SELINUX=permissive/SELINUX=disabled/g' /etc/selinux/config;
#关闭防火墙
systemctl stop firewalld.service;
systemctl disable firewalld.service;
#重启关闭selinux
reboot
2.5 安装docker-compose
shell
# 安装docker-compose
#获取pip,python版本是2.7.5
mkdir -p /data/jenkins-compose
cd /data/jenkins-compose;
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py;
#python get-pip.py -i https://pypi.douban.com/simple ;
python get-pip.py -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com;
#安装docker-compose
pip install docker-compose -i https://mirrors.aliyun.com/pypi/simple/
三、jenkins安装
3.1 镜像准备
shell
# jenkins镜像下载
https://www.jenkins.io/download/
# 检查发现最新的LTS版本是2.462.2
docker pull jenkins/jenkins:2.462.2-lts
# 备注 这个镜像里面自带一些环境
# JDK:17.0.12
# GIT:2.39.2
3.2 maven环境安装
shell
cd /data/jenkins-compose;
wget https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.tar.gz;
tar -xvf apache-maven-3.9.9-bin.tar.gz;
增加国内源配置,/data/jenkins-compose/apache-maven-3.9.9/conf/settings.xml
xml
<mirror>
<id>aliyunmaven</id>
<mirrorOf>central</mirrorOf>
<name>阿⾥云公共仓库</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
3.3 jdk环境安装
https://www.openlogic.com/openjdk-downloads
shell
# 获取jdk环境,需要根据项目的环境要求安装特定的JDK环境
cd /data/jenkins-compose/jenkins_home;
wget https://builds.openlogic.com/downloadJDK/openlogic-openjdk/8u422-b05/openlogic-openjdk-8u422-b05-linux-x64.tar.gz;
tar -xvf openlogic-openjdk-8u422-b05-linux-x64.tar.gz;
3.4 nodejs环境安装
shell
wget https://registry.npmmirror.com/-/binary/node/latest-v16.x/node-v16.20.2-linux-x64.tar.gz;
tar -xvf node-v16.20.2-linux-x64.tar.gz;
3.5 yaml文件准备
/data/jenkins-compose/jenkins.yml
yaml
version : '3'
services:
jenkins:
user: root
restart: always
privileged: true
image: jenkins/jenkins:2.462.2-lts
container_name: jenkins
ports:
- 8080:8080
- 50000:50000
environment:
TZ: 'Asia/Shanghai'
volumes:
- /data/jenkins-compose/jenkins_home/:/var/jenkins_home/
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /data/jenkins-compose/apache-maven-3.9.9:/usr/local/maven/apache-maven-3.9.9
- /data/jenkins-compose/openlogic-openjdk-8u422-b05-linux-x64:/usr/local/java/openlogic-openjdk-8u422-b05-linux-x64
- /data/jenkins-compose/node-v16.20.2-linux-x64:/usr/local/nodejs/node-v16.20.2-linux-x64
- /etc/docker/daemon.json:/etc/docker/daemon.json
3.6 进行启动
shell
cd /data/jenkins-compose/;
docker-compose -f jenkins.yml up -d
3.7 查看密码
shell
cat /data/jenkins-compose/jenkins_home/secrets/initialAdminPassword
总结
。