当前位置 : 主页 > 网络安全 > 测试自动化 >

自动化部署docker环境

来源:互联网 收集:自由互联 发布时间:2021-06-19
一、基础工具安装 #!/bin/bashecho "This check your base circumstance!"yum install -y vim wget git lrzsz net-tools echo "finished" 二、部署docker环境 #!/bin/bash###write by leoheng##env for centos7.x##please modify env variables
一、基础工具安装
#!/bin/bash

echo "This check your base circumstance!"
yum install -y vim wget git lrzsz net-tools 
echo "finished"

二、部署docker环境

#!/bin/bash
###write by leoheng
##env for centos7.x
##please modify env variables for you.

HOSTNAME=docker   ##你的主机名称
D_VERSION=`yum list docker-ce.x86_64 | sort -r |grep ‘docker‘  |awk ‘{print $2}‘ | awk -F : ‘{print $2}‘ | awk -F - ‘{print $1}‘`    ##docker环境的版本,自动更新到最新的docker版本

##set hostname and hosts
echo ‘will set hostname and hosts,you can ctrl+C pause it!!!‘ ;sleep 5   
hostnamectl set-hostname ${HOSTNAME}

##set selinux
echo ‘will set selinux ,you can ctrl+C pause it!!!‘ ;sleep 5 
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config

###set  iptables rules
echo ‘will set iptables rules,you can ctrl+C pause it!!!‘ ;sleep 5 
iptables -F
iptables -X
iptables -Z
systemctl stop firewalld.service && systemctl disable firewalld.service

###set timezone
echo ‘will set timezone , you can ctrl+C pause it!!!‘ ;sleep 5 
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
echo ‘LANG="en_US.UTF-8"‘ >> /etc/profile ; source /etc/profile

###set kernel
echo ‘will set kernel,you can ctrl+C pause it!!!‘ ;sleep 5 
cat >> /etc/sysctl.conf<<EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
EOF
modprobe br_netfilter
sysctl -p

###remove old docker_soft
echo ‘will remove old docker software , you can ctrl+C pause it!!!‘ ;sleep 5 
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate  docker-logrotate  docker-selinux  docker-engine-selinux docker-engine container*

###set version
echo ‘will set docker version,you can ctrl+C pause it!!!‘ ;sleep 5 
export docker_version=${D_VERSION}

### install utils (must)
yum update -y
yum install -y yum-utils device-mapper-persistent-data lvm2 bash-completion wget

###add docker.repo
echo ‘will add docker repo...‘ ;sleep 5 
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

###update and install docker-ce
echo ‘will install docker-ce...‘ ;sleep 5 
yum makecache all
yum -y install --setopt=obsoletes=0 docker-ce-${docker_version} docker-ce-selinux-${docker_version}

###set docker conf
echo ‘will set docker conf , you can ctrl+C pause it!!!‘ ;sleep 5 
mkdir -p /etc/docker && touch /etc/docker/deamon.json
cat >> /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com/"]
}
{
"storage-driver": "overlay2",
"storage-opts": ["overlay2.override_kernel_check=true"]
}
{
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
EOF

##set docker enable 
echo ‘enable docker....‘ ; sleep 3
systemctl enable docker
systemctl start docker

###reboot machine
echo ‘will be reboot machine , you can ctrl+C pause it!!!‘ ;sleep 10
reboot

三、说明

以上代码可能有点简单,但是能看懂就好,毕竟shell是基础语言。

网友评论