Linux sets Nginx and Redis to start automatically at boot

What is used here is to register Nginx and Redis as services and set them to start automatically at boot

redis.service content

[Unit]
Description=redis-server
After=network.target
 
[Service]
Type=forking
#ExceStart 为启动命令  请确认 启动地址和路径等等
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
 

nginx.service content

[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
#请确认相关命令是否可执行
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target
 

set as service

 
#创建相关服务文件
vim /etc/systemd/system/redis.service
vim /etc/systemd/system/nginx.service
#编辑服务文件  见上面
 
#重载系统服务
systemctl daemon-reload
#测试 服务是否生效   
systemctl  start  xxx.service  
ps aux|grep xxx
 
# 设置服务为开机启动服务  同时也需要确认下 mysql服务是否在开机服务里面
systemctl enable redis.service
systemctl enable nginx.service
 
#开机服务查询
systemctl list-units --type=service

Guess you like

Origin blog.csdn.net/qq_41596778/article/details/130194566