使用service zookeeper start 提示找不到java

zookeeper的启动脚本放在:/etc/init.d/zookeeper

使用service zookeeper start 命令,输出提示找不到java命令。

通过在终端打印 env 输出的内容里面,设置了Java的环境变量,查看service 命令,找到了答案,见下图:

相关内容就是下面两段:

service runs a System V init script in as predictable environment as possible, removing most environment variables and with current working directory set to /.

ENVIRONMENT
       LANG, TERM
              The only environment variables passed to the init scripts.

由上可知,使用service命令时,仅有 LANG, TERM 两个环境变量能使用。

暂时的解决办法,直接使用路径来启动:

/etc/init.d/zookeeper start

另一种情况,如果使用的是:systemctl start zookeeper,还是会报找不到java的错误。

这和上面的原因类似,systemctl命令是用来管理systemd进程的。而systemd默认读取的默认路径,在systemd.exec中有明确的说明:

Environment Variables Set or Propagated by the Service Manager

The following environment variables are propagated by the service manager or generated internally for each invoked process:

$PATH

Colon-separated list of directories to use when launching executables. systemd uses a fixed value of "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin" in the system manager. When compiled for systems with "unmerged /usr/" (/bin is not a symlink to /usr/bin), ":/sbin:/bin" is appended. In case of the user manager, a different path may be configured by the distribution. It is recommended to not rely on the order of entries, and have only one program with a given name in $PATH.

systemd只会调用/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin 这些目录下的命令,因为这些目录下没有java命令,所以就会报前面提到的那个找不到java命令的错误。

讲到这里,大家应该知道怎么解决该问题吧,最简单的,就是在以上任何一个目录下,创建一个java命令的软连接,比如:

ln java命令所在绝对路径 java

除了以上方法,还可以在自定义的servicename.service文件中,增加环境变量,这里就不再展开叙述了,感兴趣的去搜下添加环境变量的内容即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值