美文网首页
centos7系统初始化脚本

centos7系统初始化脚本

作者: jeffrey_hjf | 来源:发表于2020-11-17 11:38 被阅读0次

    [root@linux-node1 ~]# cat optimize.sh

    !/bin/bash

    ********************************************************************

    Author:

    URL:

    Date:

    FileName: centos7_reset.sh

    Description: The script for centos7 reset

    ********************************************************************

    设置命令提示符颜色

    echo 'PS1="[\e[1;31m][\u@\h \W]\$[\e[0m]"' >> /etc/profile.d/env.sh

    设置系统默认编辑器为vim

    echo export EDITOR=vim >> /etc/profile.d/env.sh

    检查脚本运行用户是否为root

    if [ $(id -u) !=0 ];then
    echo -e "\033[1;31m Error! You must be root to run this script! \033[0m"
    exit 10
    fi

    禁用selinux

    sed -ri 's/^(SELINUX=)enforcing/\1disabled/' /etc/selinux/config

    禁用防火墙

    systemctl stop firewalld.service
    systemctl disable firewalld.service

    优化ssh登录

    sed -ri 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config
    sed -ri 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config

    修改网卡名称为统一为传统方式命名

    sed -ri '/CMDLINE/s#(.*)"#\1 net.ifnames=0"#' /etc/default/grub
    grub2-mkconfig -o /etc/grub2.cfg

    禁用不需要的服务

    systemctl stop postfix.service
    systemctl disable postfix.service

    安装wget工具

    yum -y install wget

    配置系统使用阿里云yum源和EPEL源

    替换成阿里云的yum源速度更快一些,替换很简单,简单记录一下步骤
    1、备份原来的yum源
    sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

    2、安装wget工具

    yum install wget

    3、设置aliyun的yum源

    sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

    4、添加EPEL源

    EPEL(http://fedoraproject.org/wiki/EPEL)是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上 EPEL后,可以像在 Fedora 上一样,可以通过 yum install package-name,安装更多软件。

    sudo wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-7.repo

    5、清理缓存并生成新的缓存

    sudo yum clean all
    sudo yum makecache

    安装bash命令tab自动补全组件

    yum -y install bash-completion

    安装vim编辑器

    yum -y install vim screen lrzsz tree psmisc

    安装压缩解压工具

    yum -y install zip unzip bzip2 gdisk

    安装网络及性能监控工具

    yum -y install telnet net-tools sysstat iftop lsof iotop htop dstat

    安装源码编译工具及开发组件

    yum -y install cmake gcc gcc-c++ zib zlib-devel open openssl-devel pcre pcre-devel curl

    安装chrony时间同步服务

    yum -y install chrony
    systemctl enable chronyd.service
    systemctl start chronyd.service

    配置chrony时间同步阿里云ntp服务器

    sed -i -e '/server/s//#/' -e '1a server ntp.aliyun.com iburst' /etc/chrony.conf
    systemctl restart chronyd.service

    初始化完成重启系统

    echo -e "\033[1;32m System initialization is complete and will be reboot in 10s...\033[0m"
    sleep 10
    reboot

    相关文章

      网友评论

          本文标题:centos7系统初始化脚本

          本文链接:https://www.haomeiwen.com/subject/igrxiktx.html