Linux最全干货!超实用的 Linux 初始化脚本_linux初始化脚本,2024年最新一个小例子彻底搞懂Linux运维的MVP模式到底是什么

最后的话

最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!

资料预览

给大家整理的视频资料:

给大家整理的电子书资料:

如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

#阿里的DNS
dns_server=223.5.5.5

if [[ ! -z uname -r|grep 'el6' ]]
then
kernel_version=el6
yum_repo=http://mirrors.aliyun.com/repo/Centos-6.repo
elif [[ ! -z uname -r|grep 'el7' ]]
then
kernel_version=el7
yum_repo=http://mirrors.aliyun.com/repo/Centos-7.repo
else
echo -e “\e[31mUnidentified Kernel version: $(uname -r). Only support for kernel el6/el7\e[0m”
exit
fi

function add_yum_repo(){
local item=“Add Aliyun Yum Mirrors”
yum clean all
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.${current_time} &&
curl -o /etc/yum.repos.d/CentOS-Base.repo ${yum_repo} > /dev/null 2>&1
show_result ? " ? " ?"{item}"
yum makecache
}

function show_result(){
if [ “$1” -eq 0 ]
then
echo -e “\e[32m$2 is Success . [ OK ] \e[0m”
else
echo -e “\e[31m$2 is Fail . [ FAIL ] \e[0m”
fi
}

function add_newconfig_tofile(){
local SearchResult=grep "$1" "$2"
if [ -z “${SearchResult}” ]
then
echo “$1” >> $2
fi
}

function add_config_tofile(){
local keywords=echo $1| awk -F "[= ]+" '{print $1}'
local SearchResult=grep "^${keywords}" "$2"
if [ -z “${SearchResult}” ] #空为真,非空为假
then
echo $1 >> KaTeX parse error: Expected group after '^' at position 24: … sed -i "s/^̲{keywords}.*/$1/" $2
fi
}

function config_localtime(){
local item=“Config SH As Location”
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
show_result ? " ? " ?"{item}"
}

function config_dns_addr(){
local item=“Config DNS Address”
cp /etc/resolv.conf /etc/resolv.conf.${current_time} &&
echo “nameserver ${dns_server}” > /etc/resolv.conf
show_result ? " ? " ?"{item}"
}

function maximum_file_dspt(){
local item=“Maximum File Descriptor”
cp /etc/security/limits.conf /etc/security/limits.conf.${current_time} &&
echo “* soft nofile 100000
* hard nofile 100000
* soft nproc 65535
* hard nproc 65535
* soft core unlimited
* hard core unlimited” > /etc/security/limits.conf
show_result ? " ? " ?"{item}"
}

function shutdown_nonuse_srv(){
local item=“Shutdown Unused Services”
if [[ “${kernel_version}” == el6 ]]
then
for i in chkconfig --list | awk '{print $1}'
do
chkconfig --level 2345 $i off > /dev/null 2>&1
done
for ii in crond network rsyslog sshd sysstat haldaemon
do
chkconfig --level 2345 $ii on > /dev/null 2>&1
done
show_result ? " ? " ?"{item}"
elif [[ “${kernel_version}” == el7 ]]
then
systemctl disable postfix > /dev/null 2>&1
show_result ? " ? " ?"{item}"
else
echo -e “\e[31mUnidentified Kernel version: $(uname -r). Only support for kernel el6/el7\e[0m”
fi
}

function optimize_kel_args(){
local item=“Optimize Kernel Arguments”
cp /etc/sysctl.conf /etc/sysctl.conf.KaTeX parse error: Expected 'EOF', got '&' at position 31: … > /dev/null 2>&̲1 arch\_ratio…([[ ! -z KaTeX parse error: Expected 'EOF', got '&' at position 30: …ep x86\_64) ]] &̲& expr 64 / 32 …(free -b| awk 'NR==2{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') nf\_conntr…(expr ${memory_size} / 16384 / ${arch_ratio})
#开启反向路径过滤
add_config_tofile “net.ipv4.conf.default.rp_filter = 1” /etc/sysctl.conf
add_config_tofile “net.ipv4.conf.all.rp_filter = 1” /etc/sysctl.conf
#处理无源路由包
add_config_tofile “net.ipv4.conf.all.accept_source_route = 0” /etc/sysctl.conf
add_config_tofile “net.ipv4.conf.default.accept_source_route = 0” /etc/sysctl.conf
#core文件名中添加pid作为扩展名
add_config_tofile “kernel.core_uses_pid = 1” /etc/sysctl.conf
#开启syn洪水攻击保护
add_config_tofile “net.ipv4.tcp_syncookies = 1” /etc/sysctl.conf
#修改消息队列长度
add_config_tofile “kernel.msgmnb = 65536” /etc/sysctl.conf
add_config_tofile “kernel.msgmax = 65536” /etc/sysctl.conf
#修改最大内存共享段大小bytes
add_config_tofile “kernel.shmmax = 68719476736” /etc/sysctl.conf
add_config_tofile “kernel.shmall = 4294967296” /etc/sysctl.conf
#timewait数量默认18000
add_config_tofile “net.ipv4.tcp_max_tw_buckets = 600” /etc/sysctl.conf
add_config_tofile “net.ipv4.tcp_sack = 1” /etc/sysctl.conf
add_config_tofile “net.ipv4.tcp_window_scaling = 1” /etc/sysctl.conf
add_config_tofile “net.ipv4.tcp_rmem = 4096 87380 16777216” /etc/sysctl.conf
add_config_tofile “net.ipv4.tcp_wmem = 4096 65536 16777216” /etc/sysctl.conf
add_config_tofile “net.core.rmem_default = 8388608” /etc/sysctl.conf
add_config_tofile “net.core.wmem_max = 16777216” /etc/sysctl.conf
#未收到客户端确认信息连接请求的最大值
add_config_tofile “net.ipv4.tcp_max_syn_backlog = 262144” /etc/sysctl.conf
#放弃建立连接之前发送的synack包
add_config_tofile “net.ipv4.tcp_syn_retries = 2” /etc/sysctl.conf
#开启重用,允许time—wait socket 重新用语新的tcp连接
add_config_tofile “net.ipv4.tcp_tw_reuse = 1” /etc/sysctl.conf
add_config_tofile “net.ipv4.tcp_fin_timeout = 1” /etc/sysctl.conf
#防止简单的ddos攻击
add_config_tofile “net.ipv4.tcp_max_orphans = 3276800” /etc/sysctl.conf
#启用timewait快速收回
add_config_tofile “net.ipv4.tcp_tw_recycle = 0” /etc/sysctl.conf
#keeptime启用时tcp发送keepalive消息的频度,默认2h
add_config_tofile “net.ipv4.tcp_keepalive_time = 600” /etc/sysctl.conf
#允许系统打开的端口范围
add_config_tofile “net.ipv4.ip_local_port_range = 1024 65535” /etc/sysctl.conf
#资源回收
add_config_tofile “net.ipv4.tcp_tw_recycle = 0” /etc/sysctl.conf
#路由转发
add_config_tofile “net.ipv4.ip_forward = 1” /etc/sysctl.conf
#修改防火墙连接跟踪表大小,默认65535
add_config_tofile “net.netfilter.nf_conntrack_max = ${nf_conntrack_size}” /etc/sysctl.conf
add_config_tofile “net.nf_conntrack_max = ${nf_conntrack_size}” /etc/sysctl.conf
#解禁ping
add_config_tofile “net.ipv4.icmp_echo_ignore_all = 0” /etc/sysctl.conf
modprobe bridge
sysctl -p > /dev/null 2>&1
show_result ? " ? " ?"{item}"
}

function install_pkgs(){
local item=“Install Common Pkgs”
yum -y groupinstall “Development libraries” > /dev/null 2>&1

最后的话

最近很多小伙伴找我要Linux学习资料,于是我翻箱倒柜,整理了一些优质资源,涵盖视频、电子书、PPT等共享给大家!

资料预览

给大家整理的视频资料:

给大家整理的电子书资料:

如果本文对你有帮助,欢迎点赞、收藏、转发给朋友,让我有持续创作的动力!

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

究,那么很难做到真正的技术提升。**

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

  • 22
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值