ansible安装碰到的问题

    我不会说换了十个版本的openssl,换了三个版本的python,最后还是换操作系统搞定的!!!

无敌邓超 - 无敌

1、 前言

在进行安装ansible的时候,开始安装的操作系统版本为RHEL6.2,但是怎么也不能安装上,走了很多的弯路,从而在此进行记录。

2、 安装openssl

2.1 系统环境

       系统环境如下所示:

[root@RHAN ~]#cat /etc/redhat-release 操作系统版本

Red HatEnterprise Linux Server release 6.2 (Santiago)

[root@RHAN ~]#rpm -qa opensslopenssl版本

openssl-1.0.0-20.el6.x86_64

[root@RHAN ~]#python -Vpython版本

Python 2.6.6

       在此主要查看的是pythonopenssl的版本,因为在安装ansible的时候,会安装依赖模块cryptography,而模块cryptography依赖于操作系统的openssl的版本,一般的cryptography的不支持openssl1.0.0版本,从而需要对openssl进行升级,如果使用系统自带的opensslopenssl-devel,那么是无法安装模块cryptography,从而无法安装ansible

2.2 源码编译openssl

       在进行源码编译openssl的时候,需要注意的是,官方上面的安装手册可能无法适用于任何操作系统,从而使用如下的参数进行安装:

[root@RHAN ~]#tar -xf openssl-1.1.0d.tar.gz解压

[root@RHAN ~]#cd openssl-1.1.0d

[[email protected]]# ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl  -fPIC shared 编译,安装的目录为ssl,并且openssl的目录页是ssl,同时创建共享库和静态库

[[email protected]]# make && make install 安装

[root@RHAN ~]#ls -l /usr/local/ssl/安装目录下的文件

total 52

drwxr-xr-x. 2root root  4096 Feb  6 12:22 bin

drwxr-xr-x. 2root root  4096 Feb  6 12:22 certs

drwxr-xr-x. 3root root  4096 Feb  6 12:22 include

drwxr-xr-x. 4root root  4096 Feb  6 12:22 lib

drwxr-xr-x. 2root root  4096 Feb  6 12:22 misc

-rw-r--r--. 1root root 10771 Feb  6 12:22 openssl.cnf

-rw-r--r--. 1root root 10771 Feb  6 12:22openssl.cnf.dist

drwxr-xr-x. 2root root  4096 Feb  6 12:22 private

drwxr-xr-x. 4root root  4096 Feb  6 12:24 share

[root@RHAN ~]#cd /usr/local/ssl/bin/ 查看openssl的版本

[root@RHAN bin]#./openssl versionopenssl无法正确运行,无法加载共享类库

./openssl: error while loading shared libraries: libssl.so.1.1:cannot open shared object file: No such file or directory

[root@RHAN lib]#pwd

/usr/local/ssl/lib

[root@RHAN lib]#echo `pwd`>/etc/ld.so.conf.d/openssl.conf 设置openssl的类库路径

[root@RHAN lib]#ldconfig让类库路径生效

[root@RHAN lib]#../bin/openssl version 查看openssl的版本

OpenSSL1.1.0d  26 Jan 2017

       不要将新安装的包拷贝到/usr/lib64/中,否则sshd无法启动,如下所示:

 [root@RHAN lib]# ls -l /usr/lib64/openssl/ 老版本的openssl的类库文件,存在的路径为/usr/lib64/

total 4

drwxr-xr-x. 2root root 4096 Jan 24 09:23 engines

[root@RHAN lib]#cp * /usr/lib64/将新安装的openssl类库文件拷贝,发现sshd直接断开,或者是sshd服务无法启动

cp: omittingdirectory `engines-1.1'

cp: overwrite`/usr/lib64/libcrypto.so'? y

Connectionclosed by foreign host.

       登录系统查看的时候发现,sshd无法启动:

图片

       在一般的安装步骤中,是没有此项拷贝的,也就是说无需将lib文件拷贝到/usr目录中,主要是在安装ansible的时候,查找的类库路径为此目录,那么拷贝openssl到此目录中,和老版本的openssl冲突,从而导致sshd无法启动。

       在一般的安装完成之后,需要将相关的头文件做成软连接,如下所示(不做):

[root@RHAN ~]#ln -s /usr/local/ssl/include/openssl/ /usr/include/openssl头文件链接

       在此目录下,是存在老版本的openssl头文件,从而需要进行链接,否则也没啥太大用处,主要在后面进行安装python或者其他的时候,指定查找openssl的路径。

源码安装python

       在进行源码安装python的时候,查看openssl版本:

[root@RHAN~]#  python -c "import ssl; printssl.OPENSSL_VERSION" 查看是否使用新安装的openssl

OpenSSL1.1.0d  26 Jan 2017

3.1 configure出现告警

       在进行configure的时候,出现告警如下(可以直接无视,出现告警也是直接可以正常进行):

checking for--with-cxx-main=<compiler>... no

checking forg++... no

configure:WARNING:

 

  By default, distutilswill build C++ extension modules with "g++".

  If this is not intended, then set CXX on theconfigure command line.

       主要是没有指定的编译器,从而可以用如下的方式来进行指定:

[[email protected]]#./configure --prefix=/usr/local/python --with-cxx-main=/usr/bin/gcc指定编译器来进行编译

3.2 make的时候出现无法编译ssl模块

       make的时候,出现错误如下:

Failedto build these modules:

_hashlib           _ssl 

[[email protected]]# ls -l Modules/Setup.dist (配置文件)

-rw-r--r--. 11000 1000 18479 Dec 17 15:05 Modules/Setup.dist

214 #_socketsocketmodule.c timemodule.c取消注释

