#修改机器名
hostnamectl set-hostname $1
#修改静态网络地址
addr=$2 #192.168.231.130
sed -i 's/dhcp/static/' /etc/sysconfig/network-scripts/ifcfg-ens33
echo "IPADDR=$addr" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "NETMASK=255.255.255.0" >> /etc/sysconfig/network-scripts/ifcfg-ens33
gw=`awk 'BEGIN{split("'"$addr"'",ips,".");print ips[1] "." ips[2] "." ips[3] ".2"}'`
echo "GATEWAY=$gw" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "DNS1=114.114.114.114" >> /etc/sysconfig/network-scripts/ifcfg-ens33
echo "DNS2=8.8.8.8" >> /etc/sysconfig/network-scripts/ifcfg-ens33
systemctl restart network#绑定地址和名字
echo "$addr $1" >> /etc/hosts#关闭防火墙
systemctl stop firewalldsystemctl disable firewalld
#安装vim 和 wget
yum install -y vim wget#更换yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache#创建软件安装文件夹
mkdir -p /opt/soft#配置jdk
mkdir -p /opt/soft/jdk180
jdkPath=`find /opt/ -name 'jdk*.tar.gz'`
tar -zxf $jdkPath -C /opt/soft/jdk180 --strip-components 1
if [ ! $JAVA_HOME ]
then
echo 'export JAVA_HOME=/opt/soft/jdk180' >> /etc/profile
echo 'export CLASSPATH=.:%JAVA_HOME/lib/dt.jar:%JAVA_HOME/lib/tools.jar' >> /etc/profile
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> /etc/profile
source /etc/profile
fi
linux编写shell脚本直接安装JDK
最新推荐文章于 2023-10-27 11:47:22 发布