CentOS 7以前的版本
修改 /etc/inittab 文件,将“id:5:initdefault:”这一行的"id:"后的数字(默认为5)改为 3即可。
Linux将X-Window(简称X)仅仅视作一个程序,而不捆绑于其内核之中。在UNIX/Linux中一般将运行级别分为7级(一说九级,但实际应用为六级,保留一级):
0 系统停机
1 单用户模式
2 多用户模式
3 网络多用户模式
4 保留
5 X11模式(即进入图形界面模式)
6 重起
要想修改Linux开机的启动模式(控制台或图形界面等),只需修改/etc/inittab文件。
/etc/inittab文件(部分):# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
要想修改启动级别,将“id:5:initdefault:”这一行的"id:"后的数字(默认为5)改为你要的级别即可。
注意:不要改为0,0表示关机;也不要改为6,否则开机就不停的重启了~
CentOS 7版本改为以下的方法
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# Ctrl-Alt-Delete is handled by /etc/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 set a default target, run:
#
# ln -sf /lib/systemd/system/<target name>.target /etc/systemd/system/default.target
#
[root@localhost ~]# cat /etc/systemd/system/default.target
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
就是说要用
ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
或者
默认运行级别3:systemctl set-default multi-user.target
默认运行级别5:systemctl set-default graphical.target
修改后,启动CentOS无法登录,显示module is unknown
但是用SSH可以登录,查看日志 tail -n 50 /var/log/secure
Aug 14 21:37:00 localhost login: Module is unknown
Aug 14 21:37:08 localhost login: PAM unable to dlopen(/lib/security/pam_limits.so): /lib/security/pam_limits.so: cannot open shared object file: No such file or directory
Aug 14 21:37:08 localhost login: PAM adding faulty module: /lib/security/pam_limits.so
Aug 14 21:37:12 localhost login: pam_unix(login:session): session opened for user oracle by LOGIN(uid=0)
再看登录验证文件 cat /etc/pam.d/login
发现是使用了32位的验证文件,改为64位的就可以了
#%PAM-1.0
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth substack system-auth
auth include postlogin
account required pam_nologin.so
account include system-auth
password include system-auth
# pam_selinux.so close should be the first session rule
session required pam_selinux.so close
session required pam_loginuid.so
session optional pam_console.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session required pam_selinux.so open
session required pam_namespace.so
session optional pam_keyinit.so force revoke
session include system-auth
session include postlogin
-session optional pam_ck_connector.so
session required /lib/security/pam_limits.so ⇒ /lib64/security/pam_limits.so
session required pam_limits.so
保存后重启启动,OK!