#!/bin/bash
yum -y install wget
#更换阿里源 下载epel源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
#清理缓存
yum clean all && yum makecache
#关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -ri "s/(^SELINUX=)(.*)/1disabled/" /etc/selinux/config
#下载常用命令
yum -y install vim net-tools lrzsz lsof bash-completion
#修改动态IP为静态
path=/etc/sysconfig/network-scripts/ifcfg-eth0
network=eth0 #网卡名称
ip=`ifconfig $network |grep inet | head -1|awk '{print $2}'`
netmask=255.255.255.0
gateway=192.168.198.1
if `grep -q "dhcp" $path`;then
sed -ri.bak "/TYPE|BOOT|$network|ONBOOT/ !d" $path
sed -i "s/dhcp/none/" $path
sed -i "$ a IPADDR=$ip" $path
sed -i "$ a NETMASK=$netmask" $path
sed -i "$ a GATEWAY=$gateway" $path
sed -i "$ a DNS1=114.114.114.114" $path
sed -i "$ a DNS2=8.8.8.8" $path
ifdown $network;ifup $network
sleep 3
fi
#自动对时
yum -y install chrony
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
sed -ri "/server/ d" /etc/chrony.conf
echo "server ntp1.aliyun.com iburst" >> /etc/chrony.conf #同步阿里时间
#sed -ri "/#allow/ s/.*/allow 192.168.0.0/24/" /etc/chrony.conf #允许哪个网段同步
#sed -ri "/server/ d" /etc/chrony.conf #同步内网机器时间
#echo "server 192.168.1.1 iburst" >> /etc/chrony.conf
systemctl enable chronyd --now
#yum -y install ntp-4.2.6p5-29.el7.centos.x86_64 #ntp
#ntpdate time1.aliyun.com