Shell练习题(二)docker自动安装

本练习主要编写shell完成docker的自动安装:

1.下载安装包

下载docker安装包 https://download.docker.com/linux/static/stable/,我下载的是:docker-19.03.15.tgz

2.编辑docker.service  该文件主要是将docker注册为service

vi docker.service
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
  
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd --selinux-enabled=false --insecure-registry=127.0.0.1
ExecReload=/bin/kill -s HUP $MAINPID
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
#TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
# restart the docker process if it exits prematurely
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
  
[Install]
WantedBy=multi-user.target

3.编辑安装shell文件,并给予执行权限

vi install.sh
#!/bin/bash

echo '解压tar包'
tar -zxvf docker-19.03.15.tgz

echo '将docker目录移动到/usr/bin目录下。。'
cp docker/*  /usr/bin

echo '将docker.service移动到/etc/systemd/system/'
cp docker.service /etc/systemd/system

echo '添加文件权限'
chomd +x /etc/systemd/system/docker.service

echo '重新加载配置文件'
systemctl daemon-reload

echo '启动docker'
systemctl start docker

echo '设置开机启动'
systemctl enable docker.service

echo 'docker安装成功'
docker -v

 

4.编辑卸载shell脚本,并给予执行权限

vi uninstall.sh
#!/bin/bash

echo '删除docker.service'
rm -f /etc/systemd/system/docker.service

echo '删除docker文件'
rm -f /usr/bin/docker*

echo '重新加载配置'
systemctl daemon-load

echo '卸载成功'

5.将压缩包和脚本放到同一个文件夹

 

 

一起学习朋友可以联系我

 

posted @ 2022-01-19 11:04  中仕  阅读(5)  评论(0编辑  收藏  举报