# README
# 此脚本需要在master节点上使用
# 注意root密码,请提前修改
# 个人实验环境,注意机器最低配置:master(2G内存,1cpu2核心,否则集群会创建失败),node(各1G内存,1cpu1核心即可)
# 此脚本适用于干净环境,注意提前关闭selinux(设置为disabled)
# 此脚本仅创建完k8s集群,加入集群以及网络的配置,请手动配置
# 此脚本使用的是本地镜像导入,注意提前准备镜像,将tar包放到master机器的/root/目录下,或自定义存放,并修改脚本内的路径
# 镜像下载地址:链接:https://pan.baidu.com/s/1-r8da1KJFxiRP_nAFGUMYA 提取码:rxas (镜像包1.18G)
#!/bin/bash
# Bandian
# Date:2020/08/17
# kubeadm install kubenetes 1.18.6 check_network() {
printf "\e[1;32m###########正在检查网络######################################\e[0m\n"
ping -c1 www.baidu.com > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "网络链接失败,请检查网络"
exit
else
echo "网络链接成功,继续执行,请稍后"
fi
}
check_network # 检查防火墙和selinux
check_firewalld() {
printf "\e[1;32m###########正在检查selinux&firewalld#########################\e[0m\n"
setenforce 0 &> /dev/null && systemctl disable firewalld --now > /dev/null 2>&1
for i in node1 node2
do
ssh root@$i setenforce 0 &> /dev/null && systemctl disable firewalld --now > /dev/null 2>&1
done
} # 关闭swap分区
off_swap() {
printf "\e[1;32m###########正在关闭swap分区##################################\e[0m\n"
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
for j in node1 node2
do
ssh root@$j swapoff -a
ssh root@$j "sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab"
done
} # 创建解析
read -p "请输入master的ip地址:" master
read -p "请输入node1的ip地址:" node1
read -p "请输入node2的ip地址:" node2
printf "\e[1;32m###########正在写入hosts解析#################################\e[0m\n"
cat >> /etc/hosts <<eof
$master master
$node1 node1
$node2 node2
eof
ping -c1 master > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "解析失败,正在退出"
exit 1
else
echo "解析成功,请稍后"
fi nopasswd(){
printf "\e[1;32m###########正在创建master免密登录其他节点####################\e[0m\n"
yum -y install expect > /dev/null 2>&1
ssh-keygen -t rsa -P "" -f /root/.ssh/id_rsa
for k in master node1 node2
do
expect -c "
spawn ssh-copy-id -i /root/.ssh/id_rsa.pub root@$k
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"123.com\r\"; exp_continue}
\"*password*\" {send \"123.com\r\";}
}"
done > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "免密失败,正在退出"
exit
else
echo "免密成功,请稍后"
fi
}
nopasswd printf "\e[1;32m###########正在发送hosts文件到其他节点#######################\e[0m\n"
for l in node1 node2
do
scp /etc/hosts $l:/etc/hosts
done off_swap
check_firewalld # 设置内核参数
printf "\e[1;32m###########正在设置内核参数##################################\e[0m\n"
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
modprobe -- br_netfilter
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules for m in node1 node2
do
scp /etc/sysconfig/modules/ipvs.modules $m:/etc/sysconfig/modules/ipvs.modules
ssh root@$m chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules
done # 设置内核转发
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-ip6tables=1
net.ipv4.ip_forward=1
net.ipv4.tcp_tw_recycle=0
vm.swappiness=0
vm.overcommit_memory=1
vm.panic_on_oom=0
fs.inotify.max_user_watches=89100
fs.file-max=52706963
fs.nr_open=52706963
net.ipv6.conf.all.disable_ipv6=1
net.netfilter.nf_conntrack_max=2310720
EOF
sysctl -p /etc/sysctl.d/k8s.conf > /dev/null 2>&1 printf "\e[1;32m###########正在发送内核参数文件到其他节点####################\e[0m\n"
for n in node1 node2
do
scp /etc/sysctl.d/k8s.conf $n:/etc/sysctl.d/k8s.conf
ssh root@$n sysctl -p /etc/sysctl.d/k8s.conf > /dev/null 2>&1
done printf "\e[1;32m###########正在安装所需软件##################################\e[0m\n"
yum -y install epel-release.noarch conntrack ipvsadm ipset jq sysstat curl iptables libseccomp > /dev/null 2>&1 printf "\e[1;32m###########正在清除旧docker##################################\e[0m\n"
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 2>&1
printf "\e[1;32m###########正在安装docker####################################\e[0m\n"
yum install -y yum-utils device-mapper-persistent-data lvm2 > /dev/null 2>&1
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo > /dev/null 2>&1
yum makecache fast > /dev/null 2>&1
yum -y install docker-ce-18.09.9-3.el7
systemctl enable docker --now > /dev/null 2>&1 printf "\e[1;32m###########正在配置docker镜像加速############################\e[0m\n"
sed -i "13i ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT" /usr/lib/systemd/system/docker.service
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://bk6kzfqm.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"storage-opts": [
"overlay2.override_kernel_check=true"
]
}
EOF
systemctl daemon-reload && systemctl restart docker printf "\e[1;32m###########正在其他节点安装docker以及配置镜像加速############\e[0m\n"
for o in node1 node2
do
ssh root@$o 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 2>&1
ssh root@$o yum install -y yum-utils device-mapper-persistent-data lvm2 > /dev/null 2>&1
ssh root@$o yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo > /dev/null 2>&1
ssh root@$o yum makecache fast > /dev/null 2>&1
ssh root@$o yum -y install docker-ce-18.09.9-3.el7
ssh root@$o systemctl enable docker --now > /dev/null 2>&1
ssh root@$o "sed -i '13i ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT' /usr/lib/systemd/system/docker.service"
scp /etc/docker/daemon.json $o:/etc/docker/daemon.json
ssh root@$o systemctl daemon-reload && systemctl restart docker
done printf "\e[1;32m###########正在部署kubeadm和kubelet##########################\e[0m\n"
cat > /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
# 不加上版本号,会导致安装最新版的kubeadm、kubectl以及kubelet
yum -y install kubelet-1.18.6 kubeadm-1.18.6 kubectl-1.18.6 && systemctl enable kubelet.service --now > /dev/null 2>&1 printf "\e[1;32m###########正在部署其他节点kubeadm和kubelet##################\e[0m\n"
for p in node1 node2
do
scp /etc/yum.repos.d/kubernetes.repo $p:/etc/yum.repos.d/kubernetes.repo
ssh root@$p yum install -y yum -y install kubelet-1.18.6 kubeadm-1.18.6 kubectl-1.18.6 && systemctl enable kubelet.service --now > /dev/null 2>&1
done printf "\e[1;32m###########正在配置自动补全##################################\e[0m\n"
yum -y install bash-completion > /dev/null 2>&1
kubectl completion bash > /etc/bash_completion.d/kubectl
kubeadm completion bash > /etc/bash_completion.d/kubeadm for q in node1 node2
do
ssh root@$q yum -y install bash-completion > /dev/null 2>&1
ssh root@$q kubectl completion bash > /etc/bash_completion.d/kubectl
ssh root@$q kubeadm completion bash > /etc/bash_completion.d/kubeadm
done # 导入镜像,注意路径,请q提前上传镜像
printf "\e[1;32m###########正在导入镜像######################################\e[0m\n"
docker load -i /root/k8s-1.18.6-images.tar
printf "\e[1;32m###########正在导入镜像到其他节点#############################\e[0m\n"
for s in node1 node2
do
scp /root/k8s-1.18.6-images.tar $s:/root/
ssh root@$s docker load -i /root/k8s-1.18.6-images.tar
done
printf "\e[1;32m###########kubernetes-1.18.6集群初始化环境准备完成###########\e[0m\n"
printf "\e[1;32m###########可以开始手动添加kubernetes集群####################\e[0m\n"

