systemctl --now参数

1、我们安装一个httpd服务来测试一下 --now参数

yum install httpd

2、查看一下当前服务状态  可以看到服务没有启动 而且服务没有自启

[root@master1 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)
[root@master1 ~]#

[root@master1 ~]# systemctl is-enabled httpd
disabled
[root@master1 ~]#

3、用 --now参数启动一下

systemctl enable --now httpd

4、我们在看一下状态  可以看到服务启动了 同时  也开机自启了

[root@master1 conf]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-03-02 17:42:17 CST; 32s ago
     Docs: man:httpd(8)
           man:apachectl(8)
 Main PID: 26736 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
    Tasks: 6
   Memory: 2.8M
   CGroup: /system.slice/httpd.service
           ├─26736 /usr/sbin/httpd -DFOREGROUND
           ├─26737 /usr/sbin/httpd -DFOREGROUND
           ├─26738 /usr/sbin/httpd -DFOREGROUND
           ├─26739 /usr/sbin/httpd -DFOREGROUND
           ├─26740 /usr/sbin/httpd -DFOREGROUND
           └─26741 /usr/sbin/httpd -DFOREGROUND

Mar 02 17:42:17 master1 systemd[1]: Starting The Apache HTTP Server...
Mar 02 17:42:17 master1 systemd[1]: Started The Apache HTTP Server.
Mar 02 17:42:17 master1 httpd[26736]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1...s message
Hint: Some lines were ellipsized, use -l to show in full.
[root@master1 conf]# systemctl is-enabled httpd.service
enabled
[root@master1 conf]#

5、同理如果用 systemctl disable --now httpd.service  去关闭服务 他会关闭服务的同时 去掉开机自启

[root@master1 conf]# systemctl disable --now httpd.service
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
[root@master1 conf]# systemctl is-enabled httpd.service
disabled
[root@master1 conf]# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:httpd(8)
           man:apachectl(8)

 

posted @ 2021-03-02 09:46  s。  阅读(2559)  评论(0编辑  收藏  举报