歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 每天一個Linux命令(53)service命令

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

日期:2017/3/3 11:48:47   编辑:Linux技術

[b] service命令用於對系統服務進行管理。[/b] [b] (1)[/b][b]用法:[/b]

[b] 用法: service [服務] [操作][/b] [b] (2)功能:[/b]

[b] 功能: service命令用於啟動、停止、重新啟動和關閉系統服務,還可以顯示所有系統服務的當前狀態。[/b][b] (3)選項參數:[/b]

1) status       

2) start 3) stop

4) reload 5) disable

6) force-reload[b] 這幾個參數顧名思義,不再解釋![/b]

[b] (4)實例:[/b] 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

Copyright © Linux教程網 All Rights Reserved