shell一键安装jdk

在root用户下

#!/bin/bash
tar -zxvf jdk*
cd jdk1*
home=`pwd`
echo $home
echo "export JAVA_HOME=${home}" >> /etc/profile
echo "export CLASSPATH=\$JAVA_HOME/lib" >> /etc/profile
echo "export PATH=\$PATH:\$JAVA_HOME/bin" >> /etc/profile
source /etc/profile

在普通用户下

1.登录root创建普通用户并修改参数

#!/bin/bash
user=haha
groupadd ${user}
useradd -g ${user} ${user} -m
passwd ${user}
chmod +w /etc/sudoers
echo "${user} ALL=(ALL:ALL)  NOPASSWD:ALL" >> /etc/sudoers
chmod -w /etc/sudoers
echo "*   soft noproc   65535" >> /etc/security/limits.conf
echo "*   hard noproc   65535" >> /etc/security/limits.conf
echo "*   soft nofile   1000000" >> /etc/security/limits.conf
echo "*   hard nofile   1000000" >> /etc/security/limits.conf
echo "sysctl -w fs.file-max =65536" >> /etc/security/limits.conf
echo "ulimit -u 10000" >> /etc/profile
source  /etc/profile

2.登录创建的用户

su 用户名

3.安装jdk脚本文件

#!/bin/bash
tar -zxvf jdk*
cd jdk1*
home=`pwd`
echo $home
sudo sh -c "echo 'export JAVA_HOME=${home}' >> /etc/profile"
sudo sh -c "echo 'export CLASSPATH=\$JAVA_HOME/lib' >> /etc/profile"
sudo sh -c "echo 'export PATH=\$PATH:\$JAVA_HOME/bin' >> /etc/profile"
 
source /etc/profile



©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页