快捷搜索:

您的位置:澳门新葡4473网站 > 项目 > shell搭建CentOS_7基础环境

shell搭建CentOS_7基础环境

发布时间:2019-10-19 03:00编辑:项目浏览(176)

    #!/bin/bash
    #Auth:Darius
    #自动化安装dhcp服务
    #"$1"为测试IP,用来查看IP段是否能通
    eno=`ifconfig|awk '{print $1}'|head -1|awk -F ":" '{print $1}'`
    file=/etc/sysconfig/network-scripts/ifcfg-$eno
    file1=/etc/dhcp/dhcpd.conf
    dir=/etc/yum.repos.d
    #ip地址设置
    ping -c 4 -i 0.1 -W 2 $1 &>/dev/null
    if [ $? -ne 0 ];then
    echo -e "DEVICE=$enonTYPE=EthernetnONBOOT=yesnBOOTPROTO=static" >$file
    read -p "请输入ip地址": ip
    read -p "请输入子网掩码": nt
    read -p "请输入网关": gw
    echo "IPADDR=$ip" >> $file
    echo "NETMASK=$nt" >>$file
    echo "GATEWAY=$gw" >>$file
    if [ $? -eq 0 ]
    then
    [ $? -eq 0 ] && echo "IP地址配置成功"
    else
    echo "IP地址配置失败"
    fi
    else
    echo "网络测试成功"
    fi
    #构建yum本地仓库
    mkdir /media/cdrom
    mount /dev/sr0 /media/cdrom/
    #设置光盘自动挂载
    echo "/dev/sr0 /media/cdrom iso9660 defaults 0 0" >> /etc/fstab
    mkdir $dir/bak
    mv $dir/C* $dir/bak/
    echo -e "[yum]nname=yumnbaseurl=file:///media/cdromngpgcheck=0nenabled=1" >$dir/yum.repo
    yum clean all &>/dev/null
    yum makecache &>/dev/null
    echo "yum仓库构建完成"
    #检测并安装dhcp服务
    yum install -y dhcp &>/dev/null
    echo "dhcp服务安装成功"
    cat /usr/share/doc/dhcp*/dhcpd.conf.sample >$file1
    [ $? -eq 0 ] && echo "模板复制成功"
    cp $file1 /etc/dhcp/dhcpd.conf.bak
    echo -e "subnet 192.168.1.0 netmask 255.255.255.0{nrange 192.168.1.2 192.168.1.100;noption routers 192.168.1.1;n}" >>$file1
    echo "文件配置完成"
    service dhcpd start &>/dev/null
    chkconfig dhcpd on &>/dev/null
    [ $? -eq 0 ] && echo "dhcp服务已启动"

    #!/bin/bash
    #Auth:Darius
    #CentOS_7配置实验环境
    eno=`ifconfig|awk '{print $1}'|head -1|awk -F ":" '{print $1}'`
    file=/etc/sysconfig/network-scripts/ifcfg-$eno
    dir=/etc/yum.repos.d
    #关闭防火墙
    systemctl stop firewalld.service
    systemctl disable firewalld.service
    #查看防火墙是否开启
    firewall-cmd --state
    #清空防火墙规则
    iptables -F
    #临时关闭selinux
    setenforce 0

    #永久关闭selinux
    sed -i 's/=enforcing/=disabled/' /etc/sysconfig/selinux
    sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
    #修改主机名
    echo "当前主机名:$(hostname)"
    read -p "请输入新主机名:" hostname_input
    hostname $hostname_input &> /dev/null
    hostnamectl set-hostname $hostname_input &> /dev/null

    #ip地址设置
    rm -rf /etc/udev/*
    echo -e "DEVICE=$enonTYPE=EthernetnONBOOT=yesnBOOTPROTO=static" >$file
    read -p "请输入ip地址": ip
    read -p "请输入子网掩码": nt
    read -p "请输入网关": gw
    echo "IPADDR=$ip" >> $file
    echo "NETMASK=$nt" >>$file
    echo "GATEWAY=$gw" >>$file
    [ $? -eq 0 ] && echo "IP地址配置成功"
    #构建yum本地仓库
    mkdir /media/cdrom
    mount /dev/sr0 /media/cdrom/
    #设置光盘自动挂载
    echo "/dev/sr0 /media/cdrom iso9660 defaults 0 0" >> /etc/fstab
    mkdir $dir/bak
    mv $dir/C* $dir/bak/
    echo -e "[yum]nname=yumnbaseurl=file:///media/cdromngpgcheck=0nenabled=1" >$dir/yum.repo
    yum clean all &>/dev/null
    yum makecache &>/dev/null
    echo "yum仓库构建完成"
    yum install -y vim gcc gcc-c++ make &>/dev/null

    本文由澳门新葡4473网站发布于项目,转载请注明出处:shell搭建CentOS_7基础环境

    关键词:

上一篇:Windows forfiles(删除历史文件)

下一篇:没有了