前言
不搞那么复杂,就一行命令搞定:
1
| bash <(curl -fSsL http://www.chenb.top/deploy/docker-install.sh)
|
脚本代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #!/bin/bash
now=`date +%s` function log() { echo "[$((`date +%s` - now ))] ## $@ ##" }
log "Installation start at `date`"
[[ `whoami` != "root" ]] && echo "Root Privilege needed, use sudo please." && exit 1 OS=`awk -F= '/^NAME/{print $2}' /etc/os-release | sed "s/\"//g"` if [[ "$OS" == "Ubuntu" ]];then : elif [[ "$OS" == "CentOS Linux" ]];then OS="CentOS" else echo "Unknown OS: \"$OS\", exit" exit 2 fi
log "install and upgrade docker" if [[ "$OS" == "Ubuntu" ]];then apt-get update apt-get -y install apt-transport-https ca-certificates curl software-properties-common curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | apt-key add - add-apt-repository -u "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" apt-get -y install docker-ce fi
if [[ "$OS" == "CentOS" ]];then yum install -y yum-utils device-mapper-persistent-data lvm2 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo yum makecache fast yum -y install docker-ce systemctl enable docker && systemctl start docker fi
log "congifure mirror and insecure registries" cat > /etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://m.mirror.aliyuncs.com"] } EOF systemctl daemon-reload && systemctl restart docker log "Installation end at `date`"
|
启动Jenkins的命令
1 2 3 4 5 6 7 8 9 10 11 12
| docker run \ --name jenkins \ -d \ -u root \ -p 8080:8080 \ -v jenkins-data:/var/jenkins_home \ -v /var/run/docker.sock:/var/run/docker.sock \ -v /usr/bin/docker:/usr/bin/docker \ -e TZ=Asia/Shanghai \ -v "$HOME":/home \ -m 2g \ jenkins/jenkins:2.401.1
|
参考链接
GitHub项目地址:https://github.com/chenbin-353549444/deploy
参考别人的项目:https://github.com/wrfly/k8s-install.sh
官网安装链接:https://docs.docker.com/install/linux/docker-ce/centos/