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 日 -- :: PDT; 22min ago
Process: ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=/SUCCESS)
Main PID: (xinetd)
CGroup: /system.slice/xinetd.service
└─ /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 一 -- :: PDT; 15s ago
Process: ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=/SUCCESS)
Main PID: (code=exited, status=/SUCCESS) 6月 :: localhost.localdomain xinetd[]: removing echo
6月 :: localhost.localdomain xinetd[]: removing tcpmux
6月 :: localhost.localdomain xinetd[]: removing time
6月 :: localhost.localdomain xinetd[]: removing time
6月 :: localhost.localdomain xinetd[]: xinetd Version 2.3. st...
6月 :: localhost.localdomain xinetd[]: Started working: avail...
6月 :: localhost.localdomain systemd[]: Started Xinetd A Powerful ...
6月 :: localhost.localdomain systemd[]: Started Xinetd A Powerful ...
6月 :: localhost.localdomain systemd[]: Stopping Xinetd A Powerful...
6月 :: localhost.localdomain systemd[]: 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

每天一个Linux命令(53)service命令的更多相关文章

  1. 每天一个linux命令(53)--ps命令

    要毁掉一天,从早上开始. Linux中的ps命令是 process status 的缩写.ps 命令用来列出系统中当前运行的那些进程.ps 命令列出的是当前那些进程的快照,就是执行ps 命令的那个时刻 ...

  2. linux常用命令:service 命令

    service命令用于对系统服务进行管理,比如启动(start).停止(stop).重启(restart).查看状态(status)等.相关的命令还包括chkconfig.ntsysv等,chkcon ...

  3. Linux下的service命令和chkconfig命令的原理

    CentOS下的service命令和chkconfig命令的原理 1.service命令的原理 service命令用来对服务进行启动和关闭,比如service mysqld start可以启动mysq ...

  4. 在Linux中利用Service命令添加系统服务及开机自启动

    有时候我们需要Linux系统在开机的时候自动加载某些脚本或系统服务 主要用三种方式进行这一操作: ln -s                       在/etc/rc.d/rc*.d目录中建立/e ...

  5. 【Linux】缺少service命令的解决办法

    执行保存防火墙策略报错:提示没有找到service的文件遇到这个问题后,执行下面的命令,需要安装一个包initscripts rpm -qa | grep initscripts yum list | ...

  6. centos7也支持service命令启动服务吗,对于centos7 中的systemctl和旧的service命令的区别和联系

    一.centos7也支持service命令启动服务吗 CentOS 7.0中一个最主要的改变,就是切换到了systemd.它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服 ...

  7. linux下service+命令和直接去执行命令的区别,怎么自己建立一个service启动

    启动一些程序服务的时候,有时候直接去程序的bin目录下去执行命令,有时候利用service启动. 比如启动mysql服务时,大部分喜欢执行service mysqld start.当然也可以去mysq ...

  8. 每天一个linux命令(53):route命令

    Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或 ...

  9. 【转】每天一个linux命令(53):route命令

    原文网址:http://www.cnblogs.com/peida/archive/2013/03/05/2943698.html Linux系统的route命令用于显示和操作IP路由表(show / ...

随机推荐

  1. Linux下批量删除空文件

    Linux下批量删除空文件(大小等于0的文件)的方法 find . -name "*" -type f -size 0c | xargs -n 1 rm -f 用这个还能够删除指定 ...

  2. 结构体成员管理AVClass AVOption之1AVClass

    AVOption用于描述结构体中的成员变量.它最主要的作用可以概括为两个字:“赋值”. 一个AVOption结构体包含了变量名称,简短的帮助,取值等信息. 所有和AVOption有关的数据都存储在AV ...

  3. android模拟器怎么直接安装apk

    方法一:进入adb的tools目录,下面有adb.exe如图, 在cmd下进入tools目录,然后输入adb install apk路径,就行了 方法二:直接写一个批处理文件 运行就行了.

  4. 继续聊WPF——动态数据模板

    我为啥称之为“动态数据模板”?先看看下面的截图,今天,我们就是要实现这种功能. 大概是这样的,我们定义的DataTemplate是通过触发器动态应用到 ComboBoxItem 上. 这个下拉列表控件 ...

  5. WPF-Binding对数据的检验

    设置Binding的ValidationRules属性对Binding进行检验 <StackPanel> <TextBox x:Name="txtAge" Fon ...

  6. 红外图像处理之直方图均衡的matlab源码与效果验证

    红外图像是热辐射成像,由于场景中的目标与背景的温差相对较小,红外图像的动态范围大.对比度 低, 信噪比也较可见光图像的低.为了能够从红外图像中正确地识别出目标,必须对红外图像进行增强处理.一般红外探测 ...

  7. day1笔记 初识python,paython基础

    一.计算机,操作系统 软件发送指令给操作系统,操作系统再把指令发送给  内存,cpu,硬盘等 二.Python的历史. Python2: 1.臃肿,源码的重复量很多.2.语法不清晰,掺杂着c,++,P ...

  8. 单线程爬虫VS多线程爬虫的效率对比

    单线程爬虫: import re import requests import time url_EB = 'http://www.amazon.com/gp/search/other/ref=sr_ ...

  9. ios代码实现时间设置NSDate

    本文转载至 http://www.baidu.com/link?url=dcQWiL1FD_She6P4RM2IvEeJas0_gtG3LkRNTV5H87X0AyKCHvwYjBz2hdcB2JVp ...

  10. shell脚本中出现^M

    在Windows中编辑的shell脚本,传到linux系统中,在末尾发现出现了很多^M字符 1.问题分析 在windows下使用notepad++写的脚本上传到Linux下,在使用vim编辑的时候我们 ...