在一台阿里云服务器上需要搭建nacos集群,服务器是centos7.
先是使用安装上传命令
yum install lrzsz
rz:从本地上传文件至服务器
sz filename:从服务器下载文件至本地
然后各种准备文件和数据库,最后执行nacos的sh startup.sh命令,报错信息:
which: no JAVAc in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
readlink: missing operand
Try 'readlink --help' for more information.
dirname: missing operand
Try 'dirname --help' for more information.
ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! !!
查找原因:。
好久没有安装过jdk了,平时在windows上安装,配置一下环境变量,基本都是几分钟搞定,信心满满的开始了踩坑之路
使用了最简单的安装方式:
1.先查询一下库里有的jdk版本
yum search java|grep jdk
2.选择安装1.8 最新版本
yum install java-1.8.0-openjdk
3.设置环境变量
[root@localhost ~]# vi /etc/profile
添加
#set java environment
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
让修改生效:
source /etc/profile
4.验证
java -version
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)
本以为完事大吉了,继续执行nacos的sh startup.sh命令,仍然同样的报错。
报错信息:
which: no javac in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
readlink: missing operand
Try 'readlink --help' for more information.
dirname: missing operand
Try 'dirname --help' for more information.
ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! !!
使用命令查看javac
which javac
报错:
which: no javac in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
查找jdk安装路径:
ls -lrt /usr/bin/java
lrwxrwxrwx 1 root root 22 Apr 12 13:44 /usr/bin/java -> /etc/alternatives/java
ls -lrt /etc/alternatives/java
lrwxrwxrwx 1 root root 73 Apr 12 13:44 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre/bin/java
cd /usr/lib/jvm
ll
5. 多次尝试修改环境变量的位置,然后source /etc/profile
然后其中一台服务器被玩坏了,修改/etc/profile配置错误command is not found
/usr/libexec/grepconf.sh: line 5: grep: command not found
很多命令如ls,yum命令都不能使用了,想着重置系统,发现太麻烦了,从网上发现一个可行的解决方式:
1.找到另一条好好的服务器,
echo $PATH
得到完整的路径
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre/bin:/root/bin
2.在玩坏的服务器上执行
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-1.el7_9.x86_64/jre/bin:/root/bin
然后让变量生效:
source /etc/profile
命令都生效了,可以正常使用了。
6.经过搜索网上,最终发现openjdk安装需要两部分:
安装jre:
sudo yum install java-1.8.0-openjdk -y
安装jdk:
sudo yum install java-1.8.0-openjdk-devel -y
此时,使用which javac命令来看
which javac
/usr/bin/javac
openjdk和oracle的jdk是不一样的,安装时请一定注意。