您的位置:首页 > 运维架构 > Linux

CentOS java(zookeeper)项目自启动配置及注意事项

2018-01-12 13:48 871 查看
创建新服务脚本/etc/init.d/zookeeper内容如下

#! /bin/bash
# chkconfig: 2345 20 80
# description: zookeeper
#
rc=0
source /etc/profile
case "$1" in
start)
cd /usr/local/zookeeper-3.4.6/
sh /usr/local/zookeeper-3.4.6/bin/zkServer.sh start
;;
stop)
cd /usr/local/zookeeper-3.4.6
sh /usr/local/zookeeper-3.4.6/bin/zkServer.sh stop
;;
status)
ps aux | grep zookeeper
;;
restart|reload|force-reload)
cd "$CWD"
$0 stop
$0 start
rc=$?
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
exit 2
esac

exit $rc

注意source /etc/profile

  由于java项目都是有java虚拟机启动起来的,如果java程序不在系统目录下,则会因为找不到java导致项目无法启动。CentOS的服务程序需要显式加载环境变量,通常都配置在/etc/profile文件内。

当前的/etc/profile中有如下配置

export JAVA_HOME=/usr/local/jdk1.8.0_101
export PATH=$PATH:$JAVA_HOME/bin


添加到系统服务,做到开机自启动
[root@localhost init.d]# chkconfig --add zookeeper

[root@localhost init.d]# chkconfig zookeeper on

[root@localhost init.d]# chkconfig

Note: This output shows SysV services only and does not include native

      systemd services. SysV configuration data might be overridden by native

      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.

      To see services enabled on particular target use

      'systemctl list-dependencies [target]'.

myservice          0:off    1:off    2:on    3:on    4:on    5:on    6:off

netconsole         0:off    1:off    2:off    3:off    4:off    5:off    6:off

network            0:off    1:off    2:on    3:on    4:on    5:on    6:off

zookeeper          0:off    1:off    2:on    3:on    4:on    5:on    6:off

可以看到zookeeper已经成功添加到系统服务。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  系统服务 linux