因为要配置3台master和3台node,一个一个配置环境比较麻烦,写了个简单脚本跑一下
下面两个配置是加载模块,我的实验环境下缺少这个,所以需要先加载一下
modprobe br_netfilter
modprobe ip_conntrack
limits.conf 文件修改后需要重启才能生效,所以脚本最后增加了重启
==========================
更新了一下,重启以后会失效,需要把模块写入/etc/modules,重启时才会自动加载
cat >> /etc/modules << EOF
br_netfilter
ip_conntrack
EOF
==========================
顺便再增加一点,关闭swap,selinux,清空iptables
以下为完整脚本
#!/bin/bash
echo "step 0 start...!"
swapoff -v /swapfile
rm /swapfile
free -m
ufw disable
iptables -F
modprobe br_netfilter
modprobe ip_conntrack
sleep 1
cat >> /etc/modules << EOF
br_netfilter
ip_conntrack
EOF
echo "step 0 ok"
sleep 1
echo "step 1 start..."
sleep 1
cat >> /etc/sysctl.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-arptables = 1
net.ipv4.tcp_tw_reuse = 0
net.core.somaxconn = 32768
net.netfilter.nf_conntrack_max=1000000
vm.swappiness = 0
vm.max_map_count = 655360
fs.file-max = 6553600
EOF
sleep 1
sysctl -p
echo "step 1 ok"
sleep 1
echo "step 2 start..."
cat >> /etc/security/limits.conf << EOF
* soft core unlimited
* hard core unlimited
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
* soft memlock 32000
* hard memlock 32000
* soft msgqueue 8192000
* hard msgqueue 8192000
root soft core unlimited
root hard core unlimited
root soft nproc 1000000
root hard nproc 1000000
root soft nofile 1000000
root hard nofile 1000000
root soft memlock 32000
root hard memlock 32000
root soft msgqueue 8192000
root hard msgqueue 8192000
EOF
sleep 1
echo "step 2 ok"
sleep 1
echo "finish all !"
sleep 1
echo "ready to reboot ...."
sleep 1
reboot
本文提供了在Ubuntu 18.04上进行k8s实验前,用于批量配置sysctl.conf和limits.conf的bash脚本。脚本包括加载必要模块、修改配置文件并重启以使更改生效,以及后续的系统调整,如关闭swap、禁用selinux和清理iptables。
1493

被折叠的 条评论
为什么被折叠?



