目录
Linux目录层次标准
在Linux系统中,目录、字符设备、块设备、套接字、打印机等都被抽象成了文件。Linux按照文件系统层次化标准(Filesystem Hierarchy Standard,FHS)采用树形结构来存放文件,并定义了常见目录的用途(Linux系统中的目录和文件名称是严格区分大小写的)。
FHS是用户在Linux系统中存储文件时需要遵守的规则,用于指导用户应该将文件保存在什么位置,以及在何处找到所需的文件。FHS依据文件系统使用的频繁与否与是否允许使用者随意更动,将目录定义为四种交互作用的形态:
- 可分享的:可以分享给其它系统挂载使用的目录;
- 不可分享的:本机运作的配置文件或与程序有关的socket文件;
- 不变的:不会经常变动的数据,如函数库、文件说明文件、服务配置文件等;
- 可变的:经常改变的数据,如登录文件、邮件信息等。
FHS针对目录树架构仅定义出三层目录下该放什么数据:
/ | 与开机系统有关 |
---|---|
/usr | 与软件安装/执行有关 |
/var | 与系统运作过程有关 |
根目录
根目录是整个系统最重要的一个目录,因为不但所有的目录都是由根目录衍生出来的,并且根目录与开机、还原、系统修复等动作有关。
因为根目录如此重要,所以FHS标准建议根目录所在分区应该越小越好,并且应用程序所安装的软件最好不要与根目录放在同一个分区,这样根分区所在文件系统不容易出现问题。
/usr
/var
Linux目录结构和Windows目录结构差异
Windows目录结构
- 按照盘符划分,每个分区下都有一个独立的树状结构。
- Windows哲学思想:
一切皆是图形;
用户体验性为上;
尽可能隐藏实现过程。
Linux目录结构
- Linux哲学思想:
一切皆是文件(包括/dev目录下的设备文件);
小型、单一用途的程序;
配置数据放置于文本。
一切从根开始,只有一个单独的树状结构。没有Windows系统磁盘驱动器的概念,所有分区都被当做目录使用加载于根目录下。
Linux目录结构中的重要文件
网卡配置文件
网卡配置文件详解
[root@localhost Desktop]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE="Ethernet" --指定网络类型 以太网
BOOTPROTO="none" --网络获取IP地址的方式
1.dhcp 自动获取IP地址
2.none 手动配置ip地址
3.static 手动配置ip地址
NAME="eth0" --主机网卡名称 逻辑名称
UUID="e1551cc3-3446-4e9d-ba99-3fd3c56ff5e3" --虚拟主机会给每个硬件一个标识(身份证件)
DEVICE="eth0" --主机网卡名称 物理(设备)名称
ONBOOT="yes" --设置网卡是否处于开启状态(激活)
IPADDR="192.168.75.12" --静态配置IP地址
PREFIX="24" --掩码,定义网络中有多少主机
GATEWAY="192.168.75.2" --网关,一个网络到另一个网络的必经之路
DNS1="8.8.8.8" --域名系统
修改网卡配置的方式
- # nmtui
- # vim /etc/sysconfig/network-scripts/ifcfg-eth0
Linux系统服务配置文件修改之后不会立即生效,需要重启服务(重现加载读取配置文件过程),才能使配置文件的修改生效。
重启方法一:# systemctl restart network 全部网卡重启
重启方法二:# ifdown eth0 && ifup eth0 指定网卡重启
网络解析文件
网络解析文件详解
[root@localhost Desktop]# cat /etc/resolv.conf
# Generated by NetworkManager
search localdomain localhost.com --定义域名的搜索列表
nameserver 114.114.114.114 --定义DNS服务器的IP地址
主机名称配置文件
修改主机名称方式
- CentOS 7
临时修改(重启失效):hostname 主机名
永久修改(重启生效):vim /etc/hostname[root@localhost Desktop]# hostname localhost.com [root@localhost Desktop]# hostname letty-01 [root@localhost Desktop]# hostname letty-01
注意:在系统中对配置进行永久修改时,都需要修改配置文件。
CentOS 7特有的修改主机名称的方式:通过命令实现临时和永久同时修改[root@localhost Desktop]# vim /etc/hostname Letty-01 [root@localhost Desktop]# reboot
[root@localhost Desktop]# hostnamectl set-hostname letty-02 [root@localhost Desktop]# hostname letty-02 [root@localhost Desktop]# cat /etc/hostname letty-02
- CentOS 6
临时修改:hostname 主机名
永久修改:vim /etc/sysconfig/network
解析映射文件
hosts文件是Linux系统上一个负责ip地址与域名快速解析的文件,以ASCII格式保存在/etc/目录下。hosts文件包含了ip地址与主机名之间的映射,还包括主机的别名。在没有域名解析服务器的情况下,系统上的所有网络程序都通过查询该文件来解析对应于某个主机名的ip地址,否则就需要使用dns服务程序来解决。通过可以将常用的域名和ip地址映射加入到hosts文件中,实现快速方便的访问。
优先级 : dns缓存 > hosts > dns服务
- Windows本地解析文件位置:C:\Windows\System32\drivers\etc\hosts
# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost
- Linux解析文件位置:/etc/hosts
[root@letty-02 Desktop]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
存储设备挂载文件
fstab表参数解析
服务自启配置文件
通过查看可以发现/etc/rc.d/rc.local是/etc/rc.local的原文件,但是/etc/rc.d/rc.local并没有可执行权限,因此需要使用命令chmod +x /etc/rc.d/rc.local后,才能使用/etc/rc.local文件。
[root@letty-02 Desktop]# vim /etc/rc.local
[root@letty-02 Desktop]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Apr 9 22:10 /etc/rc.local -> rc.d/rc.local
[root@letty-02 Desktop]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 473 Apr 27 21:15 /etc/rc.d/rc.local
当系统启动时,会加载/etc/rc.local文件中的内容,将其内容作为命令执行一遍,由此可实现服务开机自启。
启动级别文件
Centos 6 runlevel查看方式
- # runlevel
- # cat /etc/inittab
Centos 6 runlevel修改方式
- 临时修改
# init 切换的运行级别
- 永久修改:
# vim /etc/inittab id:切换的运行级别:initdefault:
runlevel修改方式
- 临时修改
# init 切换的运行级别
- 永久修改:
# vim /etc/inittab id:切换的运行级别:initdefault:
Centos 7 target查看方式
- systemctl get-default 命令(CentOS 7 特有方式)
[root@letty-02 Desktop]# systemctl get-default graphical.target
- runlevel(CentOS 6 的方式)
[root@letty-02 Desktop]# runlevel N 5
Centos 7 target修改方式
-
临时修改(CentOS 6 的方式)
[root@letty-02 Desktop]# init 3 [root@letty-02 Desktop]# init 5 [root@letty-02 Desktop]# runlevel 3 5
-
永久修改
systemctl set-default 命令(CentOS 7 特有方式)[root@letty-02 Desktop]# 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@letty-02 Desktop]# systemctl get-default --检查默认级别 graphical.target
登录提示文件
登录之后提示文件
/etc/motd文件:对操作系统的用户进行注意事项说明,每次用户登录时。/etc/motd文件的内容会显示在用户的终端。
[root@letty-02 Desktop]# cat /etc/motd --默认没有内容
[root@letty-02 Desktop]#
[root@letty-02 Desktop]# vim /etc/motd --编辑登录之后提示信息
Hello, world.
[root@letty-02 Desktop]# cat /etc/motd
Hello, world.
测试
登录之前提示文件
- /etc/issue和/etc/issue.net都是Linux终端登录的欢迎语句,文件内容显示在login提示符之前。默认情况下/etc/issue和/etc/issue.net文件内容相同。
- /etc/issue文件是提供给本地终端登录显示的(非图形界面);/etc/issue.net文件是提供给telnet远程登录程序显示的,远程登录是否显示欢迎信息还要看ssh的配置文件/etc/ssh/sshd_config 的 Banner 字段,且/etc/issue.net文件不支持转义字符。
[root@letty-02 Desktop]# cat /etc/issue
\S --\S:操作系统名称
Kernel \r on an \m -\r:操作系统版本 \m硬:件等级
[root@letty-02 Desktop]# cat /etc/issue.net
\S
Kernel \r on an \m
重要日志文件
日志文件保存目录:/var/log/
两个重要日志文件:/var/log/messages和/var/log/secure
/var/log/messages
记录系统或服务程序运行的状态信息和错误信息。
[root@letty-02 Desktop]# tail -n 5 /var/log/messages
Apr 30 07:15:27 letty-02 systemd: Started Hostname Service.
Apr 30 07:18:33 letty-02 systemd: Starting Cleanup of Temporary Directories...
Apr 30 07:18:33 letty-02 systemd: Started Cleanup of Temporary Directories.
Apr 30 07:20:01 letty-02 systemd: Started Session 3 of user root.
Apr 30 07:20:01 letty-02 systemd: Starting Session 3 of user root.
01 02 03 04
- 事件的日期和时间
- 事件的来源主机
- 产生该事件的程序(进程号)
- 实际日志信息
/var/log/secure
记录用户登录信息,可以进行监控文件信息检查是否有过多的失败记录。
[root@letty-02 Desktop]# cat /var/log/secure
Apr 27 18:01:17 localhost sshd[1430]: Server listening on 0.0.0.0 port 22.
Apr 27 18:01:17 localhost sshd[1430]: Server listening on :: port 22.
01 02 03 04
- 01:用户登录时间
- 02:用户登录主机名称
- 03:远程登陆方式
- 04:登录情况说明(正确登录情况说明和错误登录情况说明)