systemd管理
systemd是目前Linux系统上主要的系统守护进程管理工具,配置文件要以.service
结尾且放到 /usr/lib/systemd/system/
目录下面
1、systemd管理 elasticsearch
Type=forking
User=robot
Group=robot
ExecStart=/home/robot/elasticsearch-7.17.6/bin/elasticsearch -d
ExecStop=/bin/kill -s QUIT $MAINPID
LimitNOFILE=65536
LimitNPROC=65536
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start elasticsearch.service
2、systemd管理 zookeeper
[Unit]
Description=zookeeper Service
[Service]
Type=forking
WorkingDirectory=/home/zookeeper/apache-zookeeper-3.6.1-bin
User=zookeeper
Group=zookeeper
ExecStart=/home/zookeeper/apache-zookeeper-3.6.1-bin/bin/zkServer.sh start
ExecStop=/home/zookeeper/apache-zookeeper-3.6.1-bin/bin/zkServer.sh stop
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start zookeeper.service
3、systemd管理 jar包
[Unit]
Description= jar Package manager
[Service]
Type=forking
WorkingDirectory=/home/robot/robotv6.6.2/rbc_web
User=robot
Group=robot
ExecStart=/home/robot/robotv6.6.2/rbc_web/run.sh start
ExecStop=/home/robot/robotv6.6.2/rbc_web/run.sh stop
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start robot_web.service
常用配置:
Description:
服务备注信息After:
服务依赖,指明启动顺序Type:
上文中使用的是:forking 以fork方式从父进程创建子进程,创建后父进程会立即退出,子进程将成为主进程PIDFile:
PID文件路径ExecStartPre:
启动前要做的事情ExecStart:
启动服务ExecReload:
重载服务ExecStop:
停止服务WorkingDirectory:
工作目录User:
启动用户Group
启动组PrivateTmp:
True表示给服务分配独立的临时空间WantedBy:
服务安装的用户模式,上文中使用的是:multi-user.target ,就是指想要使用这个服务的目录是多用户。