每日一个shell脚本之一键部署Docker
源码参上
bash
#!/usr/bin/bash
# **************************************
# CSDN: M乔木
# qq邮箱: 2776617348@qq.com
# 解释器: 这是一个shell脚本
# **************************************
#声明函数
function Aq_jc(){
clear
#检测防火墙selinux
echo "------------------------------------------------------------"
echo "[1]开始检测防火墙SeLinux是否关闭..."
sleep 1
f_w=`systemctl status firewalld | awk '/Active:/{print $2}'`
s_l=`getenforce`
#判断是否关闭 没关闭就结束运行
if [ ${f_w} = "inactive" -a ${s_l} = "Disabled" ];then
echo "[2]防火墙SeLinux已关闭..."
sleep 1
echo "[3]正在飞速安装docker中..."
sleep 1
else
echo "[2]防火墙SeLinux未关闭..."
systemctl disable firewalld &>/dev/null
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
sleep 1
echo "[3]正在关闭..."
sleep 1
echo "[4]防火墙SeLinux已关闭 请重启机器生效..."
echo "------------------------------------------------------------"
exit 0
fi
#防火墙关了的话就继续开启路由转发
echo "[4]正在开启路由转发虚拟网桥..."
echo 'net.ipv4.ip_forward =1' >>/etc/sysctl.conf
echo 'net.bridge.bridge-nf-call-iptables =1' >>/etc/sysctl.conf
echo 'net.bridge.bridge-nf-call-ip6tables =1' >>/etc/sysctl.conf
sysctl -p &>/dev/null
sleep 1
#防火墙关闭的话就清理docker环境
echo "[5]正在清理环境中..."
yum -y remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-selinux docker-engine-selinux docker-engine &>/dev/null
sleep 1
echo "[6]开始安装docker依赖..."
yum install -y yum-utils device-mapper-persistent-data lvm2 &>/dev/null
sleep 1
echo "[7]开始配置阿里docker源..."
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo &>/dev/null
yum clean all &>/dev/null && yum makecache fast &>/dev/null
sleep 1
echo "[8]开始安装docker..."
yum -y install docker-ce doker-ce-cli containerd.io &>/dev/null
sleep 1
echo "[9]开始配置开机自启..."
systemctl start docker &>/dev/null
systemctl enable docker &>/dev/null
systemctl restart docker &>/dev/null
sleep 1
echo "[10]开始配置阿里云镜像加速器..."
clear
echo "[11]开始建立docker加速器放置目录..."
mkdir -p /etc/docker
sleep 1
echo "[12]开始写入配置..."
tee /etc/docker/daemon.json &>/dev/null<<-'EOF'
{
"registry-mirrors": ["https://2zwkpj0m.mirror.aliyuncs.com"]
}
EOF
sleep 1
echo "[13]重新加载system工具..."
systemctl daemon-reload &>/dev/null
sleep 1
echo "[14]重新启动docker..."
systemctl restart docker &>/dev/null
sleep 1
echo "[15]阿里云镜像加速器配置完毕!"
sleep 1
echo "[16]开始拉取基础镜像centos:7..."
docker pull centos:7 &>/dev/null
sleep 1
echo "[17]已部署docker及第一个基础镜像centos7已配置完毕!"
sleep 1
echo '[18]开始使用你的一个docker命令体验激动人心的docker吧!'
sleep 1
echo '[19]docker images:查看已下载镜像'
sleep 1
echo '[20]docker info:查看docker基本信息'
sleep 1
echo '[21]docker run -it centos:7 /bin/bash:以centos7为基础启动一个容器'
echo "------------------------------------------------------------"
}
#主界面
Aq_jc
使用方法
bash
[root@qm ]# vim docker-az.sh
#复制粘贴上面的代码进去
[root@qm ]# sh docker-az.sh
#运行脚本
结尾
还是那话点赞关注转发感谢!