19. Cloud computing & big data _linux basics (18) What is linux_Linux directory configuration

Linux directory configuration according --FHS

Because the development community to use the product or distributions of Linux / companies and individuals too much, if everyone is to place the configuration file directory with their own ideas, it will likely cause a lot of problems in management. Can you imagine, after you enter a business, the exposure to the Linux directory configuration even tell you've learned completely different, so, then there is the so-called Filesystem Hierarchy Standard (FHS) standard baked!

According to FHS ( http://www.pathname.com/fhs/ ) official document states that their main purpose is to allow users to understand the installed software is usually placed in that directory, so they want an independent software development business, operating system makers, as well as the user wants to maintain the system, we are able to follow the standard of FHS. In other words, FHS focus is under the specification for each specific directory data should look like you want to place it. So good at very much, because the Linux operating system will be able to (change directory schema) in the face of existing developers want to develop a unique style.

Indeed, FHS is based on past experience has been continued for the revision, FHS based file system used frequently or not and whether to allow the user to freely modifiers, and the directory defined to form four kinds of interaction, a table for a bit like the bottom of this:

  Shareable (shareable) Not sharing (unshareable)
Constant (static) / Usr (software stored) / Etc (profile)
  / Opt (third-party software in conjunction) / Boot (boot and core files)
Can change (variable) / Var / mail (mail box user) / Var / run (application dependent)
  / Var / spool / news (newsgroups) / Var / lock (application dependent)

Directory is on the table some representative directory, under the directory is placed under the data to the talks, where the first skip the talk. We want to know is, what is the four types?

  • Shareable: other systems can share directory mount use, so execution file including the user data such as e-mail, to be able to share the directory on the network used to mount other hosts;

  • Can not share: the operation of their machines with the above devices file or program-related socket files, and since only about their own machine, so of course is not suitable for other hosts to share a.

  • Unchanged: Some data is not constantly changing, followed by distribution without changes. Such as libraries, documentation file, the system administrator managed hosting services configuration file, and so on;

  • Can change: constantly changing data, such as the log file, the general user can accept the newsgroups.

Indeed, FHS directory tree for a three-tier architecture only defines what data should be placed under the catalog only, which are defined under three directories:

  • / (Root, root): related to boot the system;
  • / Usr (unix software resource): software installation and / enforcing;
  • / Var (variable): related to the operation of the process system.

Root directory (/) the meaning and content:

The root directory is the most important one of the whole system, not only because all directories are derived from the root directory and the root directory of the boot also with / restore / repair systems and other related actions. Because the software requires specific boot system boot, the core file, start the necessary procedures, libraries, etc. file data, if a system error occurs, the root directory must also include a program to repair the file system of the job. Because the root directory is so important, so the requirements of the FHS, he hopes not on the root of a very large tank division, because the larger the dividing groove u will put more and more data, this way lies the root directory the dividing groove may have more chance of error occurred.

Therefore, the FHS recommendations: root directory (/) where the dividing groove should be as small as possible, and the software applications installed it is best not placed in the same division with the root of the tank, keeping the root of the smaller the better. So not only better performance, the root directory where the file system is also less prone to problems.

In view of the above description, so FHS defines a root directory (/) under the presence of views should have under these directories go:

table of Contents Contents of the file should be placed
/bin There are many systems perform file directory placement, but the / bin special. Since / bin is placed under the single instruction maintenance mode it can also be operated. In / bin under the instruction can be used with the root account the general, mainly: cat, chmod, chown, date , mv, mkdir, cp, bash like commonly used commands.
/boot This file is placed in the main directory open opportunities to use, including the Linux kernel and the boot menu and boot files required configuration file, and so on. Linux kernel commonly used file named: vmlinuz, if you are using the grub boot manager, you will continue to exist / boot / grub / directory Oh!
/dev On Linux system, any device with an interface to the device patterns are present in the directory file among. As long as you have access to this through a file directory under, it means access to a device than Hello ~ important documents have to / dev / null, / dev / zero, / dev / tty, / dev / lp *, / dev / hd *, / dev / sd * , etc.
/etc The main system configuration files are placed almost in the directory, for example, account password file personnel of various services starting stalls, and so on. In general, the properties of each file in this directory is that it gives access to the general user, but only root has the power to modify. FHS is not recommended to place the executable (binary) Oh this directory. There are more important documents:  / etc / inittab, /etc/init.d/, the /etc/modprobe.conf, / etc / X11 /, / etc / fstab, / etc / sysconfig / etc. In addition, under its important directories are:
  • /etc/init.d/: pre-start script all services are placed here, for example, to enable or disable iptables words: "/etc/init.d/iptables start", "/ etc / init.d / iptables stop "
  • /etc/xinetd.d/: This is the profile directory of services so-called super daemon management.
  • / Etc / X11 /: X Window associated with the various configuration files are in here, especially this xorg.conf X Server configuration file.
/home This is the default user's home directory (home directory). When you add a regular user account, the default user's home directory will be standardized to be here. More important is that the code Oh, there are two home directory:
~: This represents the current user's home directory,
~ dmtsai: dmtsai represents the home directory!
/lib Very many library systems, and / lib is placed in the boot will be used in libraries, and libraries in / bin or / sbin under the directive would call it. What is the library it? U He can be thought of as "plug-in", some of these instructions must have "plug-in" was intended to complete the implementation of the program smoothly. Of particular importance is / lib / modules / directory because the directory will be placed related to the core module (driver) Oh!
/media media is "media" in English, as the name suggests, this under the media is placed in the device / removable friends! Including floppy disks, CD-ROM, DVD device, etc. are temporarily mounted here. Common file name there: / media / floppy, / media / cdrom and so on.
/ mnt If u want some additional means for temporarily mount, general recommendations u can be placed into this directory. In the old days, when the purpose of this directory / media the same as it! With only / after the media, this directory is used to temporarily mount use.
/opt 这个是给第三方协力软件放置的目录。什么是第三方协力软件啊? 举例来说,KDE这个桌面管理系统是一个独立的计划,不过他可以安装到Linux系统中,因此KDE的软件就建议放置到此目录下了。 另外,如果妳想要自行安装额外的软件(非原本的distribution提供的),那么也能够将你的软件安装到这里来。 不过,以前的Linux系统中,我们还是习惯放置在/usr/local目录下呢!
/root 系统管理员(root)的家目录。之所以放在这里,是因为如果进入单人维护模式而仅挂载根目录时, 该目录就能够拥有root的家目录,所以我们会希望root的家目录与根目录放置在同一个分割槽中。
/sbin Linux有非常多指令是用来设定系统环境的,这些指令只有root才能够利用来『设定』系统,其他用户最多只能用来『查询』而已。 放在/sbin底下的为开机过程中所需要的,里面包括了开机、修复、还原系统所需要的指令。 至于某些服务器软件程序,一般则放置到/usr/sbin/当中。至于本机自行安装的软件所产生的系统执行文件(system binary), 则放置到/usr/local/sbin/当中了。常见的指令包括:fdisk, fsck, ifconfig, init, mkfs等等。
/srv srv可以视为『service』的缩写,是一些网络服务启动之后,这些服务所需要取用的数据目录。 常见的服务例如WWW, FTP等等。举例来说,WWW服务器需要的网页数据就可以放置在/srv/www/里面。
/tmp 这是让一般使用者或者是正在执行的程序暂时放置文件的地方。 这个目录是任何人都能够存取的,所以你需要定期的清理一下。当然,重要数据不可放置在此目录啊! 因为FHS甚至建议在开机时,应该要将/tmp下的数据都删除唷!

事实上FHS针对根目录所定义的标准就仅有上面的,不过我们的Linux底下还有许多目录你也需要了解一下的。 底下是几个在Linux当中也是非常重要的目录喔:

目录 应放置文件内容
/lost+found 这个目录是使用标准的ext2/ext3文件系统格式才会产生的一个目录,目的在于当文件系统发生错误时, 将一些遗失的片段放置到这个目录下。这个目录通常会在分割槽的最顶层存在, 例如你加装一颗硬盘于/disk中,那在这个系统下就会自动产生一个这样的目录『/disk/lost+found』
/proc 这个目录本身是一个『虚拟文件系统(virtual filesystem)』喔!他放置的数据都是在内存当中, 例如系统核心、行程信息(process)、周边装置的状态及网络状态等等。因为这个目录下的数据都是在内存当中, 所以本身不占任何硬盘空间啊!比较重要的文件例如:/proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net/* 等等。
/sys 这个目录其实跟/proc非常类似,也是一个虚拟的文件系统,主要也是记录与核心相关的信息。 包括目前已加载的核心模块与核心侦测到的硬件装置信息等等。这个目录同样不占硬盘容量喔!

除了这些目录的内容之外,另外要注意的是,因为根目录与开机有关,开机过程中仅有根目录会被挂载, 其他分割槽则是在开机完成之后才会持续的进行挂载的行为。就是因为如此,因此根目录下与开机过程有关的目录, 就不能够与根目录放到不同的分割槽去!那哪些目录不可与根目录分开呢?有底下这些:

  • /etc:配置文件
  • /bin:重要执行档
  • /dev:所需要的装置文件
  • /lib:执行档所需的函式库与核心所需的模块
  • /sbin:重要的系统执行文件

这五个目录千万不可与根目录分开在不同的分割槽!请背下来啊! 好了,谈完了根目录,接下来我们就来谈谈/usr以及/var!先看/usr里面有些什么东西:

 

/usr 的意义与内容:

依据FHS的基本定义,/usr里面放置的数据属于可分享的与不可变动的(shareable, static), 如果你知道如何透过网络进行分割槽的挂载(例如在服务器篇会谈到的NFS服务器),那么/usr确实可以分享给局域网络内的其他主机来使用喔!

很多读者都会误会/usr为user的缩写,其实usr是Unix Software Resource的缩写, 也就是『Unix操作系统软件资源』所放置的目录,而不是用户的数据啦!这点要注意。 FHS建议所有软件开发者,应该将他们的数据合理的分别放置到这个目录下的次目录,而不要自行建立该软件自己独立的目录。

因为是所有系统默认的软件(distribution发布者提供的软件)都会放置到/usr底下,因此这个目录有点类似Windows 系统的『C:\Windows\ + C:\Program files\』这两个目录的综合体,系统刚安装完毕时,这个目录会占用最多的硬盘容量。 一般来说,/usr的次目录建议有底下这些:

目录 应放置文件内容
/usr/X11R6/ 为X Window System重要数据所放置的目录,之所以取名为X11R6是因为最后的X版本为第11版,且该版的第6次释出之意。
/usr/bin/ 绝大部分的用户可使用指令都放在这里!请注意到他与/bin的不同之处。(是否与开机过程有关)
/usr/include/ c/c++等程序语言的档头(header)与包含档(include)放置处,当我们以tarball方式 (*.tar.gz 的方式安装软件)安装某些数据时,会使用到里头的许多包含档喔!
/usr/lib/ 包含各应用软件的函式库、目标文件(object file),以及不被一般使用者惯用的执行档或脚本(script)。 某些软件会提供一些特殊的指令来进行服务器的设定,这些指令也不会经常被系统管理员操作, 那就会被摆放到这个目录下啦。要注意的是,如果你使用的是X86_64的Linux系统, 那可能会有/usr/lib64/目录产生喔!
/usr/local/ 系统管理员在本机自行安装自己下载的软件(非distribution默认提供者),建议安装到此目录, 这样会比较便于管理。举例来说,你的distribution提供的软件较旧,你想安装较新的软件但又不想移除旧版, 此时你可以将新版软件安装于/usr/local/目录下,可与原先的旧版软件有分别啦! 你可以自行到/usr/local去看看,该目录下也是具有bin, etc, include, lib...的次目录喔!
/usr/sbin/ 非系统正常运作所需要的系统指令。最常见的就是某些网络服务器软件的服务指令(daemon)啰!
/usr/share/ 放置共享文件的地方,在这个目录下放置的数据几乎是不分硬件架构均可读取的数据, 因为几乎都是文本文件嘛!在此目录下常见的还有这些次目录:
  • /usr/share/man:联机帮助文件
  • /usr/share/doc:软件杂项的文件说明
  • /usr/share/zoneinfo:与时区有关的时区文件
/usr/src/ 一般原始码建议放置到这里,src有source的意思。至于核心原始码则建议放置到/usr/src/linux/目录下。

 

/var 的意义与内容:

如果/usr是安装时会占用较大硬盘容量的目录,那么/var就是在系统运作后才会渐渐占用硬盘容量的目录。 因为/var目录主要针对常态性变动的文件,包括缓存(cache)、登录档(log file)以及某些软件运作所产生的文件, 包括程序文件(lock file, run file),或者例如MySQL数据库的文件等等。常见的次目录有:

目录 应放置文件内容
/var/cache/ 应用程序本身运作过程中会产生的一些暂存档;
/var/lib/ 程序本身执行的过程中,需要使用到的数据文件放置的目录。在此目录下各自的软件应该要有各自的目录。 举例来说,MySQL的数据库放置到/var/lib/mysql/而rpm的数据库则放到/var/lib/rpm去!
/var/lock/ 某些装置或者是文件资源一次只能被一个应用程序所使用,如果同时有两个程序使用该装置时, 就可能产生一些错误的状况,因此就得要将该装置上锁(lock),以确保该装置只会给单一软件所使用。 举例来说,刻录机正在刻录一块光盘,你想一下,会不会有两个人同时在使用一个刻录机烧片? 如果两个人同时刻录,那片子写入的是谁的数据?所以当第一个人在刻录时该刻录机就会被上锁, 第二个人就得要该装置被解除锁定(就是前一个人用完了)才能够继续使用啰。
/var/log/ 重要到不行!这是登录文件放置的目录!里面比较重要的文件如/var/log/messages, /var/log/wtmp(记录登入者的信息)等。
/var/mail/ 放置个人电子邮件信箱的目录,不过这个目录也被放置到/var/spool/mail/目录中! 通常这两个目录是互为链接文件啦!
/var/run/ 某些程序或者是服务启动后,会将他们的PID放置在这个目录下喔! 至于PID的意义我们会在后续章节提到的。
/var/spool/ 这个目录通常放置一些队列数据,所谓的『队列』就是排队等待其他程序使用的数据啦! 这些数据被使用后通常都会被删除。举例来说,系统收到新信会放置到/var/spool/mail/中, 但使用者收下该信件后该封信原则上就会被删除。信件如果暂时寄不出去会被放到/var/spool/mqueue/中, 等到被送出后就被删除。如果是工作排程数据(crontab),就会被放置到/var/spool/cron/目录中!

 

目录树(directory tree)

是所有目录与文件的源头~ 然后再一个一个的分支下来,有点像是树枝状啊~因此,我们也称这种目录配置方式为:『目录树(directory tree)』 这个目录树有什么特性呢?他主要的特性有:

  • 目录树的启始点为根目录 (/, root);
  • 每一个目录不止能使用本地端的 partition 的文件系统,也可以使用网络上的 filesystem 。举例来说, 可以利用 Network File System (NFS) 服务器挂载某特定目录等。
  • 每一个文件在此目录树中的文件名(包含完整路径)都是独一无二的。

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zhimahu/p/11834131.html