美文网首页
2019-02-16

2019-02-16

作者: 三生之幸 | 来源:发表于2019-02-16 14:40 被阅读0次
    #!/usr/bin/env bash
    red='\e[31m'
    end='\e[0m'
    while read -p "请输入您要设定的主机名:" name
    do
        read -p "Are sure your hostname[y/n]: " var
        if [ "$var" == "y" -o "$var" == "yes" ];then
            hostnamectl set-hostname $name
            break
        else
            echo "重新输入"
    fi
    done
    ip=`ip a show eth0 |grep 'inet ' |awk '{print $2}' |awk -F"/" '{print $1}'`
    sed -ri '$a'"$ip $name" /etc/hosts
    
    
    echo -e "$red 清空防火墙 $end"
    systemctl stop firewalld && systemctl disable firewalld
    
    echo -e "$red 关闭selinux $end"
    setenforce 0
    sed -ri '/^SELINUX=/ c SELINUX=disabled' /etc/selinux/config 
    
    yum_dir=/etc/yum.repos.d
    back_dir=$yum_dir/backup
    echo -e "$red 配置yum源 $end"
    if [ ! -d $back_dir ];then
        mkdir -p $back_dir
    fi
    mv $yum_dir/*.repo $back_dir
    if ! rpm -q wget &>/dev/null ;then
        cat > $yum_dir/ftp.repo <<-EOF
        [ftp]
        name=ftp
        baseurl=ftp://10.18.40.100/centos7u3
        gpgcheck=0
        EOF
        if [ $? -eq 0 ];then
            yum -y install wget
            rm -rf $yum_dir/ftp.repo
        fi
    fi
    
    wget -P /etc/yum.repos.d/ ftp://10.18.42.13/repo/163.repo
    yum makecache
    
    echo -e "$red install epel-release $end"
    if rpm -q epel-release &>/dev/null
    then
        rpm -e epel-release && yum -y install epel-release
    else
        yum -y install epel-release
    fi
    echo -e "$red install init soft $end"
    yum -y install vim bash-completion psmisc lftp tree chrony
    
    echo -e "$red  modify sshd_config $end"
    sed -ri '/^GSSAPIA/ s/yes/no/' /etc/ssh/sshd_config 
    sed -i '$a UseDNS no' /etc/ssh/sshd_config
    systemctl restart sshd
    
    echo -e "$red  同步时间 $end"
    sed -ri 's/^(server)/#\1/' /etc/chrony.conf
    sed -ri '/^#server 3/ a server 10.18.42.13 iburst' /etc/chrony.conf
    systemctl restart chronyd
    systemctl enable chronyd
    

    相关文章

      网友评论

          本文标题:2019-02-16

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