1. 进入/etc/systemd/system目录
cd /etc/systemd/system
2. 创建nginx.service文件
vim nginx.service
3. 配置nginx.service内容
* ExecStart,ExecStop,ExecReload以服务器实际存放位置为准
[Unit] Description=The NGINX HTTP and reverse proxy server After=network.target [Service] Type=forking ExecStart=/home/data/nginx/sbin/nginx ExecReload=/home/data/nginx/sbin/nginx -s reload ExecStop=/home/data/nginx/sbin/nginx -s stop PrivateTmp=true [Install] WantedBy=multi-user.target
4. 配置开机启动
# 设置开机启动 systemctl enable nginx # 取消开机自启动 systemctl disable nginx # 查看服务当前状态 systemctl status nginx # 启动nginx服务 systemctl start nginx # 停止nginx服务 systemctl stop nginx # 重启nginx服务 systemctl restart nginx
5. 创建redis.service文件
vim redis.service
6. 配置redis.service文件
* ExecStart,ExecStop以服务器实际存放位置为准
[Unit] Description=Redis persistent key-value store After=network.target [Service] ExecStart=/home/data/redis-7.2.4/src/redis-server /etc/redis/6379.conf ExecStop=/home/data/redis-7.2.4/src/redis-cli shutdown Restart=always [Install] WantedBy=multi-user.target
7. 配置开机启动
# 设置开机启动 systemctl enable redis # 取消开机自启动 systemctl disable redis # 查看服务当前状态 systemctl status redis # 启动redis服务 systemctl start redis # 停止redis服务 systemctl stop redis # 重启redis服务 systemctl restart redis
标签:service,nginx,Redis,redis,Nginx,开机,systemctl,自启,home From: https://www.cnblogs.com/ljhblogs/p/18515347