数据税和系统

Datastax & systemd

我已经为 DataStax Enterprise 4.8.5 配置了一个系统单元:

### /etc/systemd/system/dse1.service

[Unit]
Description=DataStax Enterprise

[Service]
User=cassandra
ExecStart=/opt/dse/dse1/bin/dse cassandra -k
ExecStop=/opt/dse/dse1/bin/dse cassandra-stop

当我执行 sudo systemctl start dse1 时,如果我之后立即执行 status,我得到:

● dse1.service - DataStax Enterprise 1
   Loaded: loaded (/etc/systemd/system/dse1.service; static; vendor preset: disabled)
   Active: active (running) since Wed 2016-03-23 13:47:57 EDT; 1s ago
 Main PID: 31699 (cassandra)
   CGroup: /system.slice/dse1.service
           ├─31699 /bin/sh /opt/dse/dse1/resources/cassandra/bin/cassandra -k -Djava.library.path=:/opt/dse/dse1/resources/hadoop/native...
           ├─31894 /bin/java -cp :/opt/dse/dse1/lib/dse-core-4.8.5.jar:/opt/dse/dse1/lib/dse-hadoop-4.8.5.jar:/opt/dse/dse1/lib/dse-hive...
           └─31895 grep -q Error: Exception thrown by the agent : java.lang.NullPointerException

如果我等几秒钟再试一次,我会得到:

● dse1.service - DataStax Enterprise 1
   Loaded: loaded (/etc/systemd/system/dse1.service; static; vendor preset: disabled)
   Active: inactive (dead)

Mar 23 13:34:28 pspldsea01p.fleet.ad systemd[1]: Started DataStax Enterprise 1.
Mar 23 13:34:28 pspldsea01p.fleet.ad systemd[1]: Starting DataStax Enterprise 1...
Mar 23 13:38:33 pspldsea01p.fleet.ad systemd[1]: Started DataStax Enterprise 1.
Mar 23 13:38:33 pspldsea01p.fleet.ad systemd[1]: Starting DataStax Enterprise 1...
Mar 23 13:47:41 pspldsea01p.fleet.ad systemd[1]: Started DataStax Enterprise 1.
Mar 23 13:47:41 pspldsea01p.fleet.ad systemd[1]: Starting DataStax Enterprise 1...
Mar 23 13:47:44 pspldsea01p.fleet.ad dse[31267]: nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused'.
Mar 23 13:47:57 pspldsea01p.fleet.ad systemd[1]: Started DataStax Enterprise 1.
Mar 23 13:47:57 pspldsea01p.fleet.ad systemd[1]: Starting DataStax Enterprise 1...
Mar 23 13:48:01 pspldsea01p.fleet.ad dse[32004]: nodetool: Failed to connect to '127.0.0.1:7199' - ConnectException: 'Connection refused'.
Hint: Some lines were ellipsized, use -l to show in full.

如果我只是作为 cassandra 用户执行 /opt/dse/dse1/bin/dse cassandra -k,它工作正常。

我似乎无法在正常日志记录位置或使用 sudo journalctl -u dse1

找到任何其他日志记录

有什么想法吗?谢谢!

不幸的是,DataStax Enterprise 没有附带能够使用 systemctl 的 systemd 服务文件。但是,它确实带有一个初始化脚本。完整文档可在 docs

基本上你有两个选择。第一个是直接使用init.d,通过启动服务:

sudo service dse start

但是,我现在太习惯 systemctl 了,无法回到那个状态。所以这是我的系统服务文件

[Unit]
Description=DataStax Enterprise
After=network.target

[Service]
PIDFile=/var/run/dse/dse.pid
ExecStart=/etc/init.d/dse start
ExecStop=/etc/init.d/dse stop
SuccessExitStatus=143
TimeoutSec=300

[Install]
WantedBy=multi-user.target

初始化脚本有很多配置选项。为了简单起见,直接在脚本中使用它们可能是明智的。例如,您在 systemd 服务文件中指定用户。这给我带来了问题,直到我注意到脚本中已经指定了用户。无需重复选项。

SucessExitStatus=143 选项是 Java 应用程序的常见配置。

如果您没有使用包管理器安装 DSE,您可能需要调整脚本的位置

添加这个以防万一 post 晚了,但仍然有用。 添加附加参数 RemainAfterExit

/etc/systemd/system/dse1.服务

[Unit]
Description=DataStax Enterprise

[Service]
User=cassandra
RemainAfterExit=yes
ExecStart=/opt/dse/dse1/bin/dse cassandra -k
ExecStop=/opt/dse/dse1/bin/dse cassandra-stop

[Install]
WantedBy=multi-user.target