解放双手,纯小白复制粘贴系列。让你快速上手搞定jenkins自动化运维
事前准备:
2核4g的centos7服务器(1核2g也可以,但实在好慢。。。。。建议2核4g起步)Jenkins自动构建JAVA(二) (复制粘贴系列)Jenkins自动构建JAVA(完) (复制粘贴系列)
1.jenkins安脚本创建(复制粘贴运行就好啦)
mkdir -p /home/sh
touch /home/sh/jenkins_install.sh
1.1 jenkins_install.sh脚本内容(vi /home/sh/jenkins_install.sh)(复制一下内容到脚本内)
#!/bin/bash
#1.安装docker
yum update
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum -y install docker-ce
docker -v
systemctl start docker
systemctl enable docker
docker version
#2.修改镜像源
cat <<'EOF'> /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"]
}
EOF
#加载文件
systemctl daemon-reload
#重启docker
systemctl restart docker.service
#3.安装Maven
yum install -y wget
mkdir -p /home/service && cd /home/service
wget http://mirror.bit.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
tar -xzvf /home/service/apache-maven-3.6.3-bin.tar.gz -C /home/service
cd /home/service/apache-maven-3.6.3
#4.修改maven源
yum install -y dos2unix
dos2unix /home/service/apache-maven-3.6.3/conf/settings.xml
sed -i '/<\/mirrors>/i\ <mirror>\n <id>aliyunmaven</id>\n <mirrorOf>*</mirrorOf>\n <name>阿里云公共仓库</name>\n <url>https://maven.aliyun.com/repository/public</url>\n </mirror>' /home/service/apache-maven-3.6.3/conf/settings.xml
#5.新增系统环境
cat <<'EOF'>> /etc/profile
export M2_HOME=/home/service/apache-maven-3.6.3
export PATH=$PATH:${M2_HOME}/bin
EOF
#6.jenkins 安装
docker pull jenkins/jenkins
mkdir -p /home/jenkins_home
# 记得赋予挂载目录的权限,不然启动会报错误
sudo chown -R 1000:1000 /home/jenkins_home
# 启动jenkins,并且挂载数据目录以及maven安装目录
docker run --restart=always -d --name jenkins -p 8888:8080 -v /etc/localtime:/etc/localtime:ro -v /home/jenkins_home:/var/jenkins_home -v /home/service/apache-maven-3.6.3:/usr/local/maven jenkins/jenkins
2.执行脚本(复制粘贴运行就好啦)
# 执行安装脚本
sh /home/sh/jenkins_install.sh
3.等待安装完成后,docker 就会启动完jenkins
3.1 打开网页查看jenkins管理页面,请等到这个页面后执行步骤4的脚http://192.168.0.30:8888
4.替换下载源(可跳过,如果要替换,谨记等步骤3的页面出来,不然文件没有初始完)
#替换插件源路径
sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' /home/jenkins_home/updates/default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' /home/jenkins_home/updates/default.json
#重启jenkins
docker restart jenkins
5. 查看jenkins密码(复制粘贴运行就好啦)拿到密码后进行步骤3的登录
#查看密码
cat /home/jenkins_home/secrets/initialAdminPassword
6. 选择默认安装就好了,然后等待安装,部分插件安装失败也没事,继续下一步就好