首页 > 代码库 > centoa7.1 minimal 新机配置步骤及其脚本

centoa7.1 minimal 新机配置步骤及其脚本

一、手动部分 (目的是链接CRT)

root 登陆后

1图形配置IP方法:

命令 nmtui 进入图像界面配置ip

    1 编辑链接

技术分享

    2选择网卡并进入编辑页

技术分享

技术分享

中文对比

技术分享


    3 默认是激活的(*为已激活)

     

    4 设置主机名


重启reboot后即可用CRT链接之

systemctl restart network

完毕


2 配置文件方法:

1 输入配置信息

TYPE="Ethernet"

BOOTPROTO="none"

DEFROUTE="yes"

IPV4_FAILURE_FATAL=yes

NAME="eno16777736"

UUID="3df58a29-8e45-4475-b0e2-b0c474f9e53a"

DEVICE="eno16777736"

ONBOOT="yes"

HWADDR="00:0C:29:F5:D5:70"

DNS1="202.96.134.133"

DNS2=8.8.8.8

IPADDR=192.168.10.139

PREFIX=24

GATEWAY=192.168.10.1


重启网络

systemctl restart network

systemctl status network



二、脚本部分1 (详细配置)

用winscp上传脚本 xinconf1.sh 到ROOT家目录并且用用CRT远程工具链接

内容如下


#!/bin/bash

# set -x

#. /etc/profile

#-------------------------

#Sys:           centos7

#Date:          2016-01-20

#Author:        litao

#Mail:          88643217@qq.com

#Function:      static_ip

#Version:       1.0

#Using method:  IP NETMASK NETWORK GATEWAY NO_SELINUNX HOST DNS HOSTNAME

#-------------------------

Network_Path=/etc/sysconfig/network-scripts

echo "##### root_authority #####"

sleep 1

if [ `id -u` -eq 0 ]

        then

                echo " root authority yes "

        else

                echo " root authority no "

        exit 1

fi

#-------------------------

ls /etc/sysconfig/network-scripts/ | grep ifcfg | grep -v ifcfg-lo | cut -d‘-‘ -f2

会显示为 eno16777736

echo "##### ethN_peizhi #####"

read -p " eth0 | 1 | n :" N


until grep "eth$N" $Network_Path/ifcfg-eth$N >/dev/null

 do

        echo "NO_There eth$N"

        read -p "eth0 | 1 | n :" N

 done

echo "##### eth$N_OK #####" 

#-------------------------

echo " ### IP/ONBOOT/NM_CONTROLLED/BOOTPROTO/ARPCHECK ###"

read -p " ech$N NOW IPADDR= : " NOW_IP

echo "$NOW_IP"

if grep "IPADDR=" $Network_Path/ifcfg-eth$N >/dev/null

        then

                sed -i "s@`grep "IPADDR" $Network_Path/ifcfg-eth$N`@IPADDR=$NOW_IP@g" $Network_Path/ifcfg-eth$N

        else

                echo "IPADDR=$NOW_IP" >>$Network_Path/ifcfg-eth$N

fi

sed -i "s@`grep "ONBOOT" $Network_Path/ifcfg-eth$N`@ONBOOT=yes@g" $Network_Path/ifcfg-eth$N

sed -i "s@`grep "NM_CONTROLLED" $Network_Path/ifcfg-eth$N`@NM_CONTROLLED=no@g" $Network_Path/ifcfg-eth$N

sed -i "s@`grep "BOOTPROTO" $Network_Path/ifcfg-eth$N`@BOOTPROTO=static@g" $Network_Path/ifcfg-eth$N

sed -i "s@`grep "ARPCHECK" $Network_Path/ifcfg-eth$N`@ARPCHECK=no@g" $Network_Path/ifcfg-eth$N

#-------------------------

echo " #####  NETMASK  #####"

read -p "  NETMASK= : " MASKS

echo " NETMASK=$MASKS "

