1 Star 0 Fork 0

Rkun18/configfiles_or_scripts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
k8s-environment-ini.bash 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
Rkun18 提交于 2023-05-19 19:45 +08:00 . k8s环境初始化
#!/bin/bash
#设置你的主机名或者域名
echo "请输入你要设置的主机名或者域名 :"
read vm_name
hostnamectl set-hostname --static $vm_name
#安装vim编辑器
yum install -y vim
#主机名解析
cat >> /etc/hosts <<EOF
#你每台主机的IP地址 和你自己设置的主机名或者域名 这几行都是可以你自己设置的
IP1 NAME1
IP2 NAME2
IP3 NAME3
EOF
#时间同步
#k8s要求集群中节点时间必须精确一致,这里直接使用chronyd 同步网络时间
systemctl start chronyd
systemctl enable chronyd
#关闭firewalld
systemctl stop firewalld
systemctl disable firewalld
#关闭selinux
sed -i '/SELINUX/{s/enforcing/disabled/}' /etc/selinux/config
#禁用swap分区
sed -i '/\/dev\/mapper\/centos-swap/s/^/#/' /etc/fstab
#修改linux内核参数,添加网桥过滤和地址转发功能
echo "net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1 " > /etc/sysctl.d/kubernets.conf
#重新加载配置
sysctl -p
#加载网桥过滤
modprobe br_netfilter
#查看模块是否加载成功
if ! lsmod | grep br_netfilter &>/dev/null; then
echo "模块 br_netfilter 未成功加载"
else
echo "模块 br_netfilter 已成功加载"
fi
#配置ipvs功能
#安装ipset和ipvsadmin
yum install ipset ipvsadmin -y
#添加需要加载的模块写入脚本
cat <<EOF > /etc/sysconfig/modules/ipvs.modules
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF
#为脚本添加可执行权限
chmod u+x /etc/sysconfig/modules/ipvs.modules
#执行脚本文件
/bin/bash /etc/sysconfig/modules/ipvs.modules
#查看模块是否加载成功
echo "ipvs.modules 模块载入情况 : "
lsmod | grep -e ip_vs -e nf_conntrack_ipv4
#步骤完成后,需要重新启动linux系统
echo "脚本执行完毕,是否重启 [y/n] ?"
read choice
if [ "$choice" == "y" ] ; then
echo "重启"
reboot
else
echo "稍后请你自行重启"
fi
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Rkun18/shell-script-case.git
git@gitee.com:Rkun18/shell-script-case.git
Rkun18
shell-script-case
configfiles_or_scripts
master

搜索帮助