zoukankan      html  css  js  c++  java
  • 每天一个Linux命令(53)service命令

        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 日 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 

  • 相关阅读:
    青山一别
    Spring Mvc Long类型精度丢失
    Spring 版MediatR--中介者模式实现库
    Spring 实现策略模式--自定义注解方式解耦if...else
    spring泛型注入
    Spring Boot Mvc 统一返回结果
    简化mapstruct代码: mapstruct-spring-plus
    .NET后端开发编码规范
    深度优先遍历(DFS)和广度优先遍历(BFS)的实现与简单应用
    将HTML字符串编译为虚拟DOM对象的基础实现
  • 原文地址:https://www.cnblogs.com/MenAngel/p/5600782.html
Copyright © 2011-2022 走看看