if grep "NETMASK=" $Network_Path/ifcfg-eth$N >/dev/null

        then

                sed -i "s@`grep "NETMASK" $Network_Path/ifcfg-eth$N`@NETMASK=$MASKS@g" $Network_Path/ifcfg-eth$N

        else

                echo "NETMASK=$MASKS" >>$Network_Path/ifcfg-eth$N

fi

#-------------------------

echo " #####  NETWORK  #####"

read -p "  NETWORK= : " WORK

echo " NETWORK=$WORK "

if grep "NETWORK=" $Network_Path/ifcfg-eth$N >/dev/null

        then

                sed -i "s@`grep "NETWORK" $Network_Path/ifcfg-eth$N`@NETWORK=$WORK@g" $Network_Path/ifcfg-eth$N

        else

                echo "NETWORK=$MASKS" >>$Network_Path/ifcfg-eth$N

fi

#-------------------------

echo " #####  NETWORK  #####"

read -p "GATEWAY= :  " GW

echo " GATEWAY=$GW "

grep GATEWAY $Network_Path/ifcfg-eth$N >/dev/null


if grep "GATEWAY=" $Network_Path/ifcfg-eth$N >/dev/null

        then

                sed -i "s@`grep "GATEWAY" $Network_Path/ifcfg-eth$N`@GATEWAY=$GW@g" $Network_Path/ifcfg-eth$N

        else

                echo "GATEWAY=$GW" >>$Network_Path/ifcfg-eth$N

fi

#-------------------------

echo " #####  DOWN_SELINUNX  #####"

read -p "DOWN_SELINUNX= yes | no  : " SE

if [ $SE == yes ]

        then          

            sed -i ‘s#SELINUX=.*#SELINUX=disabled#g‘ /etc/selinux/config

        else [ $SE == no ]

            sed -i ‘s#SELINUX=.*#SELINUX=enforcing#g‘ /etc/selinux/config

fi

#-------------------------

echo " #####  DNS  #####"

read -p "NOW_1_NAMESERVER= : " DNSIP

echo "NOW_1_NAMESERVER=$DNSIP"

echo " " >/etc/resolv.conf

echo "nameserver $DNSIP" >>/etc/resolv.conf

read -p "NOW_2_NAMESERVER=? : " DNSIP2

echo "NOW_2_NAMESERVER=$DNSIP2"

echo "nameserver $DNSIP2" >>/etc/resolv.conf

#-------------------------

echo " #####  HOSTNAME  #####"

read -p "HOSTNAME= : " HS

echo "HOSTNAME=$HS"

sed -i "s@`grep "HOSTNAME=" /etc/sysconfig/network`@HOSTNAME=$HS@g" /etc/sysconfig/network

echo "$NOW_IP $HS" >>/etc/hosts

echo "order hosts,bind" >>/etc/hosts

echo "multi on" >>/etc/hosts

echo "nospoof on" >>/etc/hosts


echo " #### RESTART NETWORK_and__REBOOT #### "



三、脚本部分2 (详细配置)

用winscp上传脚本 xinconf2.sh 到ROOT家目录并且用用CRT远程工具链接

xinconf2.sh

内容如下:

1 检查测试网络:网卡IP 主机名 DNS 系统版本 ping网络通否

2 创建普通登录用户 XXX并给密码

3 sudo授权管理,免密码

4 删除危险用户个组

5 改远程端口3389为原来的22,拒绝ROOT远程,禁用空密码

6 防止Ctrl-Alt-Del组合件错误重启


#!/bin/bash

ifconfig | grep "inet addr"

echo "######################################"

hostname

echo "######################################"

cat /etc/resolv.conf

echo "######################################"

uname -a

echo "######################################"

ping -w 1 -c 1 127.0.0.1>/dev/null

if [ $? -eq 0 ];then
      echo " 127.0.0.1 is up "
else
      echo "127.0.0.1 is down"

fi

#-------------------------------------------

ping -w 1 -c 1 `ip route show | grep default | awk  ‘{print $3}‘`>/dev/null

if [ $? -eq 0 ];then
      echo " GATEWAY is up "

else
      echo "GATEWAY is down"

fi

