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

本文提供了在Ubuntu 18.04上进行k8s实验前,用于批量配置sysctl.conf和limits.conf的bash脚本。脚本包括加载必要模块、修改配置文件并重启以使更改生效,以及后续的系统调整,如关闭swap、禁用selinux和清理iptables。

因为要配置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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值