There are several ways to run a program on Linux startup.
The /etc/rc.d/init.d way in centsos 6, add commands to rc.local file, or systemctl in centos 7.
I prefer use systemctl to manage your services if you are using centos 7+ version:
Add a service config file
cd /usr/lib/systemd/system/
vi zookeeper.service
The file content like this:
[Unit]
Description=zookeeper - apache zookeeper
Requires=network.target
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/opt/apache-zookeeper-3.6.2-bin/bin/zkServer.sh start
ExecReload=/opt/apache-zookeeper-3.6.2-bin/bin/zkServer.sh restart
ExecStop=/opt/apache-zookeeper-3.6.2-bin/bin/zkServer.sh stop
Restart=always
RestartSec=5min
TimeoutSec=360
[Install]
WantedBy=multi-user.target
Enable run on boot
systemctl enable zookeeper.service
systemctl start zookeeper.service
More parameters can be found here: