Now more and more environment using CentOS 7 as a base configuration, especially if you want to test or ecological Hadoop deployment environment need to start many components (zookeeper, kafka, redis, etc.), the following is the operating system layer to achieve start-up, so when to check on operation and maintenance staff no longer need each hardware device is powered down or restart planned, freed from boring work frequently.
Centos7 service systemctl script generally stored in: / usr / lib / systemd, there are user directory and system of points:
/ Usr / lib / systemd / system # service system, the boot process does not require user login will be able to run (the equivalent of boot from Kai)
/ Usr / lib / systemd / user # user services, in order to run the program need to log in
Step one: Create a new service file in / usr / lib / systemd under the / system directory (for example zookeeper.service)
cd /usr/lib/systemd/system
touch zookeeper.service
Use vi editing tools zookeeper.service file and add the following:
[Unit]
Description=Zookeeper Service
After=network.target
[Service]
Type=forking
User = icop # This is the user that you expect to start the service user name, but requires that the user has execute permissions for /home/icop/app/zookeeper/bin/zkServer.sh
Group = whdata # is that you expect the user to start the service user group name
SyslogIdentifier = icop # indicate the name of the boot process
Environment = ZOO_LOG_DIR = / home / icop / app / zookeeper / logs # ZOO_LOG_DIR this parameter must give, or have problems starting zookeeper
Environment=PATH=/usr/local/jdk1.8.0_181/bin:/usr/local/jdk1.8.0_181/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
ExecStart=/home/icop/app/zookeeper/bin/zkServer.sh start
ExecStop=/home/icop/app/zookeeper/bin/zkServer.sh stop
ExecReload=/home/icop/app/zookeeper/bin/zkServer.sh restart
[Install]
WantedBy=multi-user.target
Step Two: Load
root user "systemctl daemon-reload" command zookeeper.service join Unit.
Step 3: Set boot
root user "systemctl enable zookeeper.service" command to set the service to boot.
Step Four: Verify
root user "systemctl list-unit-files" command lists all Unit whether service boot .