tomcat软连接配置

一、配置

tomcat配置

修改Tomcat/conf/context.xml文件,在Context节点上添加属性allowLinking=”true”

<Context>
    <Resources allowLinking="true" />
    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    -->

<Loader delegate="true"/>

</Context>

tomcat不同版本context.xml文件配置

7.0及其一下版本 <Context allowLinking="true"></Context>
8.0及其以上版本 <Context > <Resources allowLinking="true" /></Context>

windows系统:

mklink是windows系统下创建符号链接和硬链接的命令工具,它是一个很好的解决文件系统问题的工具。使用它需要管理员权限

mklink
创建符号链接。
mklink [[/D] | [/H] | [/J]] Link Target
/D 创建目录符号链接。默认为文件符号链接。
/H 创建硬链接而非符号链接。
/J 创建目录联接。
Link 指定新的符号链接名称。
Target 指定新链接引用的路径(相对或绝对)。

注意:因为powershell不支持mklink命令,所以要在前面加cmd /c表示用cmd来运行该命令,路径注意引号,可以是相对路径也可以是绝对路径。

目录符号链接目录联接的区别在于:

目录联接在创建时会自动引用目标目录的绝对路径,而符号链接允许相对路径的引用。

如分别用 mklink /D dira tdir 和 mklink /J dirb tdir 创建 dira、dirb 对相对目录的 tdir 的符号链接和目录联接,之后将 dira、dirb 移动到其它目录下,则访问 dira 时会提示“位置不可用”,访问 dirb 时仍然正常指向 tdir;

且win10_x64_build10565的cmd下dir命令查看会发现, dira符号链接链接到的是相对路径下的tdir文件(不管是否存在tdir文件), 且文件类型是symlink, dirb目录联接则链接到绝对(全)路径下的tdir文件, 且文件类型是junction(可能是系统自动把相对路径转换为全路径)

而分别用 mklink /D dira c:\demo\tdir 和 mklink /J dirb c:\demo\tdir 创建 c:\demo\tdir 的符号链接和目录联接,再将这两个目录链接移动到其它目录下,则 dira 和 dirb 均可正常指向 c:\demo\tdir;

例如:

mklink /D  D:\Project\hjiczoom\target\hjiczoom-0.0.1\staticproduct  D:\file\Files\staticproduct

D:\file\Files\staticproduct:文件实际存放位置

D:\Project\hjiczoom\target\hjiczoom-0.0.1\staticproduct:项目访问位置

Linux系统:

ln 命令用于给文件创建链接,根据 Linux 系统存储文件的特点,链接的方式分为以下 2 种:

  • 软链接:类似于 Windows 系统中给文件创建快捷方式,即产生一个特殊的文件,该文件用来指向另一个文件,此链接方式同样适用于目录。
  • 硬链接:我们知道,文件的基本信息都存储在 inode 中,而硬链接指的就是给一个文件的 inode 分配多个文件名,通过任何一个文件名,都可以找到此文件的 inode,从而读取该文件的数据信息。

选项:

-s:建立软链接文件。如果不加 "-s" 选项,则建立硬链接文件;

-f:强制。如果目标文件已经存在,则删除目标文件后再建立链接文件;

例如:

ln -s /Files/staticproduct /www/hjiczoom/staticproduct
/Files/staticproduct:文件实际存放位置

/www/hjiczoom/staticproduct:项目访问位置

linux删除软链接的正确方式

1、创建一个软连接

[root@auc-linux home]# ln -s /usr/hb/ /home/hb_link

 

2、删除软连接出现错误

[root@auc-linux home]# rm /home/hb_link/

rm: 无法删除"/home/hb_link/": 是一个目录

 

3、删除软连接的正确方式

[root@auc-linux home]# rm /home/hb_link/

rm: 无法删除"/home/hb_link/": 是一个目录

[root@auc-linux home]# rm /home/hb_link

rm:是否删除符号链接 "/home/hb_link"?y

 

4、只是删除了软连接文件(正确方式)

[root@auc-linux home]# rm -rf /home/hb_link

[root@auc-linux home]# ll /usr/hb/

总用量 4

-rw-r--r-- 1 root root 12 6月   4 18:09 hb.txt

 

5、错误操作,通过软连接删除了实际存在的数据。

[root@auc-linux home]# ln -s /usr/hb /home/hb_link

[root@auc-linux home]# ls

1234.cap  freeswitch.bin  logs        monitor      packages.tar.gz  www

Adtec     hb_link         lost+found  monitor_log  recordings

[root@auc-linux home]# rm -rf /home/hb_link/

[root@auc-linux home]# ls

1234.cap  freeswitch.bin  logs        monitor      packages.tar.gz  www

Adtec     hb_link         lost+found  monitor_log  recordings

[root@auc-linux home]# cd hb_link/

[root@auc-linux hb_link]# ls

[root@auc-linux hb_link]# cd /usr/hb/

[root@auc-linux hb]# ls

折叠

备注:想要删除链接文件要用以下命令 rm /home/hb_link 只是少了一个“ / ” 删除的 就是链接文件, 也就是在文件名的最后不要加上/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值