每天一個Linux命令(53)service命令


    service命令用於對系統服務進行管理。

 

    (1)用法:

    用法:  service  [服務]  [操作]

 

    (2)功能:

    功能:  service命令用於啟動、停止、重新啟動和關閉系統服務,還可以顯示所有系統服務的當前狀態。

 

    (3)選項參數:

      1) status       

      2) start

      3) stop

      4) reload

      5) disable

      6) force-reload

    這幾個參數顧名思義,不再解釋!

 

    (4)實例:

      1)[sunjimeng@localhost ~]$ service mysql           查看service命令的簡介       

[sunjimeng@localhost ~]$ service mysql
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

      2)[sunjimeng@localhost ~]$ service xinetd status             查看指定服務的狀態信息

[sunjimeng@localhost ~]$ service xinetd status
Redirecting to /bin/systemctl status  xinetd.service
xinetd.service - Xinetd A Powerful Replacement For Inetd
   Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled)
   Active: active (running) since 日 2016-06-19 23:49:21 PDT; 22min ago
  Process: 1395 ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1426 (xinetd)
   CGroup: /system.slice/xinetd.service
           └─1426 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid

      查看網絡連接服務的狀態信息:

[root@localhost sunjimeng]# service network status
Configured devices:
lo eno16777736 配置_1
Currently active devices:
lo eno16777736

    3)[sunjimeng@localhost ~]$ service xinetd stop        停止xinetd服務

[sunjimeng@localhost ~]$ service xinetd stop
Redirecting to /bin/systemctl stop  xinetd.service
Failed to issue method call: Access denied                //沒有root權限,所以拒絕訪問
[sunjimeng@localhost ~]$ su root
密碼:                                                     //登入root
[root@localhost sunjimeng]# service xinetd stop
Redirecting to /bin/systemctl stop  xinetd.service        
[root@localhost sunjimeng]# service xinetd status
Redirecting to /bin/systemctl status  xinetd.service
xinetd.service - Xinetd A Powerful Replacement For Inetd
   Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled)
   Active: inactive (dead) since 一 2016-06-20 00:15:27 PDT; 15s ago
  Process: 1395 ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1426 (code=exited, status=0/SUCCESS)

6月 19 23:49:21 localhost.localdomain xinetd[1426]: removing echo
6月 19 23:49:21 localhost.localdomain xinetd[1426]: removing tcpmux
6月 19 23:49:21 localhost.localdomain xinetd[1426]: removing time
6月 19 23:49:21 localhost.localdomain xinetd[1426]: removing time
6月 19 23:49:21 localhost.localdomain xinetd[1426]: xinetd Version 2.3.15 st...
6月 19 23:49:21 localhost.localdomain xinetd[1426]: Started working: 0 avail...
6月 20 00:07:22 localhost.localdomain systemd[1]: Started Xinetd A Powerful ...
6月 20 00:08:07 localhost.localdomain systemd[1]: Started Xinetd A Powerful ...
6月 20 00:15:27 localhost.localdomain systemd[1]: Stopping Xinetd A Powerful...
6月 20 00:15:27 localhost.localdomain systemd[1]: Stopped Xinetd A Powerful ...
Hint: Some lines were ellipsized, use -l to show in full.

      4)[root@localhost sunjimeng]# service xinetd restart      重啟守護進程

[root@localhost sunjimeng]# service xinetd restart
Redirecting to /bin/systemctl restart  xinetd.service

      5)[root@localhost sunjimeng]# service xinetd reload      重新加載守護進程xinetd的配置文件

[root@localhost sunjimeng]# service xinetd reload
Redirecting to /bin/systemctl reload  xinetd.service

 

    (5)其他:

    1.service程序與一般的程序的區別:

      service(也稱為daemon)表示后台運行的程序,一般隨系統的啟動自動地啟動且在用戶logoff后仍然能夠繼續運行。該daemon進程一般在啟動后需要與父進程斷開關系,並使進程沒有控制終端(tty)。

      因為daemon程序在后台執行,不需要於終端交互,通常就關閉STDIN、STDOUT和STDER。daemon無法輸出信息,可以使用syslog或自己的日志系統進行日志處理。

      可以使用/etc/rc.d/init.d/functions腳本中的daemon函數來將一般的程序啟動為daemon:

[root@localhost sunjimeng]# ls /etc/rc.d/init.d/functions
/etc/rc.d/init.d/functions

     2.xinetd:

  xinetd本身是一個service,他的作用是監聽所有的端口,根據配置對不同的端口啟動不同的應用。 對於有些需要在后台運行的程序,可以選擇設置為service在后台一直運行,也可以選擇使用xinetd來配置此程序根據需要激活。

  對於需要頻繁訪問的服務,需要在/etc/rc.d/init.d下配置為service;對於不是頻繁訪問的服務,可以使用xinetd來激活,從而節約服務器的資源;總之service與xinetd,選一即可。

    3.service命令和chkconfig命令與服務程序的關系:

       service的管理工具是:        /sbin/service

    service的自動啟動控制工具是:   /sbin/chkconfig 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM