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. cookie做订单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Android-ViewPagerIndicator框架使用——UnderlinePageIndicator

    前言:UnderlinePageIndicator这个指示,是一个很小巧的东西,简单,没有那么多复杂的效果. 一:布局定义simple_underlines: <LinearLayout xml ...

  3. awk合并两个文件并显示

    问题: 答案:

  4. urllib -- ProxyHandler处理器(代理设置)

    import urllib.requestimport randomimport ssl proxy_list = [ {"https" : "196.61.27.58: ...

  5. Kettle 7启动 Spoon.bat 时报错“A Java Exception has occurred.”的解决方法

    最近在研究Kettle 时出现启动时报错“A Java Exception has occurred.”的问题.刚开始没搞明白是什么原因,后来发现是jdk版本的问题.出现这个错误原因是 Kettle ...

  6. 使用jQuery lazyload 实现图片延迟加载

    下载地址 使用说明 0. 准备工作 下载jQuery和lazyload 插件(地址如上) 1. HTML 引入jQuery库和lazyload插件 <div id="imagesCon ...

  7. jQuery倒计时实例

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Apple 企业开发者账号申请记录

    1.账号分类 Apple开发者账号分三种,个人,公司,还有企业.个人和公司都称为标准账号. 还有一种是教育机构的账号. 记录:申请日期2013年4月26,看申请周期多长. 个人和公司的就不说了,现在只 ...

  9. 《从零开始学Swift》学习笔记(Day 8)——小小常量、变量大作用

    原创文章,欢迎转载.转载请注明:关东升的博客   计算机语言学习中都有常量和变量,他们几乎是我编写代码的灵魂了,离开他们我真的是“活不了” 常量是标识符的前面加上关键字let.常量其值在使用过程中不会 ...

  10. 打日志--以python为例

    日志报错要去修,要不然是隐患,总有一天会爆炸 增加日志是排错的好方法,不要不舍得加日志,比如怕代码变难看,怕日志输出太多. python logging exc_info sys.exc_info() ...