centos7自定义zookeeper开机启动

centos7启动服务改变了centos6的/etc/init.d的繁琐,sysctemctl直接调用服务的启动命令,总的来说省事很多,但是坑也多,总是缺少东西,报错,下面是配置zookeeper成为开机服务.

[root@soa-prod-zookeeper-010177210093 /etc/systemd/system] 03:56:01 0
# pwd
/etc/systemd/system
[root@soa-prod-zookeeper-010177210093 /etc/systemd/system] 04:00:39 1
# cat zookeeper-2181.service 
[Unit]
Description=Zookeeper-2181
After=network.target

[Service]
Type=forking
User=user_00
Group=users
ExecStart=/usr/local/services/zookeeper-2181/bin/zkServer.sh  start
ExecStop=/usr/local/services/zookeeper-2181/bin/zkServer.sh stop
PIDFile=/data/zookeeper-2181/data/zookeeper_server.pid 
[Install]
WantedBy=multi-user.target

然后启动服务:

[root@soa-prod-zookeeper-010177210093 ~] 03:45:01 1
# systemctl status zookeeper-2183.service
● zookeeper-2183.service - Zookeeper-2183
   Loaded: loaded (/etc/systemd/system/zookeeper-2183.service; enabled; vendor preset: disabled)
   Active: failed (Result: resources) since Tue 2017-08-08 03:45:01 CDT; 5s ago
  Process: 18732 ExecStart=/usr/local/services/zookeeper-2183/bin/zkServer.sh start (code=exited, status=0/SUCCESS)

Aug 08 03:45:00 soa-prod-zookeeper-010177210093.sl systemd[1]: Starting Zookeeper-2183...
Aug 08 03:45:00 soa-prod-zookeeper-010177210093.sl zkServer.sh[18732]: ZooKeeper JMX enabled by default
Aug 08 03:45:00 soa-prod-zookeeper-010177210093.sl zkServer.sh[18732]: Using config: /usr/local/services/zookeeper-2183/bin/../conf/zoo.cfg
Aug 08 03:45:00 soa-prod-zookeeper-010177210093.sl zkServer.sh[18732]: Starting zookeeper ... /usr/local/services/zookeeper-2183/bin/zkServer.sh: line 140: ./zookeeper.out: Permission denied
Aug 08 03:45:01 soa-prod-zookeeper-010177210093.sl systemd[1]: PID 18755 read from file /data/zookeeper-2183/data/zookeeper_server.pid does not exist or is a zombie.
Aug 08 03:45:01 soa-prod-zookeeper-010177210093.sl systemd[1]: Failed to start Zookeeper-2183.
Aug 08 03:45:01 soa-prod-zookeeper-010177210093.sl systemd[1]: Unit zookeeper-2183.service entered failed state.
Aug 08 03:45:01 soa-prod-zookeeper-010177210093.sl systemd[1]: zookeeper-2183.service failed.

发现报错了。
这里因为我指定了用户启动,所以一直起不来,zookeeper.out显示没有权限以及pid文件,因此额吧用户和用户组注释掉,然后通过root启动,然后找到zookeeper.out文件 ,并更改用户主,用户组,然后更改完成后执行:

systemctl daemon-reload
systemctl start Zookeeper-2181

参考链接:https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/System_Administrators_Guide/sect-Managing_Services_with_systemd-Unit_Files.html

你可能感兴趣的:(centos7自定义zookeeper开机启动)