zoukankan      html  css  js  c++  java
  • 服务和进程管理(二)

    二、Linux服务管理

     
    1、分类
                1、系统默认安装的服务    rpm包
                        ①独立的服务
                        ②基于xinetd的服务,xinetd是系统超级守护进程
     
                2、源码包安装的服务
     
    2、(一)系统默认安装的服务
     
            1、确定服务分类
                chkconfig    --list            查看服务的自启动状态
     
            2、独立的服务器管理
                
                1、启动
    推荐             ①    /etc/rc.d/init.d/服务名    start|stop|restart|status
                      例子  /etc/rc.d/init.d/httpd    start
     
                        ②    service    服务名    statr|stop|restart|status
     
                2、自启动(两种方法只能同时使用一种)
                         ①    chkconfig    --level    2345    服务名    on|off    (2345见5的系统运行级别)
                        
    推荐                  vi    /etc/rc.local  或者---->/etc/rc.d/rc.local(系统启动以后,会自动启动该文件中的命令)
                        例子    /etc/rc.d/init.d/httpd    start 
                                   /usr/local/php/sbin/php-fpm start
    1. [root@centos ~]# vi /etc/rc.local
    2.       1 #!/bin/sh
    3.       2 #
    4.       3 # This script will be executed *after* all the other init scripts.
    5.       4 # You can put your own initialization stuff in here if you don't
    6.       5 # want to do the full Sys V style init stuff.
    7.       6 
    8.       7 touch /var/lock/subsys/local
    9.       8 /etc/rc.d/init.d/httpd start       
     
                 
                3、ntsysv
                    所有系统默认安装服务都可以使用ntsysv命令进行自启动管理
     
    /etc/rc.d/init.d下的服务
    1. [root@centos init.d]# ls
    2. abrt-ccpp         cpuspeed      iptables      netfs        psacct       rsyslog    udev-post
    3. abrtd             crond         irqbalance    network      quota_nld    sandbox    winbind
    4. abrt-oops         cups          kdump         nfs          rdisc        saslauthd  ypbind
    5. acpid             functions     killall       nfslock      restorecond  single
    6. atd               haldaemon     lvm2-lvmetad  ntpd         rngd         smartd
    7. auditd            halt          lvm2-monitor  ntpdate      rpcbind      sshd
    8. autofs            htcacheclean  mdmonitor     oddjobd      rpcgssd      sssd
    9. blk-availability  httpd         messagebus    portreserve  rpcidmapd    sysstat
    10. certmonger        ip6tables     netconsole    postfix      rpcsvcgssd   tomcat6
     
     
        (二)源码包安装的服务
            1、源码包安装的服务
     
                1、绝对路径启动
                        /usr/local/apache2/bin/apachect1    start
     
                2、自启动
                        vi    /etc/rc.local
                        /usr/local/apache2/bin/apachect1    start
     
    3、服务管理(2中的(一)和(二)的总结)
    1、RPM包安装服务
            独立的服务
                启动:     /etc/rc.d/init.d/httpd    start    推荐
                           ②               service httpd    start
     
                自启动:① chkconfig    --level    2345    httpd    on|off
                              ② vi    /etc/rc.local        推荐
                                    /etc/rc.d/init.d/httpd    start
     
            基于xinetd的服务(越来越少了,不讲了)
     
    2、源码包服务
                 启动: /usr/local/apache2/bin/apachect1    start
     
                自启动:    vi    /etc/rc.local
                                        /usr/local/apache2/bin/apachect1    start   

    源码包的安装位置:/usr/local/
    RPM包的安装位置:/etc/rc.d/init.d

     
    4、计划任务(不会立即执行,会自动判断系统的繁忙度,有可能会推迟几分钟才执行)
            
            echo    11    >>    /root/aa    在aa文件中追加11.一会定时任务用来验证(暂时用来代替shell脚本,还没学)
     
            ps aux    | grep crond    查找指定的crond命令服务(要显示crond,即第2行才可以)
    1. [root@localhost ~]# ps aux |grep crond
    2. root      1364  0.0  0.1   7148  1284 ?        Ss   17:34   0:01 crond
    3. root      1592  0.0  0.0   5980   728 pts/0    S+   18:16   0:00 grep crond
    crond服务启动(编辑方式类vim)
     
            循环定时任务
            crontab    -e    编辑定时任务
            * * * * * 命令
            10 * 31 * * 命令
            10 * * * * 命令
            5 4 * 5-10 * 命令
            */10 * * * *  命名
            5 4 1,15 * * 命令    日期和星期不要同时指定,会超出预期
        
            第一个*:一小时中第几分钟    0-59
            第二个*:一天中第几个小时    0-23
            第三个*:一个月中第几天        1-31
            第四个*:一年中第几个月        1-12
            第五个*:一周中星期几            0-6
     
           crontab    -l        查看系统定时任务
           crontab    -r        删除定时任务
     
    注意事项:
    1. 选项都不能为空,必须填入,不知道的值使用通配符*表示任何时间
    2. 每个时间自动都可以指定多个值,不连续的值用“,”间隔,连续的值用“-”间隔
    3. 间隔固定时间执行属性为“*/n”格式
    4. 命令应该给出绝对路径
    5. 星期几和第几天不能同时出现(星期几执行,第几天也会执行)    
    6. 最小时间范围是分钟,最大时间范围是月份
    5、系统运行级别
     
            1、    dmesg                                查看系统启动信息
                      cat    /var/log/dmesg          系统启动信息日志
     
                     dmesg | grep eth0                查看eth0信息
                     dmesg | grep CPU                查看CPU信息
    windows安装之后需要手动安装驱动才能使用,UNIX系统会自动检测硬件安装驱动
     
            2、 系统运行级别:0-6(链接到命令行的基本使用(关机重启))
                    0        关机
                    1        单用户模式(windows中的 安全模式
                    2        不完全多用户,不包含NFS服务
                    3        完全多用户, 字符界面
                    4        未分配
                    5        图形界面
                    6        重启       
            
                    init    0    关机    
                    init    5    startx
                    init    3
                    init    6    重启
     
                    runlevel                   查询系统当前运行级别
     
                    init 运行级别            改变运行级别    
     
                    vi    /etc/inittab        init配置文件
                    id:3:initdefault:        定义系统默认运行级别(1和6不能使用)
     
     
     




    php是世界上最好的编程语言,没有之一
  • 相关阅读:
    [React] Cleaning up Functional Components with Custom Hooks
    [React] useCallback + useMemo to avoid re-render
    [React] Replacing Instance Variables with the useRef Hook
    [Cloud Architect] 4. Introduction to Design for Cost, Performance, & Scalability
    [Cloud Architect] 3. Monitor, React, and Recover
    [Cloud Architect] 3. Business Objectives
    1314:【例3.6】过河卒(Noip2002)
    1313:【例3.5】位数问题
    rk3568 linux sdk Buildroot 开发
    AcWing 873. 欧拉函数
  • 原文地址:https://www.cnblogs.com/lookphp/p/4683082.html
Copyright © 2011-2022 走看看