linux恢复出厂设置命令 一键初始化Linux服务器脚本



linux恢复出厂设置命令 一键初始化Linux服务器脚本

文章插图
#!/usr/bin/env bash
#关闭防火墙
close_firewalld(){
echo “closed firewalld/iptables”
if egrep “7.[0-9]” /etc/redhat-release &>/dev/null; then
systemctl stop firewalld
systemctl disable firewalld
elif egrep “6.[0-9]” /etc/redhat-release &>/dev/null; then
service iptables stop
chkconfig iptables off
fi
}
#关闭SElinux
close_SE(){
echo “SElinux —> disabled”
sed -i ‘/SELINUX/{s/permissive/disabled/}’ /etc/selinux/config
}
#安装jdk
install_jdk(){
java=$(cat /etc/profile | grep JAVA_HOME)
if [ -z “$java” ]; then
echo “请将安装文件jdk-8u271-linux-x64.tar.gz 存放在/data/soft目录中”
echo “请输入Java安装目录”
read install_home
tar -zxvf /data/soft/jdk-8u271-linux-x64.tar.gz -C $install_home
cd $install_home
basepath=$(cd `dirname $0`; pwd)
JAVA_HOME1=”$basepath/jdk1.8.0_271″
echo “export JAVA_HOME=$basepath/jdk1.8.0_271” >> /etc/profile
echo “export PATH=$JAVA_HOME1/bin:$PATH” >> /etc/bash_profile
echo “export CLASSPATH=$JAVA_HOME1/lib/dt.jar:$JAVA_HOME1/lib/tools.jar” >> /etc/bash_profile
source /etc/bash_profile
else
echo java has installed >> log.txt
fi
}
#创建用户
create_user(){
echo -e “请输入用户名:”
read UserName
id $UserName >&/dev/null && echo “user exist” && exit 3
echo -e “请输入所创建用户的家目录 。最后一个/不要写 /bigdata/install”
read userHome
groupadd $UserName
useradd -g $UserName -m -d $userHome $UserName
echo “$UserName ALL=(ALL) ALL ” >> /etc/sudoers
echo “$UserName ALL=(ALL) NOPASSWD:ALL” >> /etc/sudoers
}
close_firewalld
close_SE
install_jdk
create_user
【linux恢复出厂设置命令 一键初始化Linux服务器脚本】

    推荐阅读