zoukankan      html  css  js  c++  java
  • centos系统初始化脚本

    centos6

    作用:配置ip、yum源、ntp、关闭selinux、iptables

    #!/bin/bash
    # configure network
    cat >/etc/sysconfig/network-scripts/ifcfg-eth0<<EOF
    DEVICE=eth0
    NAME="eth0"
    TYPE=Ethernet
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=192.168.126.10
    PREFIX=24
    GATEWAY=192.168.126.2
    DNS1=114.114.114.114
    EOF
    
    # configure yum
    [ -e /yum ]|| mkdir /yum
    [ -e /dev/cdrom ]&& mount /dev/cdrom /yum
    echo "/dev/cdrom   /yum   iso9660 defaults   0 0" >>/etc/fstab
    mkdir /etc/yum.repos.d/bak 
    mv /etc/yum.repos.d/Cen* /etc/yum.repos.d/bak/
    cat > /etc/yum.repos.d/local.repo <<EOF
    [local]
    name=local
    baseurl=file:///yum
    enabled=1
    gpgcheck=0
    EOF
    
    yum clean all
    yum makecache
    yum -y install lsof wget sysstat vim lftp man ntp xorg-x11-xauth
    
    # configure ssh
    sed -i 's/^GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config
    sed -i '/UseDNS/c\UseDNS no' /etc/ssh/sshd_config
    
    # configure iptables selinux
    sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
    chkconfig iptables off
    chkconfig ip6tables off
    
    # configure ntp
    sed -i 's/^server/#server/' /etc/ntp.conf
    echo "server time1.aliyun.com iburst" >> /etc/ntp.conf
    echo "server time2.aliyun.com iburst" >> /etc/ntp.conf
    chkconfig ntpd on
    
    reboot

    centos7

    作用:配置ip、yum源、chrony、关闭selinux、firewalld

    #!/bin/bash
    # configure network
    cat >/etc/sysconfig/network-scripts/ifcfg-ens33<<EOF
    DEVICE=ens33
    TYPE=Ethernet
    ONBOOT=yes
    BOOTPROTO=static
    IPADDR=192.168.126.20
    PREFIX=24
    GATEWAY=192.168.126.2
    DNS1=114.114.114.114
    EOF
    
    # configure yum
    [ -e /yum ]|| mkdir /yum
    [ -e /dev/cdrom ]&& mount /dev/cdrom /yum
    echo "/dev/cdrom   /yum   iso9660   defaults   0 0" >>/etc/fstab
    mkdir /etc/yum.repos.d/bak 
    mv /etc/yum.repos.d/Cen* /etc/yum.repos.d/bak/
    cat > /etc/yum.repos.d/local.repo <<EOF
    [local]
    name=local
    baseurl=file:///yum
    enabled=1
    gpgcheck=0
    EOF
    
    yum clean all
    yum makecache
    yum -y install lsof wget sysstat vim lftp chrony bash-completion xorg-x11-xauth
    
    # configure ssh
    sed -i 's/^GSSAPIAuthentication yes/GSSAPIAuthentication no/' /etc/ssh/sshd_config
    sed -i '/UseDNS/c\UseDNS no' /etc/ssh/sshd_config
    
    # configure firewalld selinux
    sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
    systemctl disable firewalld
    systemctl disable NetworkManager
    
    # configure chrony
    sed -i 's/^server/#server/' /etc/chrony.conf
    echo "server time1.aliyun.com iburst" >> /etc/chrony.conf
    echo "server time2.aliyun.com iburst" >> /etc/chrony.conf
    systemctl enable chronyd
    
    chmod a+x /etc/rc.d/rc.local
    
    reboot
    本文作者:fcing
    本文出处:https://www.cnblogs.com/fcing
    版权声明:本博客所有文章除特别声明外,均采用CC BY-NC-SA 4.0 许可协议。转载请注明出处!
  • 相关阅读:
    NOI模拟赛 6.20
    NOI模拟赛 6.17
    NOI模拟赛 6.16
    计算几何学习笔记
    NOI(p)模拟赛 5.30
    NOI模拟赛 5.26
    [AGC022E] Median Replace 题解
    看完魔圆之后的一点感想(大概
    OI学习日志 11月份
    2021 CSP-S 游记
  • 原文地址:https://www.cnblogs.com/fcing/p/9349082.html
Copyright © 2011-2022 走看看