• Linux服务


    Linux服务分为RPM包默认安装的服务和源码包安装的服务
    RPM包默认安装的服务分为独立的服务和基于xinetd服务

    启动:在当前系统中让服务运行,并提供功能。
    自启动:让服务在系统开机或重启动之后,随着系统的启动而自动启动服务

    RPM包安装的服务
    chkconfig --list

    源码包安装的服务
    查看服务安装的位置 一般是/usr/local/下

    [root@localhost ~]# chkconfig --list
    netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
    network 0:关 1:关 2:开 3:开 4:开 5:开 6:关

    分析:0-6代表Linux系统的7个默认级别
    0:关机
    1:单用户
    2: 不完全用
    3:字符界面
    4:未分配
    5:图形界面
    6:重启动

    独立服务的管理:

    /etc/init.d/: 启动脚本位置
    /etc/sysconfig/: 初始化环境配置文件位置
    /etc/: 配置文件位置
    /etc/xinetd.conf:xinetd配置文件
    /etc/xinetd.d/: 基于xinetd服务的启动脚本
    /var/lib/: 服务产生的数据放在这里
    /var/log/: 日志

    启动方法:
    方法1:
    /etc/init.d/独立服务名 start|stop|status|restart

    方法2:
    service 独立服务名 start|stop|restart|status

    查询所有服务状态
    service --status-all
    ----------------------------------------------------
    自启动
    查询:chkconfig --list | grep httpd
    结果:httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭

    执行 chkconfig --level 2345 httpd on
    结果 httpd 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭

    关闭自启动:
    chkconfig httpd off 默认就是操作的2345

    自启动方法二(推荐)
    修改 /etc/rc.d/rc.local文件
    添加一行:
    /etc/rc.d/init.d/httpd start

    基于xinetd的服务管理

    安装xinetd与telnet

    yum -y install xinetd
    yum -y install telnet-server

    查看,多了基于 xinetd 的服务
    [root@localhost ~]# chkconfig --list

    netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
    network 0:关 1:关 2:开 3:开 4:开 5:开 6:关

    基于 xinetd 的服务:
    chargen-dgram: 关
    chargen-stream: 关
    daytime-dgram: 关
    daytime-stream: 关
    discard-dgram: 关
    discard-stream: 关
    echo-dgram: 关
    echo-stream: 关
    tcpmux-server: 关
    time-dgram: 关
    time-stream: 关
    [root@localhost ~]#
    [root@localhost ~]# netstat -tlun
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address Foreign Address State
    tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
    tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
    tcp6 0 0 :::3306 :::* LISTEN
    tcp6 0 0 :::22 :::* LISTEN
    tcp6 0 0 ::1:25 :::* LISTEN
    udp 0 0 127.0.0.1:323 0.0.0.0:*
    udp6 0 0 ::1:323 :::*

    没有开启23端口,23端口是telnet
    该示例没有成功!找不到 /etc/xinetd.d/telnet 文件,无法修改其配置。


    xinetd 的自启动
    chkconfig telnet on

    xinetd 的关闭
    chkconfig telnet off


    xinetd的启动和自启动是通用的

    源码包安装的服务的启动:
    使用绝对路径启动。不同的源码包的启动脚本不同。可以查看源码包的安装说明,查看启动脚本的方法。
    例如:
    /usr/local/apache2/bin/apachectl start|stop

    自启动方法:
    vi /etc/rc.d/rc.local
    添加一行:
    /usr/local/apache2/bin/apachectl start

    不推荐
    让源码包的apache服务能被service命令管理启动:建立一个软连接
    ln -s /usr/local/apache2/bin/apachectl /etc/init.d/apache

    启动:service apache restart

    让源码包的apache服务能被chkconfig管理自启动
    vim /etc/init.d/apache

    # chkconfig: 35 86 76
    # 指定httpd脚本可以被chkconfig命令管理。格式是:
    chkcofig: 运行级别 启动顺序 关闭顺序
    # description: source package apache
    # 说明,内容随意

    注释不能省略

    chkconfig --add apache #把apache加入chkconfig命令
    chkconfig --list | grep apache
    chkconfig apache on
    chkconfig --list | grep apache

  • 相关阅读:
    用IIS做宿主的WCF服务
    Apache+mono+xsp搭建Linux下的asp.net平台
    web页面中的卡片布局代码
    GridView内的数据循环滚动
    adb 无法启动问题
    User interface
    动态生成linearLayout
    跳转到下一个activity
    android studio 快捷键
    [转]项目失败的经验
  • 原文地址:https://www.cnblogs.com/javasl/p/11190527.html
Copyright © 2020-2023  润新知