#-------------------------------------------

ping -w 1 -c 1 www.baidu.com>/dev/null

if [ $? -eq 0 ];then
      echo " Internet is up "

else
      echo " Internet is down"

fi

echo "######################################"


read -p "Useradd_Ordinary_Users : " Useradd_Name

read -p "User_Passwd : " User_PassWD

echo "$User_PassWD"| passwd --stdin $Useradd_Name


sed -i "99i\ $Useradd_Name     ALL=(ALL)       ALL" /etc/sudoers

sed -i ‘/NOPASSWD/s/^#//‘ /etc/sudoers

gpasswd -a `echo $Useradd_Name` wheel


userdel adm 

userdel lp

userdel sync

userdel shutdown

userdel halt

userdel uucp

userdel operator

userdel games

userdel gopher

userdel ftp

groupdel adm

groupdel lp

groupdel dip

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak

echo "port 3389">>/etc/ssh/sshd_config

echo "PermitRootLogin no">>/etc/ssh/sshd_config

echo "PermitEmptyPasswords no">>/etc/ssh/sshd_config

/etc/init.d/sshd reload 

netstat -ntlp | grep 3389

sed -i ‘/Control-Alt-Delete pressed/s/^/#/‘ /etc/init/control-alt-delete.conf

#-------------------------------------------


如何想客隆多个VM主机那么网络MAC会一样

在新系统里,把rules文件里记录的老MAC对应的那个eth0一行删除掉

然后把新MAC对应的eth1的名字改为eth0

然后在ifcfg-eth0文件里把HDADDR的值改为新的MAC地址。

重新启动系统一切就OK了。

#-------------------------------------------

四、挂载移动硬盘并做本地YUM源

    1 挂在FAT32分区并安装NTFS驱动的RPM包

            mkdir /mnt/fat32

            mount -t vfat /dev/sdbX /mnt/vfat

            cd /mnt/vfat

            cp fuse-ntfs-3g-2013.1.13-2.el6.rf.x86_64.rpm /root

            cd /root

            rpm -ivh fuse-ntfs-3g-2013.1.13-2.el6.rf.x86_64.rpm

        

    2 挂载NTFS分区到/mnt/ntfs

            fdisk -l

            mkdir /mnt/ntfs

            mount -t ntfs-3g /dev/sdbX /mnt/ntfs  挂在NTFS盘

    3 拷贝CentOS-6.5-x86_64-bin-DVD1 到 /iso 下

            mkdir /iso

            cp /mnt/ntfs/CentOS-6.5-x86_64-bin-DVD1.iso  /iso/

    4 挂载/iso镜像到 /mnt/centos65yum

            mkdir /mnt/centos65yum

            mount -t iso9660 -o loop /iso/CentOS-6.5-x86_64-bin-DVD1.iso /mnt/centos65yum/

            ls /mnt/centos65yum

            df -h

    备份YUM的配置文件

            cd /etc/yum.repos.d

            mv CentOS-Base.repo CentOS-Base.repo.bak

            mv CentOS-Media.repo CentOS-Media.repo.bak

            mv CentOS-Vault.repo CentOS-Vault.repo.repo.bak

            mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.bak

    6 编辑新配置文件

       vi /etc/yum.repos.d/CentOS-Media.repo

    

[centos6.5-DVD]

name=CentOS6.5_DVD

baseurl=file:///mnt/centos65yum

enabled=1

gpgcheck=0

gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-6


    5 本地YUM源配置完毕

    yum clean all 清除缓存

    yum makecache 生成包信息


    6 退出目录卸载

        cd ~

        umount /mnt/vfat

        umount /mnt/ntfs

    7 开机自动挂载

        vi /etc/fstab

    /iso/CentOS-6.50-x86_64-dvd1.iso /mnt/centos65yum type udf (rw,loop=/dev/loop0)

      


      





本文出自 “孤独没有颜色” 博客,请务必保留此出处http://tenderness.blog.51cto.com/8855468/1942975

centoa7.1 minimal 新机配置步骤及其脚本