1.使用docker命令下载Jenkins
代码语言:javascript复制sudo docker pull jenkins
2.创建jenkins文件夹
代码语言:javascript复制mkdir -p /home/var/jenkins
3.进入/home/var/目录,设置jenkins文件夹归属用户UID为1000
代码语言:javascript复制cd /home/var
sudo chown -R 1000:1000 jenkins/
4.启动jenkins
代码语言:javascript复制docker run -itd -u root -p 12347:8080 -p 50000:50000 --name jenkins_01 --restart always --privileged=true -v /home/var/jenkins:/var/jenkins_home -v /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/bin/java:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/bin/java -v /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64 -v /usr/local/maven/apache-maven-3.5.4:/usr/local/maven/apache-maven-3.5.4 -v /usr/local/repo:/usr/local/repo 镜像ID
参数说明:jenkins需要配置JAVA_HOME和MAVEN_HOME,我下面会说明其安装和配置,大佬请跳过,docker启动要外挂盘(-v /home/var/jenkins:/var/jenkins_home ),不然重新run之后原先下载的插件及配置又要重新改
5.重启jenkins
代码语言:javascript复制docker restart jenkins_01
页面访问:http://部署IP地址:12347
6.获取jenkins密码
代码语言:javascript复制sudo docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword
第一次加载且下载插件很慢,可以进行插件加速,下面相关操作可以加速
代码语言:javascript复制docker exec -it jenkins_01 bash //进入容器
find / -name 'default.json' //搜索文件所在地址,一般都在/var/jenkins_home/updates/default.json
cd /var/jenkins_home/updates
sed -i 's/http://updates.jenkins-ci.org/download/https://mirrors.tuna.tsinghua.edu.cn/jenkins/g' default.json && sed -i 's/http://www.google.com/https://www.baidu.com/g' default.json
7.以后步骤完成,jenkins安装完成,接下来就是构建,我在下章里面写,踩的坑很多