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命令的简介       

  1. [sunjimeng@localhost ~]$ service mysql
  2. 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             查看指定服务的状态信息

  1. [sunjimeng@localhost ~]$ service xinetd status
  2. Redirecting to /bin/systemctl status xinetd.service
  3. xinetd.service - Xinetd A Powerful Replacement For Inetd
  4. Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled)
  5. Active: active (running) since -- :: PDT; 22min ago
  6. Process: ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=/SUCCESS)
  7. Main PID: (xinetd)
  8. CGroup: /system.slice/xinetd.service
  9. └─ /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid

查看网络连接服务的状态信息:

  1. [root@localhost sunjimeng]# service network status
  2. Configured devices:
  3. lo eno16777736 配置_1
  4. Currently active devices:
  5. lo eno16777736

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

  1. [sunjimeng@localhost ~]$ service xinetd stop
  2. Redirecting to /bin/systemctl stop xinetd.service
  3. Failed to issue method call: Access denied //没有root权限,所以拒绝访问
  4. [sunjimeng@localhost ~]$ su root
  5. 密码: //登入root
  6. [root@localhost sunjimeng]# service xinetd stop
  7. Redirecting to /bin/systemctl stop xinetd.service
  8. [root@localhost sunjimeng]# service xinetd status
  9. Redirecting to /bin/systemctl status xinetd.service
  10. xinetd.service - Xinetd A Powerful Replacement For Inetd
  11. Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled)
  12. Active: inactive (dead) since -- :: PDT; 15s ago
  13. Process: ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=/SUCCESS)
  14. Main PID: (code=exited, status=/SUCCESS)
  15.  
  16. 6 :: localhost.localdomain xinetd[]: removing echo
  17. 6 :: localhost.localdomain xinetd[]: removing tcpmux
  18. 6 :: localhost.localdomain xinetd[]: removing time
  19. 6 :: localhost.localdomain xinetd[]: removing time
  20. 6 :: localhost.localdomain xinetd[]: xinetd Version 2.3. st...
  21. 6 :: localhost.localdomain xinetd[]: Started working: avail...
  22. 6 :: localhost.localdomain systemd[]: Started Xinetd A Powerful ...
  23. 6 :: localhost.localdomain systemd[]: Started Xinetd A Powerful ...
  24. 6 :: localhost.localdomain systemd[]: Stopping Xinetd A Powerful...
  25. 6 :: localhost.localdomain systemd[]: Stopped Xinetd A Powerful ...
  26. Hint: Some lines were ellipsized, use -l to show in full.

4)[root@localhost sunjimeng]# service xinetd restart      重启守护进程

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

5)[root@localhost sunjimeng]# service xinetd reload      重新加载守护进程xinetd的配置文件

  1. [root@localhost sunjimeng]# service xinetd reload
  2. 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:

  1. [root@localhost sunjimeng]# ls /etc/rc.d/init.d/functions
  2. /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. 快速上手UIView动画

    UIView动画有两种使用方法 UIView [begin commit]模式 //动画开始标记 [UIView beginAnimations:@"changeframe" co ...

  2. SpringMVC学习(一)小demo

    首先看一下整个demo的项目结构: 第一步是导入Spring MVC单独使用时的最少jar包: 第二步在项目的web.xml中配置Spring MVC提供的拦截请求的Servlet: 全类名是:org ...

  3. Oracle基础学习登陆SQLPLUS(一)

    SQLPLUS是ORACLE公司开发的非常简洁的管理工具,SQLPLUS是最好的,最核心的ORACLE管理工具.SQLPLUS简洁而高效,舍弃浮华,反璞归真.使用sqlplus,进入sqlplus并进 ...

  4. DWR相关知识

    解决问题:服务器给前台推送消息 用途:聊天,微信签到墙,设备报警

  5. Python - except不指定异常类别(转)

    From:How to properly ignore Exceptions? try: doSomething() except: pass or try: doSomething() except ...

  6. ionic2常见问题-启动后白屏问题

    问题描述 app启动后大概有几秒白屏,才会显示首页,如下gif图 启动有白屏.gif 解决方法1 请查看以下3张图的标注 图 1-最初config.xml配置 图 2-更改后的splash配置 图 3 ...

  7. go反射----4构建

    声明:文章内容取自雨痕老师<Go语言学习笔记> 反射库提供了内置函数make和new的对应操作,其中最有意思的就是MakeFunc.可用它实现通用模板,适应不同数据类型. package ...

  8. 第一篇:尽量多的以 const/enum/inline 替代 #define

    前言 在面向过程语言,如 C 语言中,#define 非常常见,也确实好用,值得提倡.但在如今面向对象的语言,如 C++ 语言中,#define 就要尽量少用了. 为何在 C++ 中就要少用了呢? 这 ...

  9. TP表单验证

    [表单验证] javascript jquery 在服务器端通过tp框架实现表单验证 用户名.密码.重复密码.邮箱.qq.手机号码.爱好.学历 具体步骤: 制作表单 表单form数据通过create( ...

  10. iOS学习笔记(二)——Hello iOS

    前面写了iOS开发环境搭建,只简单提了一下安装Xcode,这里再补充一下,点击下载Xcode的dmp文件,稍等片刻会有图一(拖拽Xcode至Applications)的提示,拖拽至Applicatio ...