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

来源:互联网 发布:网络市场调研的程序 编辑:程序博客网 时间:2024/05/16 10:30

实例: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 <bug-coreutils@gnu.org>.

0 0
原创粉丝点击