zoukankan      html  css  js  c++  java
  • CentOS 7/8修改系统运行级别

    CentOS 5 CentOS 6可以通过修改配置文件/etc/inittab 参数,从而修改系统运行级别,切换系统的runlevel,但是从CentOS 7开始,不能用这个命令了,只能由systemd统一管理,并且减少到了两个等级(当然这里不包含poweroff.target、reboot.target等)。/etc/inittab中也明确inittab不再使用了。

    CentOS 7下的inittab文件

    注意:systemd uses 'targets' instead of runlevels. By default, there are two main targets这条信息

    [root@localhost ~]# more /etc/inittab
    # inittab is no longer used when using systemd.
    #
    # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
    #
    # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
    #
    # systemd uses 'targets' instead of runlevels. By default, there are two main targets:
    #
    # multi-user.target: analogous to runlevel 3
    # graphical.target: analogous to runlevel 5
    #
    # To view current default target, run:
    # systemctl get-default
    #
    # To set a default target, run:
    # systemctl set-default TARGET.target
    #

    CentOS 8下的inittab文件

    注意:systemd uses 'targets' instead of runlevels. By default, there are two main targets这条信息

    [root@localhost ~]#   cat /etc/inittab
    # inittab is no longer used.
    #
    # ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
    #
    # Ctrl-Alt-Delete is handled by /usr/lib/systemd/system/ctrl-alt-del.target
    #
    # systemd uses 'targets' instead of runlevels. By default, there are two main targets:
    #
    # multi-user.target: analogous to runlevel 3
    # graphical.target: analogous to runlevel 5
    #
    # To view current default target, run:
    # systemctl get-default
    #
    # To set a default target, run:
    # systemctl set-default TARGET.target

    系统运行级别都定义在/lib/systemd/system下:

    [root@localhost ~]# ll /usr/lib/systemd/system/runlevel*
    lrwxrwxrwx. 1 root root 15 6月  18 17:06 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
    lrwxrwxrwx. 1 root root 13 6月  18 17:06 /usr/lib/systemd/system/runlevel1.target -> rescue.target
    lrwxrwxrwx. 1 root root 17 6月  18 17:06 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
    lrwxrwxrwx. 1 root root 17 6月  18 17:06 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
    lrwxrwxrwx. 1 root root 17 6月  18 17:06 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
    lrwxrwxrwx. 1 root root 16 6月  18 17:06 /usr/lib/systemd/system/runlevel5.target -> graphical.target
    lrwxrwxrwx. 1 root root 13 6月  18 17:06 /usr/lib/systemd/system/runlevel6.target -> reboot.target
    
    /usr/lib/systemd/system/runlevel1.target.wants:
    总用量 0
    lrwxrwxrwx. 1 root root 39 6月  18 17:06 systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service
    
    /usr/lib/systemd/system/runlevel2.target.wants:
    总用量 0
    lrwxrwxrwx. 1 root root 39 6月  18 17:06 systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service
    
    /usr/lib/systemd/system/runlevel3.target.wants:
    总用量 0
    lrwxrwxrwx. 1 root root 39 6月  18 17:06 systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service
    
    /usr/lib/systemd/system/runlevel4.target.wants:
    总用量 0
    lrwxrwxrwx. 1 root root 39 6月  18 17:06 systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service
    
    /usr/lib/systemd/system/runlevel5.target.wants:
    总用量 0
    lrwxrwxrwx. 1 root root 39 6月  18 17:06 systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service
    [root@localhost ~]# 

     从上图可以看到runlevel2.target、runlevel3.target、runlevel4.target 这些软连接都是指向multi-user.target

    通过命令来查看运行级别:

    [root@localhost ~]# systemctl get-default   # 查看默认运行级别
    multi-user.target
    [root@localhost ~]# runlevel
    N 3

    通过命令来设置运行级别:

    systemd命令修改:
    
     
    
    #systemctl set-default TARGET.target
    
     
    
    修改软连接方式:
    
     
    
    # ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

    测试例子如下:

    例1:

    [root@db-server tmp]# systemctl set-default graphical.target
    Removed symlink /etc/systemd/system/default.target.
    Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
    [root@db-server tmp]# 

    例2:

    [root@kerrydb ~]# systemctl get-default
    graphical.target
    [root@kerrydb ~]# runlevel
    N 5
    [root@kerrydb ~]# systemctl set-default multi-user.target
    Removed /etc/systemd/system/default.target.
    Created symlink /etc/systemd/system/default.target → /usr/lib/systemd/system/multi-user.target.
    [root@kerrydb ~]# systemctl get-default
    multi-user.target
    [root@kerrydb ~]# 

    例3:

    [root@kerrydb ~]# systemctl get-default
    multi-user.target
    [root@kerrydb ~]# ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
    [root@kerrydb ~]# systemctl get-default
    multi-user.target
    [root@kerrydb ~]# ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target
    [root@kerrydb ~]# systemctl get-default
    multi-user.target

     

    # 可设置的运行级别
    runlevel0.target -> poweroff.target
    runlevel1.target -> rescue.target
    runlevel2.target -> multi-user.target
    runlevel3.target -> multi-user.target
    runlevel4.target -> multi-user.target
    runlevel5.target -> graphical.target
    runlevel6.target -> reboot.target

    修改后需要重启服务器才能生效。否则只对当前连接生效。

  • 相关阅读:
    有点忙啊
    什么是协程
    HDU 1110 Equipment Box (判断一个大矩形里面能不能放小矩形)
    HDU 1155 Bungee Jumping(物理题,动能公式,弹性势能公式,重力势能公式)
    HDU 1210 Eddy's 洗牌问题(找规律,数学)
    HDU1214 圆桌会议(找规律,数学)
    HDU1215 七夕节(模拟 数学)
    HDU 1216 Assistance Required(暴力打表)
    HDU 1220 Cube(数学,找规律)
    HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)
  • 原文地址:https://www.cnblogs.com/liujunjun/p/13260772.html
Copyright © 2011-2022 走看看