编程网

linux下/srv、/var、/opt、/usr、/tmp的职责划分

/srv :主要用来存储本机或本服务器提供的服务或数据。用户主动生产的数据、对外提供服务

/srv contains site-specific data which is served by this system.

/var :系统产生的不可自动销毁的缓存文件、日志记录。系统和程序运行后产生的数据、不对外提供服务、只能用户手动清理)(包括mail、数据库文件、日志文件)

/var contains variable data files. This includes spool directories and files, administrative and logging data, and transient and temporary files.

Some portions of /var are not shareable between different systems. For instance, /var/log, /var/lock, and /var/run. Other portions may be shared, notably /var/mail, /var/cache/man, /var/cache/fonts, and /var/spool/news.

/var is specified here in order to make it possible to mount /usr read-only. Everything that once went into /usr that is written to during system operation (as opposed to installation and software maintenance) must be in /var.

If /var cannot be made a separate partition, it is often preferable to move /var out of the root partition and into the /usr partition. (This is sometimes done to reduce the size of the root partition or when space runs low in the root partition.) However, /var must not be linked to /usr because this makes separation of /usr and /var more difficult and is likely to create a naming conflict. Instead, link /var to /usr/var.

Applications must generally not add directories to the top level of /var. Such directories should only be added if they have some system-wide implication, and in consultation with the FHS mailing list.

/usr :是Unix System Resource的简写,用于存放系统应用,但是用户的个人文档/资料/工作空间等不应该在这个目录或其子孙级目录;

/usr/local目录一般存放一些系统级的应用(系统级就是指这里的应用不是给某个用户用的可以给多个用户使用权限,类似Windows的Program Files目录),如eclipse/idea/tomcat都可以存放在这里。

注意/opt和/usr/local的区别

/usr/local 可以理解为Program Files,是我们正常安装一些的系统软件如360/mysql数据库之类的,它们的数据是可以在其它目录的,如浏览器的Download目录,数据库的数据库文件目录都可以也应该在其它目录。

/opt放置的是一些第三方程序,它有个特点是它应该是绿色版的(如tar.gz的程序,但不绝对),应用的所有数据均应该在应用目录之内;比如Windows下的hashtool工具/Http接口测试工具/WebService接口测试工具等等(即跟外界几乎无交互的软件,如无需环境变量,无需快捷方式,无需在其它地方配置,那些不需要设置为服务的tomcat也可以放在这里[只是IDE里可能配置],不用了可以直接删除而不需要做后续操作,如删除对应环境变量,删除/etc下的对应配置或/usr/rc.d下的一些配置的应用)。

/tmp :保存在使用完毕后可随时销毁的缓存文件。(有可能是由系统或程序产生、也有可能是用户主动放入的临时数据、系统会自动清理)

The /tmp directory must be made available for programs that require temporary files.

Programs must not assume that any files or directories in /tmp are preserved between invocations of the program.

热门内容