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. leetCode 75.Sort Colors (颜色排序) 解题思路和方法

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  2. 应用市场出新规,国内千款应用TargetSdkVersion调查分析

    ​​​近期,谷歌针对Google Play上架应用发布强制性适配Android 8.0公告,要求自2018 年 8 月 1 日起,所有向 Google Play 首次提交的新应用都必须基于 Andro ...

  3. memcached 经常使用命令最全总结大全

    1.首先.总结一下memcached的一些基本设置 -p 监听的port -l 连接的IP地址, 默认是本机 -d start 启动memcached服务 -d restart 重起memcached ...

  4. ftp 下载最近一小时的文件

    #!/bin/bash #cd /home/ftptmp/ ftp -v -n 192.168.0.100 2121 <<EOF user  test  2009 binary cd OU ...

  5. JS判断不同的浏览器,不同的浏览器版本

    JS判断不同的浏览器,不同的浏览器版本

  6. stick footers布局

    需求: 将footer固定到底部.文章内容不足满屏时 footer在底部,超过满屏时footer在内容末尾. 方法一: <div id="wrap"> <div ...

  7. OpenCV中Camshitf算法学习(补充)

    结合OpenCV中Camshitf算法学习,做一些简单的补充,包括: 实现全自动跟随的一种方法 参考opencv中的相关demo,可以截取目标物体的图片,由此预先计算出其色彩投影图,用于实际的目标跟随 ...

  8. weixin oauth 授权

    1. 先了解下请求授权页面的构造方式:   https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_u ...

  9. Ant Design使用问题记录

    公司的测试管理平台前端使用的是Ant Design of React框架,后台使用的是python,数据库用的是mysql.没有参与前期的开发,听说是工作了10年积累下来的一个暂且可用的管理平台,开发 ...

  10. [Spring MVC]学习笔记--@RequestMapping

    @RequestMapping是用来将请求的url,映射到整个类,或者里面的方法. @Controller @RequestMapping("/test") public clas ...