[root@centos ~]# vim /usr/lib/systemd/system/nginx.service[Unit]Description=ngixn server
After=network.target
[Service]Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
[Install]WantedBy=multi-user.target
重新加载
[root@centos ~]# systemctl daemon-reload
测试
[root@centos ~]# systemctl start nginx[root@centos ~]# systemctl status nginx
● nginx.service - ngixn server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2024-07-02 00:21:08 CST; 6s ago
Process: 4209ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 4210(nginx)
CGroup: /system.slice/nginx.service
├─4210 nginx: master process /usr/local/nginx/sbin/nginx
└─4211 nginx: worker process
7月 02 00:21:08 centos systemd[1]: Starting ngixn server...
7月 02 00:21:08 centos systemd[1]: Started ngixn server.