利用shell脚本使用kubeadm部署kubenetes 1.18.6集群环境的更多相关文章

  1. kubeadm部署kubernetes-1.12.0 HA集群-ipvs

    一.概述 主要介绍搭建流程及使用注意事项,如果线上使用的话,请务必做好相关测试及压测. 1.基础环境准备 系统:ubuntu TLS 16.04  5台 docker-ce:17.06.2 kubea ...

  2. kubeadm部署k8s1.9高可用集群--4部署master节点

    部署master节点 kubernetes master 节点包含的组件: kube-apiserver kube-scheduler kube-controller-manager 本文档介绍部署一 ...

  3. 使用kubeadm部署K8S v1.17.0集群

    kubeadm部署K8S集群 安装前的准备 集群机器 172.22.34.34 K8S00 172.22.34.35 K8S01 172.22.34.36 K8S02 注意: 本文档中的 etcd . ...

  4. 利用 kubeasz 给 suse 12 部署 kubernetes 1.20.1 集群

    文章目录 1.前情提要 2.环境准备 2.1.环境介绍 2.2.配置静态网络 2.3.配置ssh免密 2.4.批量开启模块以及创建文件 2.5.安装ansible 2.5.1.安装pip 2.5.2. ...

  5. Centos7.5基于MySQL5.7的 InnoDB Cluster 多节点高可用集群环境部署记录

    一.   MySQL InnoDB Cluster 介绍MySQL的高可用架构无论是社区还是官方,一直在技术上进行探索,这么多年提出了多种解决方案,比如MMM, MHA, NDB Cluster, G ...

  6. ProxySQL Cluster 高可用集群环境部署记录

    ProxySQL在早期版本若需要做高可用,需要搭建两个实例,进行冗余.但两个ProxySQL实例之间的数据并不能共通,在主实例上配置后,仍需要在备用节点上进行配置,对管理来说非常不方便.但是Proxy ...

  7. Rancher2.x 一键式部署 Prometheus + Grafana 监控 Kubernetes 集群

    目录 1.Prometheus & Grafana 介绍 2.环境.软件准备 3.Rancher 2.x 应用商店 4.一键式部署 Prometheus 5.验证 Prometheus + G ...

  8. 利用shell脚本或者php移动某个文件夹下的文件到各自的日期组成的目录下

    背景是这样的:网站一开始访问量比较小,大家就把所有的图片文件上传到一个目录下(比如是/data/images/).后来访问量大了,图片也多了,这样就影响读取效率.所以有个这样的需求,把这些个图片文件移 ...

  9. 利用shell脚本去备份幸运28源码搭建下载所指定的数据库

    #! /bin/bash幸运28源码搭建下载Q[115288oo99]logintool=/home/yx/server/mysql/mysql/bin/mysqldumptool=/home/yx/ ...

