记录ubuntu1804做k8s实验前,sysctl.conf和limits.conf配置脚本

因为要配置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

你可能感兴趣的:(运维,linux,k8s实验,bash,linux,开发语言)