Hazelcast服务器作为Linux服务 [英] Hazelcast server as a linux service

查看:116
本文介绍了Hazelcast服务器作为Linux服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在生产环境中将hazelcast服务器作为linux服务运行?

How to run hazelcast server as a linux service in production environments ?

java -server -cp hazelcast.jar com.hazelcast.examples.StartServer

java -server -cp hazelcast.jar com.hazelcast.examples.StartServer

StartServer运行带有输出到std终端的服务器,将其作为linux服务运行并将日志写入文件的最简单方法是什么 &如何为Hazelcast指定最小和最大内存分配.

StartServer runs the server with outputs to std terminal, what's the easiest way to run it as a linux service and write logs to a file & how do I specify min and max memory allocation for Hazelcast.

我必须将其设置为EC2实例中的服务并将其捆绑.当EC2自动扩展启动实例时,hazelcast服务器将启动并加入集群.

I have to set it up as a service in an EC2 instance and bundle it. When EC2 autoscaling starts an instance, hazelcast server will start and join the cluster.

谢谢

推荐答案

要将Hazelcast用作服务,您只需要编写启动和停止Java应用程序的shell/bash脚本即可.然后,为了控制Hazelcast配置,您需要传入系统属性hazelcast.config,并带有包含hazelcast.xml配置的文件的路径.

To use Hazelcast as a service you just need to write a shell/bash script that starts and stops the java application. Then for controlling your Hazelcast configuration you need to pass in the system property hazelcast.config with the path to the file which contains the hazelcast.xml configuration.

此外,如果要进行自定义日志记录,则可以包括JAR文件(例如,对于log4j2),并使用日志记录配置设置系统属性log4j.configurationFile以及XML/JSON文件的路径.不要忘记在hazelcast配置中将属性hazelcast.logging.type设置为相应的类型.

Moreover, if you want to have custom logging you can include the JAR files (for log4j2, for example) and set the system property log4j.configurationFile and the path to the XML/JSON file with the logging configuration. Do not forget to set the property hazelcast.logging.type to the according type in your hazelcast config.

作为示例代码,您在这里有一个非常简单的bash脚本,可以执行所需的操作.我尚未对其进行测试,但这只是可以指导您的事情:

As an example code, here you have a really simple bash script for doing what you want. I have not tested it and it is just something to guide you:

#!/bin/bash

function start {
   cd /opt/hazelcast
   rm -f /opt/hazelcast/hazelcast.pid
   javaCmd = "/my/java/home/bin/java -server -cp hazelcast.jar:apache-log4j-2.0-beta9.jar -Dhazelcast.config=/opt/hazelcast/hazelcast.xml -Dlog4j.configurationFile=/opt/hazelcast/log4j2.xml com.hazelcast.examples.StartServer"
   cmd="nohup $javaCmd >> /opt/hazelcast/service.log 2>&1 & echo \$! >/opt/hazelcast/hazelcast.pid"
   su -c "$cmd"
   return 0; }


function stop {
   pid="$(</opt/hazelcast/hazelcast.pid)"
   kill -s KILL $pid || return 1
   return 0; }


function main {
   RETVAL=0
   case "$1" in
      start)                                               
         start
         ;;
      stop)                                                
         stop
         ;;
      *)
         echo "Usage: $0 {start|stop}"
         exit 1
         ;;
      esac
   exit $RETVAL
}


main $1

这篇关于Hazelcast服务器作为Linux服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