随机推荐

  1. 第10组 Alpha冲刺 (6/6)

    1.1基本情况 ·队名:今晚不睡觉 ·组长博客:https://www.cnblogs.com/cpandbb/p/14008187.html ·作业博客:https://edu.cnblogs.co ...

  2. hisql ORM 查询语句使用教程

    HiSql 提供一个可以适合多种数据库的中间查询语法,不需要关注各个数据库的语法特性,通过HiSql写语句可以在常用的不同类型数据库中执行,且语法与Sql语境类似一看就懂一学就会 hisql.net ...

  3. Autofac实现有条件的DI

    Autofac.Annotation框架是我用.netcore写的一个DI框架,基于Autofac参考 Spring注解方式所有容器的注册和装配,切面,拦截器等都是依赖标签来完成. 开源地址:http ...

  4. 友善之臂mini2440光盘资料下载FriendlyARM-2440-DVD.7z

    这是我目前找到最全面的友善之臂mini2440的光盘资料了,几乎支持mini2440的各种lcd屏幕.另外,Windows平台工具文件夹下还有版本比较新的MiniTools,这是一个非常好用的软件! ...

  5. 【数据结构】图的基本操作——图的构造(邻接矩阵,邻接表),遍历(DFS,BFS)

    邻接矩阵实现如下: /* 主题:用邻接矩阵实现 DFS(递归) 与 BFS(非递归) 作者:Laugh 语言:C++ ***************************************** ...

  6. springboot打包第三方jar包是失败

    在项目开发时有时我们需要引入一些在maven仓库中不存在的包 一.配置maven环境变量 在path环境变量中添加 %maven_home%\bin (window10环境下) cmd界面输入 mvn ...

  7. Flowable实战(六)集成JPA

      上文提到,Flowable所有的表单数据都保存在一张表(act_hi_varinst)中,随着时间的推移,表中数据越来越多,再加上数据没有结构优化,查询使用效率会越来越低.   在Flowable ...

  8. XRecyclerView:实现下拉刷新、滚动到底部加载更多以及添加header功能的RecyclerView

    介绍: 一个实现了下拉刷新,滚动到底部加载更多以及添加header功能的的RecyclerView.使用方式和RecyclerView完全一致,不需要额外的layout,不需要写特殊的adater. ...

  9. day 20 C语言顺序结构基础3

    (1).若有定义:int a=100:则语句printf("%d%d%d\n",sizeof("a"),sizeof(a),sizeof(3.14)); 则输出 ...

  10. 设置图片DPI

    //image 可以先转换为 bitmap Bitmap bmp = new Bitmap(width, height); bmp.SetResolution(300, 300);