以非root用户身份运行时,Perl模块无法正确加载 [英] Perl modules not loading correctly when running as non-root user

查看:153
本文介绍了以非root用户身份运行时,Perl模块无法正确加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux系统上遇到了Perl的问题。

I'm running into an issue with Perl on a linux system.

在安装新模块(以root用户身份)时,偶尔会遇到如下问题:普通用户,如果不手动输入和chmod 775与模块相关的文件和目录,我将无法访问新模块。

When installing new modules (as root), I would occasionally have issues where running scripts as a regular user, I would not be able to access the new module without manually going in and chmod 775'ing the module related files and directories.

我最近执行了CPAN升级,以及为新项目安装几个模块。现在,由于似乎与权限无关的错误,Perl几乎无法用作普通用户。

I recently performed a CPAN upgrade, as well as installing several modules for a new project. Now, Perl has become almost unusable as a regular user, because of errors that don't appear to be permissions related.

例如,以下非常简单的脚本运行良好作为root用户,但返回以普通用户身份运行的错误:

For example, the following very simple script runs fine as root, but returns an error run as a regular user:

#!/usr/bin/perl
use strict;
use warnings;
use Scalar::Util;

如您所见,脚本实际上不执行任何操作,只是尝试加载Scalar :: Util模块。作为普通用户,它返回以下错误:

As you can see, the script literally does nothing except attempt to load the Scalar::Util module. As a regular user, it returns this error:

**List::Util object version 1.21 does not match bootstrap parameter 1.42 at /usr/lib64/perl5/DynaLoader.pm line 223.
Compilation failed in require at /usr/local/lib64/perl5/Scalar/Util.pm line 22.
Compilation failed in require at ./scalar-test.pl line 4.
BEGIN failed--compilation aborted at ./scalar-test.pl line 4**

当我 sudo cpan 并尝试 install List :: Util 时,我返回:
List :: Util是最新版本(1.42)。

When I sudo cpan and try install List::Util, I get back: List::Util is up to date (1.42).

说明: 这种情况发生在多个模块上,而不仅仅是一个模块例。但是,它似乎并不影响已升级的每个模块;

root可以运行脚本的事实告诉我,要么存在另一个我没有看到的潜在权限问题,要么对于root,PERL的配置与我的普通帐户在某些方面有所不同,这导致它找不到该模块。

The fact that root can run the scripts says to me that either there is another, underlying permissions issue I'm not seeing, OR PERL is configured slightly different in some way for root than my regular account which is causing it not to find this module.

正在搜索List.pm文件:

A search for the List.pm file is returning:

 » sudo find / -name List.pm 

/usr/share/perl5/I18N/LangTags/List.pm
/opt/OV/nonOV/perl/a/lib/5.8.8/I18N/LangTags/List.pm
/root/.cpan/build/perl-5.22.1-D0_eFO/dist/I18N-LangTags/lib/I18N/LangTags/List.pm

 » ls -l /usr/share/perl5/I18N/LangTags/List.pm
-rw-r--r-- 1 root root 28826 Nov  6  2014 /usr/share/perl5/I18N/LangTags/List.pm

 » ls -l /opt/OV/nonOV/perl/a/lib/5.8.8/I18N/LangTags/List.pm
-r--r--r-- 1 bin bin 28826 Nov 30  2012 /opt/OV/nonOV/perl/a/lib/5.8.8/I18N/LangTags/List.pm

 » sudo ls -l /root/.cpan/build/perl-5.22.1-D0_eFO/dist/I18N-LangTags/lib/I18N/LangTags/List.pm
-r--r--r-- 1 1018 513 28826 Oct 17 08:32 /root/.cpan/build/perl-5.22.1-D0_eFO/dist/I18N-LangTags/lib/I18N/LangTags/List.pm

系统为RHEL 6.6 x64,Perl是v5.10.1

System is RHEL 6.6 x64, Perl is v5.10.1

**» type perl**
perl is hashed (/usr/bin/perl)

**» which perl**
/usr/bin/perl 

**» sudo type perl**
sudo: type: command not found 

**» sudo which perl**
/usr/bin/perl

**» echo ${!PERL*}**
[Nothing Returned] 

**» sudo echo ${!PERL*}**
[Nothing Returned]

**» perl -wle 'print join("\n", @INC)'**
/usr/local/lib64/perl5 
/usr/local/share/perl5 
/usr/lib64/perl5/vendor_perl 
/usr/share/perl5/vendor_perl 
/usr/lib64/perl5 
/usr/share/perl5 
[run with sudo returns identical list]

[Edited for brevity] 
cpan[1]> o conf 
$CPAN::Config options from /usr/share/perl5/CPAN/Config.pm: 
build_dir [/root/.cpan/build] 
build_dir_reuse [0] 
build_requires_install_policy [ask/yes] 
connect_to_internet_ok [1] 
cpan_home [/root/.cpan] 
keep_source_where [/root/.cpan/sources] 
make [/usr/bin/make] 
make_install_make_command [/usr/bin/make] 
makepl_arg [INSTALLDIRS=site] 
prefer_installer [MB] 
prefs_dir [/root/.cpan/prefs] 

我从其他用户的文件夹中删除了几行

I redacted a few lines here from other user's folders

 » sudo find / -name Util.pm | grep "List/Util.pm"
