Linux最全干货!超实用的 Linux 初始化脚本_linux初始化脚本(1),带你快速通过字节跳动面试

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

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

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

在这里插入图片描述
写入一行配置
在这里插入图片描述
修改配置
在这里插入图片描述

配置系统时区
在这里插入图片描述

配置 dns 服务器
在这里插入图片描述

修改最大文件描述符限制
在这里插入图片描述

关闭系统不需要的服务
在这里插入图片描述

内核参数优化相关
在这里插入图片描述

安装常用工具

在这里插入图片描述

关闭 SELinux
在这里插入图片描述

主函数
在这里插入图片描述

完整脚本


#环境变量
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

#当前时间
current\_time=$(date +%Y%m%d)

#阿里的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 >> $2
  else
    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.${current\_time} > /dev/null 2>&1
  arch\_ratio=$([[ ! -z $(uname -a | grep x86\_64) ]] && expr 64 / 32 || expr 32 / 32)
  memory\_size=$(free -b| awk 'NR==2{print $2}')
  nf\_conntrack\_size=$(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


![](https://img-blog.csdnimg.cn/img_convert/9a8cb5f8c0ec69e6499adead0da6e95b.png)


最全的Linux教程,Linux从入门到精通

======================

1.  **linux从入门到精通(第2版)**

2.  **Linux系统移植**

3.  **Linux驱动开发入门与实战**

4.  **LINUX 系统移植 第2版**

5.  **Linux开源网络全栈详解 从DPDK到OpenFlow**



![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/59742364bb1338737fe2d315a9e2ec54.png)



第一份《Linux从入门到精通》466页

====================

内容简介

====

本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。另外,本书还为读者提供了大量的Linux学习资料和Ubuntu安装镜像文件,供读者免费下载。



![华为18级工程师呕心沥血撰写3000页Linux学习笔记教程](https://img-blog.csdnimg.cn/img_convert/9d4aefb6a92edea27b825e59aa1f2c54.png)



**本书适合广大Linux初中级用户、开源软件爱好者和大专院校的学生阅读,同时也非常适合准备从事Linux平台开发的各类人员。**

> 需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论




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

**[需要这份系统化的资料的朋友,可以点击这里获取!](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)**

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

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值