Linux系统重要文件(三)


一系统运行级别文件


文件路径:/etc/inittab

文件作用说明:定义系统启动后,自动开启哪些软件程序系统

runlevel 查看当前运行级别

centos6系统运行级别: 7个级别
 
   0   -- 系统关机级别    init 0
   1   -- 系统单用户级别  

   用于破解系统密码root,救援恢复系统数据,没有网络服务
                      
   2   -- 系统多用户级别  没有网络多用户级别 
   3   -- 系统多用户级别  拥有网络多用户级别,生产中使用最多  
   4   -- 未使用级别
   5   -- 系统图形化级别  
   6   -- 系统重启级别    init 6

(一)查看当前运行级别

[root@centos61 ~]# cat  /etc/redhat-release 
CentOS release 6.8 (Final)
[root@centos61 ~]# runlevel 
N 3
[root@centos71 ~]# cat  /etc/redhat-release
CentOS Linux release 7.6.1810 (Core) 
[root@centos71 ~]# runlevel 
N 3

(二)centos6设置系统级别

临时设置:init   级别数字

[root@centos61 ~]# cat  /etc/inittab 
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used 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:3:initdefault:

此时断开远程连接

[root@centos61 ~]# init  1
[root@centos61 ~]# 
Connection closed by foreign host.

Disconnected from remote host(centos61) at 19:24:25.

Type `help' to learn how to use Xshell prompt.
[c:~]$ 

永久设置

对配置文件/etc/inittab修改

可以使用小工具进行修改,比如sed,awk,强化练习

[root@centos61 ~]# sed  -i   s/:3:/:1:/g  /etc/inittab 
[root@centos61 ~]# tail  -1   /etc/inittab  
id:1:initdefault:
[root@centos61 ~]# runlevel 
S 3
[root@centos61 ~]# reboot 

Broadcast message from root@centos61.huawei.com
    (/dev/pts/2) at 19:33 ...

The system is going down for reboot NOW!
[root@centos61 ~]# 
Connection closed by foreign host.

Disconnected from remote host(centos6-1) at 19:33:29.

Type `help' to learn how to use Xshell prompt.

注意还要执行init  3才可以的

[root@centos61 ~]# runlevel 
S 3

(三)centos7设置系统级别

和centos6有区别,使用target模式

[root@centos7 ~]# ll  /usr/lib/systemd/system/runlevel*target
lrwxrwxrwx. 1 root root 15 Nov 26 17:33 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Nov 26 17:33 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Nov 26 17:33 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Nov 26 17:33 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Nov 26 17:33 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Nov 26 17:33 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Nov 26 17:33 /usr/lib/systemd/system/runlevel6.target -> reboot.target
[root@centos7 ~]# runlevel 
N 3
[root@centos71 ~]# ll   /usr/lib/systemd/system/multi-user.target
-rw-r--r--. 1 root root 492 Oct 31  2018 /usr/lib/systemd/system/multi-user.target
[root@centos71 ~]# ll   /usr/lib/systemd/system/rescue.target
-rw-r--r--. 1 root root 486 Oct 31  2018 /usr/lib/systemd/system/rescue.target
[root@centos71 ~]# cat  /usr/lib/systemd/system/multi-user.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.

[Unit]
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes


[root@centos71
~]# cat /usr/lib/systemd/system/rescue.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. [Unit] Description=Rescue Mode Documentation=man:systemd.special(7) Requires=sysinit.target rescue.service After=sysinit.target rescue.service AllowIsolate=yes [Install] Alias=kbrequest.target
   
 
临时设置:   init 级别数字
 

 
 
 
 
 

永久设置

 
在6版本的默认配置文件写明了
[root@centos71 ~]# cat  /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
 
 
 
  
 
 
 
 
 
输入系统设置的口令即可
 
 
 
 
 
 
 
 
实现远程连接,切换级别
 
 
 
 
 
 
 
 
 
 
 
 
 

二系统登录前后提示文件

 
 

(一)登录系统前显示提示信息

文件路径: /etc/issue     /etc/issue.net
  
[root@centos71 ~]# ll  /etc/issue*
-rw-r--r--. 1 root root 23 Nov 23  2018 /etc/issue
-rw-r--r--. 1 root root 22 Nov 23  2018 /etc/issue.net
[root@centos71 ~]# cat  /etc/issue*
S
Kernel 
 on an m

S
Kernel 
 on an m
[root@centos71 ~]# cat  /etc/issue
S
Kernel 
 on an m

[root@centos71 ~]# cat  /etc/issue.net 
S
Kernel 
 on an m
[root@centos71 ~]# 
文件内容没有多大区别
[root@centos71 ~]# diff   /etc/issue*
3d2
< 
[root@centos71 ~]# wc   /etc/issue.net 
 2  6 22 /etc/issue.net
[root@centos71 ~]# wc   /etc/issue
 3  6 23 /etc/issue
 
 
 
 
 
 
 

(二)登录系统后显示提示信息


文件路径: /etc/motd

 默认没有内容,可以添加有意义的
 
