如何在生产环境中将hazelcast服务器作为linux服务运行?
java -server -cp hazelcast.jar com.hazelcast.examples.StartServer
StartServer运行带有std终端输出的服务器,将它作为linux服务运行并将日志写入文件的最简单方法是什么?如何为Hazelcast指定最小和最大内存分配.
我必须将其设置为EC2实例中的服务并捆绑它.当EC2自动扩展启动实例时,hazelcast服务器将启动并加入群集.
谢谢
要将Hazelcast用作服务,您只需编写一个启动和停止Java应用程序的shell/bash脚本.然后,为了控制Hazelcast配置,您需要hazelcast.config使用包含hazelcast.xml配置的文件路径传入系统属性.
此外,如果要进行自定义日志记录,可以包含JAR文件(例如,对于log4j2),并log4j.configurationFile使用日志记录配置设置系统属性和XML/JSON文件的路径.不要忘记hazelcast.logging.type在hazelcast配置中将属性设置为相应的类型.
作为一个示例代码,这里有一个非常简单的bash脚本,用于执行您想要的操作.我没有测试它,它只是指导你:
#!/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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8215 次 |
| 最近记录: |