centos7自动配置脚本

#!/bin/bash

currentTime=$(date +"%Y-%m-%d_%H:%M:%S")

echo "blacklist i2c_piix4"  >> /etc/modprobe.d/blacklist.conf
echo "blacklist pcspkr" >> /etc/modprobe.d/blacklist.conf

##network_config
HOST_NAME="centos7"
DOMAIN="local"
IP_ADDR="192.168.127.12"
GATEWAY="192.168.127.254"
DNS1="114.114.114.114"
DNS2="8.8.8.8"
NETMASK="24"

NIC_NAME=$(nmcli dev status | sed -n 2p | awk '{print $1}')
NIC_CONF='/etc/sysconfig/network-scripts/ifcfg-'$NIC_NAME
NIC_UUID=$(cat $NIC_CONF | grep UUID)

echo "$IP_ADDR      $HOST_NAME      $HOST_NAME.$DOMAIN" >> /etc/hosts

mv $NIC_CONF $NIC_CONF'.bak'$currentTime

cat > $NIC_CONF <<EOF
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=$NIC_NAME
$NIC_UUID
DEVICE=$NIC_NAME
ONBOOT=yes
IPADDR=$IP_ADDR
PREFIX=$NETMASK
GATEWAY=$GATEWAY
DNS1=$DNS1
DNS2=$DNS2
EOF

hostnamectl set-hostname $HOST_NAME'.'$DOMAIN

##sys_config
sed -i '/UseDNS yes/s/^/#/' /etc/ssh/sshd_config
sed -i '/#UseDNS yes/a UseDNS no' /etc/ssh/sshd_config
sed -i '/#UseDNS no/a UseDNS no' /etc/ssh/sshd_config

sed -i '/SELINUX=enforcing/s/^/#/' /etc/selinux/config
sed -i '/#SELINUX=enforcing/a SELinux=disabled' /etc/selinux/config

systemctl stop firewalld
systemctl disable firewalld

systemctl stop postfix
systemctl disable postfix
yum -y remove postfix
mariadb_rpm=$(yum list installed | grep mariadb | awk '{print $1}')
yum -y remove $mariadb_rpm

###yum_conf
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup$currentTime

cat > /etc/yum.repos.d/CentOS-Base.repo << EOF
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-\$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os
baseurl=https://mirrors.ustc.edu.cn/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-\$releasever - Updates
# mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates
baseurl=https://mirrors.ustc.edu.cn/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-\$releasever - Extras
# mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras
baseurl=https://mirrors.ustc.edu.cn/centos/\$releasever/extras/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever - Plus
# mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus
baseurl=https://mirrors.ustc.edu.cn/centos/\$releasever/centosplus/\$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF

yum makecache
yum -y update
yum -y groupinstall "Development Tools"
yum -y install vim wget

posted @ 2018-10-01 00:13  javaite  阅读(1320)  评论(0编辑  收藏  举报