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