docker安装jenkins

docker 容器下载

docker容器在docker hub上下载: https://hub.docker.com/r/jenkins/jenkins

容器的详细用法官方文档在github上面: https://github.com/jenkinsci/docker/blob/master/README.md

docker pull jenkins/jenkins:lts
docker tag jenkins/jenkins:lts 192.168.30.11/basic/jenkins:lts-20190906
docker push 192.168.30.11/basic/jenkins:lts-20190906

启动docker 容器

docker run -d -v /jenkins_home:/var/jenkins_home -v /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime --name jenkins -p 80:8080 -p 50000:50000 jenkins/jenkins:lts

数据备份

在jenkins服务器创建备份脚本路径

mkdir /home/jenkins-back

在远端服务器上创建备份目录及账号(添加免密登录就不写了)

useradd databack -d /data/databack
su - databack
mkdir jenkins

编辑备份脚本

#!/bin/bash
now_time=`date +%Y%m%d-%H%M`
filename=/home/jenkins-back/${now_time}.tgz
cd /home/jenkins-back
tar zcf ${filename} /jenkins_home
scp ${now_time}.tgz  databack@192.168.30.102:~/jenkins/

加入定时任务

# crontab -e
20 0 * * * /home/jenkins-back/jenkins-back.sh > /dev/null 2>&1
posted @ 2019-09-06 17:14  长风七万里  阅读(454)  评论(0编辑  收藏  举报