由于环境限制,需要安装的机器不可以上网,如果可以连网,请参考官网文档,以下所有操作都是root(如果没有root,编译的时候需要有一些修改),OS:suse11sp2,其实大部分linux应该都可以。
主要是Net::SSH2模块安装起来很坑,,依赖 libssh2,openssl,zlib ,自己FTP上去编译了一堆,还得参考一些不完全正确的中文blog,还是英文的靠谱一些,ln 一些 动态链接库,最后手动把老的libssh2卸载,安装Net::OpenSSH就没这么多问题。
1.perl 5.10.1(假设已安装)
3.libssh2、openssl、zlib、expat源码
3.Rex模块及依赖的包
如果能连网 用yum
、apt-get
或者zypper
,下载相应的包和devel包会很方便,当然编译是通吃的。
编译expat
cd
test -f installed/expat-2.0.1.tar.gz && mv installed/expat-2.0.1.tar.gz .
test ! -f expat-2.0.1.tar.gz && wget http://download.sf.net/expat/expat-2.0.1.tar.gz
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "expat-*" -exec rm -r {} \;
tar xzvf ~/expat-2.0.1.tar.gz
cd expat-2.0.1
test $UID = 0 && chown -R root:root .
./configure --prefix=/usr
make
rm -f /usr/lib/libexpat.*
make install
ldconfig
# I had to create a .0 symlink for Firefox
ln -s /usr/lib/libexpat.so /usr/lib/libexpat.so.0
cd
mkdir -p -m 0700 installed
rm -f installed/expat-*.tar.*
mv expat-2.0.1.tar.gz installed/
编译openssl
cd
test -f installed/openssl-1.0.1g.tar.gz && mv installed/openssl-1.0.1g.tar.gz .
test ! -f openssl-1.0.1g.tar.gz && wget http://openssl.org/source/openssl-1.0.1g.tar.gz
# Verify tarball w/ md5sum:
echo "de62b43dfcd858e66a74bee1c834e959 openssl-1.0.1g.tar.gz" | md5sum -c
# Extract it
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "openssl-*" -exec rm -r {} \;
tar xzvf ~/openssl-1.0.1g.tar.gz
cd openssl-1.0.1g
test $UID = 0 && chown -R root:root .
## Configure and then build it
# If you're low on time, or this is a re-build, skip 'make test'
# You can install it where Slackware does by passing --prefix=/usr
# and --openssldir=/etc/ssl to configure
# Configure it, here using /usr/local/ssl/lib64 for 64-bit systems,
# /usr/local/ssl/lib otherwise
test $(uname -m) = "x86_64" && ./config shared --libdir=lib64
test $(uname -m) != "x86_64" && ./config shared
# Build it
make
# Test the build
make test
# If you have an old distribution-installed OpenSSL with a /etc/ssl
# configuration directory, back that up and remove it
test -d /etc/ssl &&
( mkdir -p -m 0700 ~/backup/ssl
cp -a /etc/ssl/* ~/backup/ssl/
rm -r /etc/ssl )
# Install the new version
make install
# Make sure the libraries are visible, use /usr/local/ssl/lib64 for 64-bit
# systems, /usr/local/ssl/lib otherwise
FOO=lib
test $(uname -m) = "x86_64" && FOO=lib64
( cd /usr/local/ssl/${FOO}
ln -sf libcrypto.so.1.0.0 libcrypto.so.1
ln -sf libssl.so.1.0.0 libssl.so.1
egrep -q "^/usr/local/ssl/${FOO}$" /etc/ld.so.conf ||
echo "/usr/local/ssl/${FOO}" >> /etc/ld.so.conf )
ldconfig
unset FOO
# If you upgraded from a 0.x.x version to a 1.x.x one, you may find
# old libssl.so.0.x.x shared library files in /usr/local/ssl/lib. You
# might want to leave them there because there are probably many things
# linked to them.
# Make sure your non-root user can remove the source later
chown -R $(logname) .
chmod -R u+w .
# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/openssl-*.tar.*
mv openssl-1.0.1g.tar.gz installed/
编译zlib
# Get it
cd
test -f installed/zlib-1.2.8.tar.xz && mv installed/zlib-1.2.8.tar.xz .
test ! -f zlib-1.2.8.tar.xz && wget http://zlib.net/zlib-1.2.8.tar.xz
# Verify tarball w/ md5sum:
echo "28f1205d8dd2001f26fec1e8c2cebe37 zlib-1.2.8.tar.xz" | md5sum -c
# Extract the source
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "zlib-*" -exec rm -r {} \;
tar xJvf ~/zlib-1.2.8.tar.xz
cd zlib-1.2.8
test $UID = 0 && chown -R root:root .
## configure the build
# 64-bit systems:
test $(uname -m) = "x86_64" &&
./configure --prefix=/usr --libdir=/usr/lib64 --sharedlibdir=/lib64
# Non-64-bit systems:
test $(uname -m) = "x86_64" || ./configure --prefix=/usr --sharedlibdir=/lib
# Build it
make
# Test the build
make test
test -d /lib64 && ( cd /lib64 ; rm -f libz.so.1 libz.so )
test -d /usr/lib64 && ( cd /usr/lib64 ; rm -f libz.so.1 libz.so )
test -d /lib && ( cd /lib ; rm -f libz.so.1 libz.so )
test -d /usr/lib && ( cd /usr/lib ; rm -f libz.so.1 libz.so )
# Install the new version. It will install static (.a) and shared (.so)
# versions of libz. The default base man directory is /usr/share/man,
# which in Slackware is usually either not there or a symlink to /usr/man.
make install mandir=/usr/man
# Now create symlinks in /usr/lib*/ pointing to the real one in /lib*/:
test -f /lib64/libz.so.1.2.8 &&
( ln -sf /lib64/libz.so.1.2.8 /usr/lib64/libz.so.1.2.8
ln -sf /lib64/libz.so.1.2.8 /usr/lib64/libz.so.1
ln -sf /lib64/libz.so.1.2.8 /usr/lib64/libz.so )
test -f /lib/libz.so.1.2.8 &&
( ln -sf /lib/libz.so.1.2.8 /usr/lib/libz.so.1.2.8
ln -sf /lib/libz.so.1.2.8 /usr/lib/libz.so.1
ln -sf /lib/libz.so.1.2.8 /usr/lib/libz.so )
# Update /etc/ld.so.cache
ldconfig
find /usr/doc -maxdepth 1 -type d -name "zlib-*" -exec rm -r {} \;
mkdir -p /usr/doc/zlib-1.2.8
cp ChangeLog FAQ INDEX README /usr/doc/zlib-1.2.8/
chown -R root:root /usr/doc/zlib-1.2.8
chown -R $(logname) .
chmod -R u+w .
# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/zlib-*.tar.* installed/zlib-*patch*.txt
mv zlib-1.2.8.tar.xz installed/
编译libssh2
# Get it
cd
test -f installed/libssh2-1.4.3.tar.gz &&
mv installed/libssh2-1.4.3.tar.gz .
test ! -f libssh2-1.4.3.tar.gz &&
wget http://www.libssh2.org/download/libssh2-1.4.3.tar.gz
# Extract the source
mkdir -p -m 0700 src
cd src
find -maxdepth 1 -type d -name "libssh2-*" -exec rm -r {} \;
tar xzvf ~/libssh2-1.4.3.tar.gz
cd libssh2-1.4.3
test $UID = 0 && chown -R root:root .
# Configure the build - 64-bit
test $(uname -m) = "x86_64" &&
./configure --mandir=/usr/local/man --with-libssl-prefix=/usr/local/ssl \
--libdir=/usr/local/lib64
# Configure the build - anything else
test $(uname -m) != "x86_64" &&
./configure --mandir=/usr/local/man --with-libssl-prefix=/usr/local/ssl
# Build it
make
# Install it
make install
ldconfig
# Make sure your non-root user can remove the source later
chown -R $(logname) .
chmod -R u+w .
# Save the source for later
cd
mkdir -p -m 0700 installed
rm -f installed/libssh2-*.tar.*
mv libssh2-1.4.3.tar.gz installed/
# add by shalk
ln -s /usr/local/lib64/libssh2.so.1.0.* /usr/lib64/libssh2.so.1
# If you ever want to uninstall libssh2, this should do it:
#cd
#test -d src/libssh2-* && ( cd src/libssh2-* ; make uninstall )
#for pfx in /usr /usr/local;
#do
# ( cd ${pfx}/include
# rm -f libssh2.h libssh2_sftp.h libssh2_publickey.h )
# rm -f ${pfx}/lib/libssh2.* ${pfx}/man/man3/libssh2_* \
# ${pfx}/share/man/man3/libssh2_* ${pfx}/lib/pkgconfig/libssh2.pc
# test -d ${pfx}/lib64 &&
# rm -f ${pfx}/lib64/libssh2.* ${pfx}/lib64/pkgconfig/libssh2.pc
#done
#ldconfig
#
#find ~/src -maxdepth 1 -type d -name "libssh2-*" -exec rm -r {} \;
#rm -f ~/installed/libssh2-*.tar.*
至此,openssl,expat,zlib,libssh2就安装好了,主要是他们的动态链接库都可以找到,并且覆盖掉老版本的就好。 为此我卸载了版本的libssh2rpm -e libssh2-1-0.19.0+20080814-2.16.1 --nodeps
其实只要ln -s /usr/local/lib64/libssh2.so.1.0.* /usr/lib64/libssh2.so.1
就OK了 因为那个包 只提供了两个文件,用rpm -ql
可以查看到。
感谢 jason的howto 提供的编译代码
下载cpanm
#下载了一个单独的cpanm 可执行文件
curl -LO http://xrl.us/cpanm
先下载Rex所有的依赖包到dists目录
cpanm -L /dev/null --save-dists dists --scandep Rex
生成索引
cpanm OrePAN
#disks的绝对路径
orepan_index.pl --repository=/home/path/dists/
#生成的文件为
/home/path/dists/module/02packages.details.txt.gz
可以将dists目录都copy走。
上传cpanm和dists目录
chmod a+x cpanm
cp cpanm /usr/bin/
# 从dists目录读依赖包,安装到/usr/local/rex/目录下,安装Rex模块
cpanm --mirror-only --mirror file:///root/dists/ -L /usr/local/rex/ Rex
#检验模块都OK
perl -MYAML -I/usr/local/rex/lib/perl5/ -e "1"
perl -MDBI -I/usr/local/rex/lib/perl5/ -e "1"
perl -MLWP -I/usr/local/rex/lib/perl5/ -e "1"
perl -MJSON::XS -I/usr/local/rex/lib/perl5/ -e "1"
perl -MXML::Simple -I/usr/local/rex/lib/perl5/ -e "1"
perl -MString::Escape -I/usr/local/rex/lib/perl5/ -e "1"
perl -MRex -I/usr/local/rex/lib/perl5/ -e "1"
#加入环境变量,可以加到.bashrc里
export PATH=$PATH:/usr/local/rex/bin/
export PERL5LIB=/usr/local/rex/lib/perl5/
mkdir -p projects/my-first-rex-project
cd projects/my-first-rex-project
vim Rexfile
#Rexfile
user "root";
password "111111";
pass_auth;
group myserver => "127.0.0.1";
desc "get the uptime of all server";
task "uptime",group => "myserver",sub{
my $output = run "uptime";
say $output;
};
rex uptime
linux:~/projects/my-first-rex-project # rex uptime
[2014-05-16 13:17:46] INFO - Running task uptime on 127.0.0.1
[2014-05-16 13:17:46] INFO - Connecting to 127.0.0.1:22 (root)
[2014-05-16 13:17:46] INFO - Connected to 127.0.0.1, trying to authenticate.
[2014-05-16 13:17:46] INFO - Successfully authenticated on 127.0.0.1.
13:17pm up 3:07, 4 users, load average: 0.01, 0.02, 0.05
[2014-05-16 13:17:47] INFO - Exiting Rex...
[2014-05-16 13:17:47] INFO - Cleaning up...
成功
以后就方便了,把需要用到的打包上传,相关下载 提取密码:o7n7
如果在一台内网机器需要安装
#上传到安装的节点
tar -zvxf rex_all.tar.gz
cd rex_all
sh install.sh
#等待编译完成 执行
cpanm --mirror-only --mirror file:///root/dists/ -L /usr/local/rex/ Rex