环境介绍:
主机清单:172.16.0.31 四核4G 80G硬盘 主机名:devops-2 系统:centos7.6 已安装docker和docker-compose docker和docker-compose的安装教程地址:https://9527edu.org/post/176.html
https://www.jenkins.io/
2.利用docker安装,直接利用docker拉取jenkins,镜像比较大,耐心等待一下,如果失败多输入几次
[root@devops-2 ~]# docker pull jenkins/jenkins:2.319.1-lts 返回结果: 2.319.1-lts: Pulling from jenkins/jenkins 647acf3d48c2: Pull complete 832e288237bc: Pull complete ea194d1bd1da: Pull complete 98569593b9fd: Pull complete dfe249e8cdf2: Pull complete 0f6f2e6d37bb: Pull complete 07fcb98649b6: Pull complete 1e33c26b1882: Pull complete 7b24f0e29fe1: Pull complete 4d90ef3a8f3b: Pull complete d98c8e675bea: Pull complete b45fc2bf9fd7: Pull complete d6e1fda9effc: Pull complete 3635a44047f2: Pull complete 486e1776d3bc: Pull complete 41233d151800: Pull complete 14a67803c2b3: Pull complete Digest: sha256:c1d02293a08ba69483992f541935f7639fb10c6c322785bdabaf7fa94cd5e732 Status: Downloaded newer image for jenkins/jenkins:2.319.1-lts docker.io/jenkins/jenkins:2.319.1-lts
3.创建存放jenkins配置文件的目录
[root@devops-2 ~]# mkdir -p /usr/local/docker/jenkins_docker
4.创建jenkins的docker-compose.yml文件
vim /usr/local/docker/jenkins_docker/docker-compose.yml
##写入一下内容 version: "3.1" services: jenkins: image: jenkins/jenkins:laster container_name: jenkins ports: - 8080:8080 - 50000:50000 volumes: - ./data/:/var/jenkins_home/
5.让jenkins跑起来
进入到/usr/local/docker/jenkins_docker/目录下 [root@devops-2 ~]# cd /usr/local/docker/jenkins_docker/ 运行docker-compose命令让jenkins跑起来 返回结果: [root@devops-2 jenkins_docker]# docker-compose up -d Creating network "jenkins_docker_default" with the default driver Creating jenkins ... done 查看日志 [root@devops-2 jenkins_docker]# docker logs -f jenkins touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions? 解释 这里提示显示权限不足,往/var/jenkins_home/copy_reference_file.log写不进去 解决方法: 给/usr/local/docker/jenkins_docker/data目录添加写的权限即可 [root@devops-2 jenkins_docker]# chmod -R 777 data/ 重启jenkins [root@devops-2 jenkins_docker]# docker-compose restart jenkins Restarting jenkins ... done 再来查看日志 [root@devops-2 jenkins_docker]# docker-compose logs -f jenkins 这里是我的密码 ba995596fd2f4b9cabf1fdec235a54da 返回结果: 。。。。。 jenkins | Jenkins initial setup is required. An admin user has been created and a password generated. jenkins | Please use the following password to proceed to installation: jenkins | jenkins | ba995596fd2f4b9cabf1fdec235a54da 这里是jenkins的密码 jenkins | jenkins | This may also be found at: /var/jenkins_home/secrets/initialAdminPassword 。。。。。 修改默认的源修改成国内的源 [root@devops-2 jenkins_docker]# vi data/hudson.model.UpdateCenter.xml 原内容 <?xml version='1.1' encoding='UTF-8'?> <sites> <site> <id>default</id> <url>https://updates.jenkins.io/update-center.json</url> </site> </sites> 改后 <?xml version='1.1' encoding='UTF-8'?> <sites> <site> <id>default</id> <url>http://mirror.esuni.jp/jenkins/updates/update-center.json</url> </site> </sites> # 清华大学的插件源也可以 https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json 重启jenkins [root@devops-2 jenkins_docker]# docker-compose restart jenkins Restarting jenkins ... done
6.用浏览器访问jenkins首页
http://172.16.0.31:8080/
7.选择安装插件