当前位置:首页 > Linux > 正文内容

创建软链接及解决项目内的软链访问报404的问题

canca8年前 (2017-09-16)Linux754

实例:ln -s /home/gamestat    /gamestat

 

linux下的软链接类似于windows下的快捷方式

 

ln -s a b 中的 a 就是源文件,b是链接文件名,其作用是当进入b目录,实际上是链接进入了a目录

如上面的示例,当我们执行命令   cd /gamestat/的时候  实际上是进入了 /home/gamestat/

 

值得注意的是执行命令的时候,应该是a目录已经建立,目录b没有建立。我最开始操作的是也把b目录给建立了,结果就不对了


[root@iZbp1eqd771ku506fyee6yZ storage-sc]# ln -s /data/resource/ueditor ./ueditor
[root@iZbp1eqd771ku506fyee6yZ storage-sc]# ls
config.json  controller.jsp  index.jsp  META-INF  ueditor  WEB-INF
[root@iZbp1eqd771ku506fyee6yZ storage-sc]# cd ueditor/



特别需要说明的是,我们在项目下创建的软链默认是不能被外界访问的,要解决这个问题我们得修改tomcat的配置文件,但是修改之前,我们得先看看我们的tomcat的版本是多少,如下所示,可以看到我使用的tomcat的版本是9.0.0

[root@dev bin]# ./version.sh 
Using CATALINA_BASE:   /root/tomcat/server/storage1
Using CATALINA_HOME:   /root/tomcat/server/storage1
Using CATALINA_TMPDIR: /root/tomcat/server/storage1/temp
Using JRE_HOME:        /home/data/jdk1.8.0_102
Using CLASSPATH:       /root/tomcat/server/storage1/bin/bootstrap.jar:/root/tomcat/server/storage1/bin/tomcat-juli.jar
Server version: Apache Tomcat/9.0.0.M10
Server built:   Aug 31 2016 15:00:21 UTC
Server number:  9.0.0.0
OS Name:        Linux
OS Version:     3.10.0-327.36.3.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_102-b14
JVM Vendor:     Oracle Corporation
[root@dev bin]# 

 下面我们到tomcat下找到context.xml文件,如下所示。
[root@dev storage1]# ls
bin  conf  lib  LICENSE  logs  NOTICE  RELEASE-NOTES  RUNNING.txt  SESSIONS.ser  storage-sc  temp  webapps  work
[root@dev storage1]# cd conf
[root@dev conf]# ls
Catalina  catalina.policy  catalina.properties  context.xml  jaspic-providers.xml  jaspic-providers.xsd  logging.properties  server.xml  tomcat-users.xml  tomcat-users.xsd  web.xml
[root@dev conf]# 

 不同版本的tomcat对context.xml的修改是不一样的,如果是tomcat7及以下版本,那么修改如下,也就是在<Context 后添加了allowLinking="true"这么一句话。
<Context 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="" />
    -->
</Context>

如果是tomcat8及其以上版本的话,修改如下,就是在<Context>的下方添加了 一行<Resources 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="" />
    -->
</Context>



 

删除软链接:

   rm -rf  b  注意不是rm -rf  b/

 

ln  a b 是建立硬链接

建立链接的使用方法如下:

 

 

[root@WEB_YQ_64_79 /]# ln --help

Usage: ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)

  or:  ln [OPTION]... TARGET                  (2nd form)

  or:  ln [OPTION]... TARGET... DIRECTORY     (3rd form)

  or:  ln [OPTION]... -t DIRECTORY TARGET...  (4th form)

In the 1st form, create a link to TARGET with the name LINK_NAME.

In the 2nd form, create a link to TARGET in the current directory.

In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.

Create hard links by default, symbolic links with --symbolic.

When creating hard links, each TARGET must exist.

 

Mandatory arguments to long options are mandatory for short options too.

      --backup[=CONTROL]      make a backup of each existing destination file

  -b                          like --backup but does not accept an argument

  -d, -F, --directory         allow the superuser to attempt to hard link

                                directories (note: will probably fail due to

                                system restrictions, even for the superuser)

  -f, --force                 remove existing destination files

  -n, --no-dereference        treat destination that is a symlink to a

                                directory as if it were a normal file

  -i, --interactive           prompt whether to remove destinations

  -s, --symbolic              make symbolic links instead of hard links

  -S, --suffix=SUFFIX         override the usual backup suffix

  -t, --target-directory=DIRECTORY  specify the DIRECTORY in which to create

                                the links

  -T, --no-target-directory   treat LINK_NAME as a normal file

  -v, --verbose               print name of each file before linking

      --help     display this help and exit

      --version  output version information and exit

 

The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.

The version control method may be selected via the --backup option or through

the VERSION_CONTROL environment variable.  Here are the values:

 

  none, off       never make backups (even if --backup is given)

  numbered, t     make numbered backups

  existing, nil   numbered if numbered backups exist, simple otherwise

  simple, never   always make simple backups

 

Report bugs to .

扫描二维码推送至手机访问。

版权声明:本文由Ant.Master's Blog发布,如需转载请注明出处。

本文链接:https://iant.work/post/13.html

标签: Linux
分享给朋友:

“创建软链接及解决项目内的软链访问报404的问题” 的相关文章

在Linux下安装和使用MySQL

一、引言   想使用Linux已经很长时间了,由于没有硬性任务一直也没有系统学习,近日由于工作需要必须使用Linux下的 MySQL。本以为有Windows下使用SQL Server的经验,觉得在Linux下安装MySql应该是易如反掌的事,可在真正安装和使用MySQL时走了很多弯路,遇见很多问题,...

Linux常用命令集锦

查看所有已安装前缀为samba的RPM包      rpm -qa samba*删除目录或文件   rm -r 文件名linux解压bz2文件使用   bunzip2   linux-2-4-2.tar.bz2 &nbs...

CentOS7安装iptables防火墙

CentOS7默认的防火墙不是iptables,而是firewalle.安装iptable iptable-service#先检查是否安装了iptablesservice iptables status#安装iptablesyum install -y iptables#升级iptable...

centos 7 crontab定时器及开机自启

crontab 建议直接采用centos7 自带得cronteb包,定时器:就是定时去执行干某一件事在这里我以脚本为媒介1 当然是创建一个脚本,创建目录随意但是你一定要记得。。直接通过vi来创建一个test.sh脚本!vi /etc/test.sh编辑脚本内容:#!/bin/bash #...

centos7 手动修改dns

方法一:vim /etc/resolv.conf# Generated by NetworkManager nameserver 114.114.114.114 nameserver 119.29.29.29重启网卡:systemctl ...

debian系统如何搭建 Samba服务器

debian系统如何搭建 Samba服务器

几乎所有的 Linux 发行版都提供了一个很好的工具 Samba来轻松实现文件共享。最近在Nanopi2 上安装了 debian 系统,然后准备搭建Samba 服务器来实现文件的共享,以下步骤仅供参考。1.执行以下指令:apt-get install samba samba-common-bin2....

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。