[root@centos61 ~]# ll  /etc/motd 
-rw-r--r--. 1 root root 0 Jan 12  2010 /etc/motd
 
 
[root@centos71 ~]# cat  /etc/motd 
                              (@@) (  ) (@)  ( )  @@    ()    @     O     @     O      @
                                 (   )
                             (@@@@)
                          (    )

                        (@@@)
                    ====        ________                ___________
                _D _|  |_______/        \__I_I_____===__|_________|
                 |(_)---  |   H\________/ |   |        =|___ ___|      _________________
                 /     |  |   H  |  |     |   |         ||_| |_||     _|                \_____A
                |      |  |   H  |__--------------------| [___] |   =|                        |
                | ________|___H__/__|_____/[][]~\_______|       |   -|                        |
                |/ |   |-----------I_____I [][] []  D   |=======|____|________________________|_
              __/ =| o |=-~~  /~~  /~~  /~~ ____Y___________|__|__________________________|_
               |/-=|___|=O=====O=====O=====O   |_____/~\___/          |_D__D__D_|  |_D__D__D_|
                \_/      \__/  \__/  \__/  \__/      \_/               \_/   \_/    \_/   \_/
 
 
 
[root@centos71 ~]# ll  /etc/motd
-rw-r--r--. 1 root root 1125 Dec  5 11:17 /etc/motd
 
 


 
 
 
 
 
 
 
 
 
 

三系统主机名配置文件


文件路径信息:/etc/hostname
文件作用说明:修改主机名称
 
 
PS:企业需求,统计主机信息==资产管理
PS可以理解为多说一句,plus  say
主机信息包括主机名称、主机网络地址、主机品牌型号、主机CPU、主机内存、主机存储信息
主机名称: 区域-机房-机柜号码-机器编号 BJ - pbs-010203  - 01
                 
 
 
 
 
 
 

(一)centos6/7系统主机名称临时修改

hostname 

[root@centos61 ~]# hostname 
centos61.huawei.com
[root@centos61 ~]# hostname  centos6.com
[root@centos61 ~]# exit 
logout

Connection closed by foreign host.

Disconnected from remote host(centos6-1) at 20:08:22.

Type `help' to learn how to use Xshell prompt.
[c:~]$ 

Connecting to 10.0.0.61:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Thu Dec  5 19:38:01 2019 from 10.0.0.1
[root@centos6 ~]# hostname 
centos6.com

文件内容没有变化

[root@centos6 ~]# cat /etc/sysconfig/network   
NETWORKING=yes
HOSTNAME=centos61.huawei.com
centos7的方法一样
[root@centos7 ~]# hostname   centos7.jd.com
[root@centos7 ~]# exit 
logout

Connection closed by foreign host.

Disconnected from remote host(centos7-1) at 09:58:58.

Type `help' to learn how to use Xshell prompt.
[c:~]$ ssh  10.0.0.72

Connecting to 10.0.0.200:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Wed Dec  4 08:27:57 2019 from 10.0.0.1
[root@centos7 ~]# hostname
centos7.jd.com
[root@centos7 ~]# cat  /etc/hostname 
centos7.com

   
 
 
 
 
 
 

(二)centos6系统主机名称永久修改

注意修改之后要重启,注销没用

[root@centos6 ~]# hostname  
centos6.com
[root@centos6 ~]# cat /etc/sysconfig/network   
NETWORKING=yes
HOSTNAME=centos61.com
[root@centos6 ~]# exit 
logout

Connection closed by foreign host.

Disconnected from remote host(centos6-1) at 20:13:19.

Type `help' to learn how to use Xshell prompt.
[c:~]$ 

Connecting to 10.0.0.61:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Thu Dec  5 20:08:28 2019 from 10.0.0.1
[root@centos6 ~]# hostname  
centos6.com

重启之后变成了centos61

[root@centos6 ~]# hostname  
centos6.com
[root@centos6 ~]# reboot 

Broadcast message from root@centos6.com
    (/dev/pts/0) at 20:14 ...

The system is going down for reboot NOW!
[root@centos6 ~]# 
Connection closed by foreign host.

Disconnected from remote host(centos6-1) at 20:14:36.

Type `help' to learn how to use Xshell prompt.
[c:~]$ 

Connecting to 10.0.0.61:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

Last login: Thu Dec  5 20:13:23 2019 from 10.0.0.1
[root@centos61 ~]# hostname  
centos61.com
[root@centos61 ~]# cat /etc/sysconfig/network   
NETWORKING=yes
HOSTNAME=centos61.com

(三)centos7系统主机名称永久修改

要修改两处

[root@centos71 ~]# cat     /etc/hostname 
centos71.com
[root@centos71 ~]# sed -i  s@71@7@g   /etc/hostname
[root@centos71 ~]# cat     /etc/hostname 
centos7.com
[root@centos71 ~]# hostnamectl    set-hostname  centos7.com
 
[c:~]$ 

Connecting to 10.0.0.200:22...
Connection established.
To escape to local shell, press Ctrl+Alt+].

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Thu Dec  5 20:05:40 2019 from 10.0.0.1
[root@centos7 ~]# host
-bash: host: command not found
[root@centos7 ~]# hostname
centos7.com
 
 
 

 


作者:wang618
出处:https://www.cnblogs.com/wang618/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/wang618/p/11990911.html