1 #!/bin/bash 2 # coding: utf-8 3 # Copyright (c) 2018 4 set -e #返回值為0時,退出腳本 5 echo "1. 備份yum" 6 { 7 for i in /etc/yum.repos.d/*.repo;do cp $i ${i%.re ...
安裝docker
1 #!/bin/bash 2 # coding: utf-8 3 # Copyright (c) 2018 4 set -e #返回值為0時,退出腳本 5 echo "1. 備份yum" 6 { 7 for i in /etc/yum.repos.d/*.repo;do cp $i ${i%.repo}.bak;done 8 rm -rf /etc/yum.repos.d/*.repo 9 } || { 10 echo "備份出錯,請手動執行" 11 exit 1 12 } 13 14 echo "2. 獲取網路yum" 15 { 16 wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/Centos-7.repo >/dev/null 2>&1 17 wget -P /etc/yum.repos.d/ http://mirrors.163.com/.help/CentOS7-Base-163.repo >/dev/null 2>&1 18 yum clean >/dev/null 2>&1 19 yum repolist >/dev/null 2>&1 20 } || { 21 echo "獲取出錯,請手動執行" 22 exit 1 23 } 24 25 echo "3. 安裝docker-ce......" 26 { 27 yum -y install yum-utils >/dev/null 2>&1 28 yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo >/dev/null 2>&1 29 yum clean >/dev/null 2>&1 30 yum repolist >/dev/null 2>&1 31 yum -y install epel-release docker-ce >/dev/null 2>&1 32 } || { 33 echo "安裝出錯,請手動安裝" 34 exit 1 35 } 36 37 systemctl start docker >/dev/null 2>&1 38 systemctl enable docker >/dev/null 2>&1 39 40 echo "4. 添加內和參數" 41 { 42 cat <<EOF>> /etc/sysctl.conf 43 net.bridge.bridge-nf-call-ip6tables = 1 44 net.bridge.bridge-nf-call-iptables = 1 45 EOF 46 sysctl -p >/dev/null 2>&1 47 } 48 49 echo "5. 添加鏡像加速" 50 { 51 cat <<EOF>> /etc/docker/daemon.json 52 { 53 "registry-mirrors": [ 54 "https://registry.docker-cn.com" 55 ] 56 } 57 EOF 58 } 59 60 systemctl daemon-reload >/dev/null 2>&1 61 systemctl restart docker >/dev/null 2>&1 62 63 rm -rf ./*.shView Code