无法在CentOS7上启动Zookeeper服务

时间:2020-04-02 20:29:07

标签: apache-kafka centos7 apache-zookeeper

尝试启动Zookeeper服务时,我得到以下信息

● zookeeper.service
   Loaded: loaded (/etc/systemd/system/zookeeper.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2020-04-02 16:19:24 EDT; 5min ago
  Process: 5201 ExecStop=/usr/local/kafka/kafka_2.13-2.4.1/bin/zookeeper-server-stop.sh (code=exited, status=1/FAILURE)
  Process: 4882 ExecStart=/usr/local/kafka/kafka_2.13-2.4.1/bin/zookeeper-server-start.sh /usr/local/kafka/kafka_2.13-2.4.1/config/zookeeper.properties (code=exited, status=127)
 Main PID: 4882 (code=exited, status=127)

Apr 02 16:19:24 centos.localdomain systemd[1]: Started zookeeper.service.
Apr 02 16:19:24 centos.localdomain systemd[1]: zookeeper.service: main process exited, code=exited, status=127/n/a
Apr 02 16:19:24 centos.localdomain systemd[1]: zookeeper.service: control process exited, code=exited status=1
Apr 02 16:19:24 centos.localdomain systemd[1]: Unit zookeeper.service entered failed state.
Apr 02 16:19:24 centos.localdomain systemd[1]: zookeeper.service failed.

zookeeper.service文件的配置如下

[Unit]
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
User=specadmin
ExecStart=/usr/local/kafka/kafka_2.13-2.4.1/bin/zookeeper-server-start.sh  /usr/local/kafka/kafka_2.13-2.4.1/config/zookeeper.properties
ExecStop=/usr/local/kafka/kafka_2.13-2.4.1/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

当尝试使用服务文件中配置的同一用户手动运行zookeeper时,一切正常。

请告知

1 个答案:

答案 0 :(得分:0)

发现问题与systemd使用的环境变量有关。

Systemd使用固定的$ PATH变量,对/ etc / profile / etc / bashrc等所做的更改不会应用于systemd。

Zookeeper运行需要作为搜索路径一部分的Java,但是由于systemd不使用设置了搜索路径的文件,因此zookeeper启动脚本找不到Java。

我通过在zookeeper服务文件中添加Environment = PATH = ...参数并添加所有必需的目录来覆盖搜索路径来解决此问题。