215

216 # Socketmodule helper for SSL support; you must comment out the other

217 # socketline above, and possibly edit the SSL variable:

218#SSL=/usr/local/ssl取消注释安装的最新版本的openssl路径

219 #_ssl _ssl.c\取消注释

220 #       -DUSE_SSL -I$(SSL)/include-I$(SSL)/include/openssl \取消注释

221 #       -L$(SSL)/lib -lssl -lcrypto取消注释

       修改之后如下所示:

214 _socketsocketmodule.c timemodule.c

215

216 # Socketmodule helper for SSL support; you must comment out the other

217 # socketline above, and possibly edit the SSL variable:

218SSL=/usr/local/ssl

219 _ssl _ssl.c\

220         -DUSE_SSL -I$(SSL)/include-I$(SSL)/include/openssl \

221         -L$(SSL)/lib -lssl -lcrypto

       主要是用来指定openssl类库的路径,从而能成功安装ssl等模块。

4 安装ansible

4.1 安装cryptography出错

       在安装cryptography的时候,出现错误如下:

creating build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7

    gcc-pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall-Wstrict-prototypes -fPIC -I/usr/local/python/include/python2.7 -c build/temp.linux-x86_64-2.7/_openssl.c -obuild/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o

   build/temp.linux-x86_64-2.7/_openssl.c:2078: warning: functiondeclaration isn?. a prototype

   build/temp.linux-x86_64-2.7/_openssl.c:2079: warning: functiondeclaration isn?. a prototype

   build/temp.linux-x86_64-2.7/_openssl.c:2080: warning: functiondeclaration isn?. a prototype

   build/temp.linux-x86_64-2.7/_openssl.c:2105: warning: functiondeclaration isn?. a prototype

   build/temp.linux-x86_64-2.7/_openssl.c:2163: warning: functiondeclaration isn?. a prototype

    build/temp.linux-x86_64-2.7/_openssl.c:In function ?.cffi_const_CMS_DEBUG_DECRYPT?.

   build/temp.linux-x86_64-2.7/_openssl.c:8193: error:?.MS_DEBUG_DECRYPT?.undeclared (first use in this function)

   build/temp.linux-x86_64-2.7/_openssl.c:8193: error: (Each undeclaredidentifier is reported only once

   build/temp.linux-x86_64-2.7/_openssl.c:8193:error: for each function it appears in.)

    error:command 'gcc' failed with exit status 1

   

   ----------------------------------------

Command "/usr/bin/python -u -c "importsetuptools,tokenize;__file__='/tmp/pip-HCuemf-build/setup.py';exec(compile(getattr(tokenize,'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"install --record /tmp/pip-YsGgK9-record/install-record.txt --single-version-externally-managed--compile" failed with error code 1 in /tmp/pip-HCuemf-build/

       主要是openssl的版本不匹配,从而需要指定新的版本的ssl的路径,设置环境变量如下所示:

[root@RHAN ~]# exportCPPFLAGS="-I/usr/local/ssl/include/" 指定openssl头文件路径

[root@RHAN ~]# export LDFLAGS="-lssl -lcrypto-Wl,-rpath=/usr/local/ssl/lib/"指定openssl的库文件路径

4.2 无法找到-lssl

       无法找到ssl的路径,可能出现如下报错:

  /usr/bin/ld: cannot find -lssl

    collect2:ld returned 1 exit status

    error:command 'gcc' failed with exit status

gcc -pthread -shared build/temp.linux-x86_64-2.7/build/temp.linux-x86_64-2.7/_openssl.o-lssl -lcrypto -obuild/lib.linux-x86_64-2.7/cryptography/hazmat/bindings/_openssl.so

    /usr/bin/ld: cannot find -lssl

    collect2:ld returned 1 exit status

    error:command 'gcc' failed with exit status 1

       主要也是没有找到ssl的路径,从而执行设置环境变量即可:

[root@RHAN ~]# exportCPPFLAGS="-I/usr/local/ssl/include/" 指定openssl头文件路径

[root@RHAN ~]# export LDFLAGS="-lssl -lcrypto-Wl,-rpath=/usr/local/ssl/lib/"指定openssl的库文件路径

4.3 未能正确安装python

       当没有正确安装python,可能出现如下错误:

[root@RHAN pip-8.1.0]# python setup.py install

ERROR:root:code for hash md5was not found.

Traceback (most recent call last):

  File"/usr/local/python/lib/python2.7/hashlib.py", line 147, in<module>

   globals()[__func_name] = __get_hash(__func_name)

       主要是在make的时候,没有编译正确的扩展模块,也就是openssl的头文件未找到,如果是本机的,直接yum安装openssl-devel即可,如果是自己安装的,那么就必须重新安装python,并且加入ssl的编译。

4.4 安装模块出现运行时错误

       在安装模块的时候,出现如下错误:

[root@RHanible install]# pip installpycrypto-2.6.1.tar.gz

    RuntimeError: autoconf error

   

   ----------------------------------------

Command "/usr/bin/python -u -c "importsetuptools, tokenize;__file__='/tmp/pip-vz034B-build/setup.py';

exec(compile(getattr(tokenize, 'open',open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))"

install --record /tmp/pip-FIiSr7-record/install-record.txt--single-version-externally-managed --compile"

 failed witherror code 1 in /tmp/pip-vz034B-build/

       主要是未安装gcc,如下即可:

[root@RHAN ~]# # yum -y groupinstall"Development tools"

排错

       当出现可能是因为类库的问题的时候,那么可以使用strace -f命令来查看查找类库的路径,也就是看类库路径的位置。


猜你喜欢

转载自blog.51cto.com/15060545/2654258
今日推荐