/usr/lib64/perl5/List/Util.pm
/usr/local/lib64/perl5/List/Util.pm
/home/{USERNAME REDACTED}/.cpanm/work/1448660183.31550/ExtUtils-MakeMaker-7.10/bundled/Scalar-List-Utils/List/Util.pm
/root/.cpan/build/Scalar-List-Utils-1.42-2c3ONp/lib/List/Util.pm
/root/.cpan/build/Scalar-List-Utils-1.42-2c3ONp/blib/lib/List/Util.pm
/root/.cpan/build/Scalar-List-Utils-1.42-NOwU0A/lib/List/Util.pm
/root/.cpan/build/Scalar-List-Utils-1.42-NOwU0A/blib/lib/List/Util.pm
/root/.cpan/build/perl-5.22.1-D0_eFO/cpan/Scalar-List-Utils/lib/List/Util.pm

根据brian d foy的要求,我安装了一个新模块。该模块Config :: Onion先前未安装,因此没有任何旧问题。该模块安装成功,但是我创建了一个onion-test.pl脚本,与上面相同,并且存在相同的问题,即它仅以根用户身份加载该模块。

Per request of brian d foy, I installed a new module. This module Config::Onion was not previously installed, so nothing old to conflict. The module installs OK, but I created an onion-test.pl script, same as above, and it has the same issue where it only loads the module as root.

 » sudo perl -MConfig::Onion -e 'print "Module: " . $ARGV[0] . "\nVersion: " . $ARGV[0]->VERSION . "\n\n"' Config::Onion
Can't locate Config/Onion.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.

 » sudo cpan
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.10)
Enter 'h' for help.

cpan[1]> install Config::Onion

[Redacted for brevity. No errors noted during this process.]

Result: PASS
  DSHEROH/Config-Onion-1.004.tar.gz
  /usr/bin/make test -- OK
Running make install
Prepending /root/.cpan/build/Config-Onion-1.004-TigyuT/blib/arch /root/.cpan/build/Config-Onion-1.004-TigyuT/blib/lib to PERL5LIB for 'install'
Manifying 2 pod documents
Installing /usr/local/share/perl5/Config/Onion.pm
Installing /usr/local/share/perl5/Config/Onion/Simple.pm
Installing /usr/local/share/man/man3/Config::Onion.3pm
Installing /usr/local/share/man/man3/Config::Onion::Simple.3pm
Appending installation info to /usr/lib64/perl5/perllocal.pod
  DSHEROH/Config-Onion-1.004.tar.gz
  /usr/bin/make install  -- OK

 » cd /usr/local/share/perl5/Config
 » sudo ls -l  Onion
total 4
-r--r--r-- 1 root root 1856 May  9  2014 Simple.pm

 » sudo find / -name Onion.pm
/usr/local/share/perl5/Config/Onion.pm
/root/.cpan/build/Config-Onion-1.004-TigyuT/lib/Config/Onion.pm
/root/.cpan/build/Config-Onion-1.004-TigyuT/blib/lib/Config/Onion.pm


onion-test.pl:

#!/usr/bin/perl
use strict;
use warnings;

use Config::Onion;



 » ./onion-test.pl
Can't locate Hash/Merge/Simple.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /usr/local/share/perl5/Config/Onion.pm line 9.
BEGIN failed--compilation aborted at /usr/local/share/perl5/Config/Onion.pm line 9.
Compilation failed in require at ./onion-test.pl line 29.
BEGIN failed--compilation aborted at ./onion-test.pl line 29.


 » sudo ./onion-test.pl
[No Errors]

每个池上县,我都运行了以下命令:

Per Ikegami, I ran this command:

sudo chmod -R go+rX                   \
   /usr/local/lib64/perl5        \
   /usr/local/share/perl5        \
   /usr/lib64/perl5/vendor_perl  \
   /usr/share/perl5/vendor_perl  \
   /usr/lib64/perl5              \
   /usr/share/perl5 

我的两个测试脚本wi Scalar :: Util和Config :: Onion正在正确加载模块。我认为他的解决方案是解决我遇到的问题的正确方法,并且已相应标记。谢谢大家的研究,也感谢池上提供的解决方案。

Both of my test scripts, with Scalar::Util and Config::Onion are loading the modules without error. I think his solution is the right one for the issue I was having, and I've marked it accordingly. Thanks everyone for your research, and to Ikegami for hitting on the solution.

推荐答案

List / Util / Util.so

List/Util/Util.so probably exists twice in

/usr/local/lib64/perl5 
/usr/local/share/perl5 
/usr/lib64/perl5/vendor_perl 
/usr/share/perl5/vendor_perl 
/usr/lib64/perl5 
/usr/share/perl5 

它们是不同的版本。较新的版本只能由root用户访问。如果这是问题,将使用

They are different versions. The newer one can only be accessed by root. If this is the problem it will be solved using

chmod -R go+rX                   \
   /usr/local/lib64/perl5        \
   /usr/local/share/perl5        \
   /usr/lib64/perl5/vendor_perl  \
   /usr/share/perl5/vendor_perl  \
   /usr/lib64/perl5              \
   /usr/share/perl5 

这篇关于以非root用户身份运行时,Perl模块无法正确加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