Apache Zookeeper:无法访问数据目录

laawzig2  于 2023-04-10  发布在  Apache
关注(0)|答案(1)|浏览(264)

操作系统:RHEL 8.2
我正在尝试为zookeeper创建systemctl服务。它无法访问datadir
这是我的zookeeper配置,

dataDir=/opt/zookeeper
maxClientCnxns=20
tickTime=2000
dataDir=/var/zookeeper/
initLimit=20
syncLimit=10
server.0=master:2888:3888
clientPort=2181
admin.serverPort=8082

/opt/zookeeper的权限设置为777

[user1@server1 opt]$ ls -lart
total 0
dr-xr-xr-x. 17 root       root       244 Jul  3 10:56 ..
drwxr-xr-x   3 root       root        27 Jul 10 10:29 rh
drw-r--r--   2 user2 user2   6 Jul 17 08:48 hsluw_data
drw-r--r--   2 user2 user2   6 Jul 17 08:58 hsluw_config
drwxr-xr-x.  6 root       root        71 Jul 17 08:58 .
drwxrwxrwx   3 user2 user2  23 Jul 17 09:40 zookeeper

如果我运行命令,

./bin/zookeeper-server-start.sh config/zookeeper.properties

它给了我一个错误消息:Unable to access datadir

[2020-07-30 10:25:50,767] ERROR Invalid configuration, only one server specified (ignoring) (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
[2020-07-30 10:25:50,767] INFO Starting server (org.apache.zookeeper.server.ZooKeeperServerMain)
[2020-07-30 10:25:50,769] INFO zookeeper.snapshot.trust.empty : false (org.apache.zookeeper.server.persistence.FileTxnSnapLog)
[2020-07-30 10:25:50,769] ERROR Unable to access datadir, exiting abnormally (org.apache.zookeeper.server.ZooKeeperServerMain)
org.apache.zookeeper.server.persistence.FileTxnSnapLog$DatadirException: Cannot write to data directory /var/zookeeper/version-2
    at org.apache.zookeeper.server.persistence.FileTxnSnapLog.<init>(FileTxnSnapLog.java:132)
    at org.apache.zookeeper.server.ZooKeeperServerMain.runFromConfig(ZooKeeperServerMain.java:124)
    at org.apache.zookeeper.server.ZooKeeperServerMain.initializeAndRun(ZooKeeperServerMain.java:106)
    at org.apache.zookeeper.server.ZooKeeperServerMain.main(ZooKeeperServerMain.java:64)
    at org.apache.zookeeper.server.quorum.QuorumPeerMain.initializeAndRun(QuorumPeerMain.java:128)
    at org.apache.zookeeper.server.quorum.QuorumPeerMain.main(QuorumPeerMain.java:82)
Unable to access datadir, exiting abnormally

但是,sudo执行上述命令可以工作,

sudo ./bin/zookeeper-server-start.sh config/zookeeper.properties

现在我已经在/etc/systemd/system/zookeeper.service中创建了一个服务
我在/etc/systemd/system/zookeeper.service中这样编写服务,

[Unit]
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
User=user2
ExecStart=/home/user2/kafka/bin/zookeeper-server-start.sh /home/user2/kafka/config/zookeeper.properties
ExecStop=/home/user2/kafka/bin/zookeeper-server-stop.sh
Restart=on-abnormal
[Install]
WantedBy=multi-user.target

SELinux状态被禁用。

user2@server1$ sestatus
SELinux status:                 disabled

现在如果我做下面的事情

sudo systemctl daemon-reload
sudo systemctl start zookeeper 
sudo systemctl enable zookeeper

我得到了相同的Unable to access the datadir错误,如下所示:

[user2@server1 /]$ systemctl status zookeeper 
\u25cf zookeeper.service
   Loaded: loaded (/etc/systemd/system/zookeeper.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2020-07-30 10:13:19 CEST; 24s ago
 Main PID: 12911 (code=exited, status=3)

Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: org.apache.zookeeper.server.persistence.FileTxnSnapLog$Data>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]:         at org.apache.zookeeper.server.persistence.FileTxnS>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]:         at org.apache.zookeeper.server.ZooKeeperServerMain.>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]:         at org.apache.zookeeper.server.ZooKeeperServerMain.>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]:         at org.apache.zookeeper.server.ZooKeeperServerMain.>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]:         at org.apache.zookeeper.server.quorum.QuorumPeerMai>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]:         at org.apache.zookeeper.server.quorum.QuorumPeerMai>
Jul 30 10:13:19 server1.localdomain zookeeper-server-start.sh[12911]: Unable to access datadir, exiting abnormally
Jul 30 10:13:19 server1.localdomain systemd[1]: zookeeper.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Jul 30 10:13:19 server1.localdomain systemd[1]: zookeeper.service: Failed with result 'exit-code'.

我错过了什么?

bvk5enib

bvk5enib1#

在配置文件中,此行

dataDir=/var/zookeeper/

出现两次。删除该行可解决此问题。

相关问题