首页 > 系统相关 >shell脚本自动选择空间最大的目录安装docker

shell脚本自动选择空间最大的目录安装docker

时间:2024-10-16 13:53:51浏览次数:3  
标签:shell Space Unamer 目录 awk print docker Docker

#!/bin/bash
# 二进制包安装docker-xy.xy.x-ce

# 变量
unamer=`uname -r |cut -d'.' -f1-2`
Max_Space=$(df|grep "^/dev"|sort -rn -k2|head -1|awk '{print $6}')
Registry="mirror.eastraycloud.com:8665"

#判断当前系统类型
Unamer=$(uname -v|awk '{print $1}'|awk -F - '{print $2}')
#Unamer=`cat /proc/version|awk -F "(" '{print $4}'|awk '{print $1}'`
#Unamer=`cat /etc/os-release |grep ID|head -1|awk -F "=" '{print $2}'|sed 's/\"//g'`
if [ "$Unamer" = "Ubuntu" ]; then
  Service=/lib/systemd/system/docker.service
else
  Service=/usr/lib/systemd/system/docker.service
fi

# docker-compose安装
Docker_Compose() {
cp -f ../docker-compose/* /usr/local/bin/
chmod u+x /usr/local/bin/docker-compose
}

# 解压安装docker

Docker_Install (){
   tar zxf ../docker-ce/docker-*-ce.tgz -C $Max_Space
   mv $Max_Space/docker/* /usr/bin/
   Docker_Data=$Max_Space/docker
}

# 设置容器日志大小限制
Docker_log_limits() {
   mkdir /etc/docker
   cat > /etc/docker/daemon.json<<EOF
{
  "log-driver":"json-file",
  "log-opts": {"max-size":"500m", "max-file":"3"},
  "default-address-pools":[{"base":"172.80.0.0/16","size":24},{"base":"172.90.0.0/16","size":24}],
  "registry-mirrors":["https://docker.nju.edu.cn"]
}
EOF
}

# 启动docker并设置自动启动
Docker_Start() {
    cat >$Service <<EOF
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
  
[Service]
OOMScoreAdjust=-1000
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
## "--ip-forward=true --iptables=false"
##ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock --insecure-registry=$Registry --data-root $Docker_Data 
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
EOF
# 启动docker服务
systemctl start docker
# 设置docker开机自启动
systemctl enable docker
}

Docker() {
   Docker_Compose
   Docker_Install
   Docker_log_limits
   Docker_Start
}
Docker

标签:shell,Space,Unamer,目录,awk,print,docker,Docker
From: https://blog.csdn.net/qq_15753385/article/details/142971317

相关文章

  • OS-Lab1-Linux的常见命令和Shell脚本编程
    Lab1:Linux常见命令的基本使用和总结:如ls、cd、mkdir、torch、rm、mv、clear、grep、find、cat、shutdown等。Lab2:Linux常见命令的应用案例:下面的步骤,通过相关的Linux命令,完成指定步骤的操作Lab3:VMware的Host(如Windows系统)与Guest(如UbuntuLinux)的数据交换:常见......
  • Win10客户端使用Powershell连接到O365
    Win10客户端使用Powershell连接到O365 首选使用get-module命令查看我的本机电脑是否安装了相关模块,上图发现并没有安装相关模块Install-Module-NameMSOnline  (安装相应的模块)   ......
  • (保姆级图文)如何使用PowerShell连接Exchange Online
    (保姆级图文)如何使用PowerShell连接ExchangeOnline直接开始菜单->所有程序-> WindowsPowerShell->WindowsPowerShell 然后右键使用管理员权限打开打开后窗口如下#连接ExchangeOnlinePowerShell#为了使从Internet下载的所有PowerShell脚本能够由受信任的......
  • 基于cloudreve(Docker应用)搭建网盘服务,用于目录的分享和在线预览。
    文章目录I基于cloudreve(Docker应用)搭建网盘服务安装主要功能设置角色最大容量II知识扩展:网盘类的文件预览需求背景:iOS可以直接预览PDF等常见格式文件,但是Android浏览器需要先下载文件,才能查看文件内容,因此需要搭建支持目录的分享和在线预览的Min......
  • centos离线安装docker,docker-compose
    安装环境操作系统:Centos7.99内核版本:3.10.0-1160.el7.x86_64安装用户:rootdocker离线安装1下载压缩包官网下载地址:https://download.docker.com/linux/static/stable/x86_64/这里默认选择最新版本(26.0.2)。2上传压缩包并解压tarzxvfdocker-26.0.2.tgz3......
  • YOLOv11改进 | 代码逐行解析(一) | 项目目录构造分析
     一、本文介绍Hello,大家好这次给大家带来的不是改进,是整个YOLOv11项目的分析,整个系列大概会更新5-7篇左右的文章,从项目的目录到每一个功能代码的都会进行详细的讲解,下面开始进行YOLOv11逐行解析的第一篇——项目目录构造分析开头之前顺便给大家推荐一下我的专栏,本专栏更新上......
  • Docker Compose部署GitLab
    今天我将向你展示如何在一小时内安装GitLab服务器,并在其中运行第一个CI/CD进程。本文是“如何开始使用流行的CI/CD工具”系列文章的一部分。在本文中,我将向你展示如何安装CI/CD工具,以及如何准备基于Maven构建和测试一个简单项目的流程。什么是GitLab?Gitlab是一款......
  • docker如何建立本地私有仓库,并将docker镜像推到私有仓库
    在Docker中,您可以通过DockerRegistry创建本地私有仓库,并将Docker镜像推送到这个私有仓库。以下是具体步骤:步骤1:启动一个本地Docker私有仓库拉取registry镜像:Docker官方提供了一个registry镜像,可以用来运行私有仓库。首先,您需要从DockerHub拉取这个镜......
  • 【shell脚本】计算网卡速率
    #!/bin/basheth="br-lan"timer=1#SettingIFS(inputfieldseparator)valueas","IFS=''#Readingthesplitstringintoarrayread-raarr<<<"$(cat/proc/net/dev|grep$eth)"in_old=${arr[1]}......
  • 《15分钟轻松学Go》教程目录
    在AI快速发展的时代,学习Go语言依然很有用。Go语言擅长处理高并发任务,也就是说可以同时处理很多请求,这对于需要快速响应的AI服务非常重要。另外,Go适合用来处理和传输大量数据,非常适合机器学习模型的数据预处理。Go还可以和其他更常用的AI语言(如Python)配合使用,这使得建立AI系统......