2021-05-12 14:32:11
Linux下原始碼編譯安裝Ansible及排錯記錄
1、測試環境描述
系統 SUSE 11 sp2
因為是生產環境無法存取外網,所以搭建環境都是離線環境下原始碼安裝的。
軟體包:
Python-2.7.11.tar.xz
setuptools-7.0.tar.gz
pycrypto-2.6.1.tar.gz
yaml-0.1.4.tar.gz
PyYAML-3.11.tar.gz
MarkupSafe-0.9.3.tar.gz
Jinja2-2.7.3.tar.gz
ecdsa-0.11.tar.gz
paramiko-1.15.1.tar.gz
simplejson-3.6.5.tar.gz
ansible-1.7.2.tar.gz
如果順利的話一次編譯上邊的原始碼包就可以完成環境的搭建,但是我的環境中在剛開始編譯python的時候就出現了問題
2、問題描述及解決過程
ansible需要python的支援,我們的環境中都是python2.6的,網上看好多文章都說到使用python2.7版本會比較好,在之後依賴性的問題會比較少,說做就做,結果在編譯python的過程中折騰了老半天,下面詳細記錄遇到的問題。
環境原本的python環境
server:/ansibletest # python
Python 2.6 (r26:66714, May 6 2011, 15:10:21)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
備份python指令碼
server:/ansibletest # mv /usr/bin/python /usr/bin/python.bak
server:/ansibletest # xz -d Python-2.7.11.tar.xz
(如果環境中沒有xz命令說明還需要編譯xz工具)
server:/ansibletest # tar -xf Python-2.7.11.tar
server:/ansibletest # mkdir src
server:/ansibletest/Python-2.7.11 # ./configure --prefix=/ansibletest/src/python27
server:/ansibletest/Python-2.7.11 # make
make出錯
linux-3qo7:/ansibletest/Python-2.7.11 # make
Failed to build these modules:
_curses _curses_panel _hashlib
_ssl
出現上邊的錯誤如果不解決的話之後在編譯ecdsa-0.11.tar.gz 的時候就會出現下面的錯誤
ERROR:root:code for hash md5 was not found.
Traceback (most recent call last):
File "/ansibletest/usr/local/python27/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/ansibletest/usr/local/python27/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type md5
ERROR:root:code for hash sha1 was not found.
Traceback (most recent call last):
File "/ansibletest/usr/local/python27/lib/python2.7/hashlib.py", line 147, in <module>
globals()[__func_name] = __get_hash(__func_name)
File "/ansibletest/usr/local/python27/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type sha1
ERROR:root:code for hash sha224 was not found.
.......略過資訊
ValueError: unsupported hash type sha512
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from ecdsa.six import print_
File "/ansibletest/ecdsa-0.11/ecdsa/__init__.py", line 3, in <module>
from .keys import SigningKey, VerifyingKey, BadSignatureError, BadDigestError
File "/ansibletest/ecdsa-0.11/ecdsa/keys.py", line 5, in <module>
from . import rfc6979
File "/ansibletest/ecdsa-0.11/ecdsa/rfc6979.py", line 14, in <module>
from .util import number_to_string, number_to_string_crop
File "/ansibletest/ecdsa-0.11/ecdsa/util.py", line 6, in <module>
from hashlib import sha256
ImportError: cannot import name sha256
經過網上的查詢,定位到缺少_curses和_curses_panel是因為缺少ncurses-devel的包,而缺少_hashlib 和_ssl我則參考下面連結裡的文章 。
http://blog.csdn.net/chary8088/article/details/22891357
處理過程:
根據我的另一篇文章你可以在本地windows系統搭建一個yum源
連結:http://xiaoxiaozhou.blog.51cto.com/4681537/1888713
環境基礎安裝元件:
rpm -qa | grep ncurses
libncurses5-32bit-5.6-90.55
libncurses5-5.6-90.55
yast2-ncurses-2.17.20-0.5.103
libncurses6-5.6-90.55
ncurses-utils-5.6-90.55
yast2-ncurses-pkg-2.17.19-0.5.100
安裝ncurses-devel
# zypper install ncurses-devel
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following NEW packages are going to be installed:
ncurses-devel tack
2 new packages to install.
Overall download size: 3.2 MiB. After the operation, additional 22.7 MiB will be used.
Continue? [y/n/?] (y): y
Retrieving package tack-5.6-90.55.x86_64 (1/2), 79.0 KiB (170.0 KiB unpacked)
Retrieving: tack-5.6-90.55.x86_64.rpm [done]
Retrieving package ncurses-devel-5.6-90.55.x86_64 (2/2), 3.1 MiB (22.5 MiB unpacked)
Retrieving: ncurses-devel-5.6-90.55.x86_64.rpm [done]
Installing: tack-5.6-90.55 [done]
Installing: ncurses-devel-5.6-90.55 [done]
編譯openssl-1.0.1h.tar.gz
解壓
server:/ansibletest # tar -zxf openssl-1.0.1h.tar.gz
編譯
server:/ansibletest/openssl-1.0.1h # ./config --prefix=/ansibletest/usr/local/openssl
server:/ansibletest/openssl-1.0.1h # make && make install
server:/ansibletest # mkdir -p usr/local
server:/ansibletest/usr/local # ln -s openssl ssl
server:/ansibletest/usr/local # ln -s openssl /usr/local/ssl
server:/ansibletest/usr/local # vi /etc/ld.so.conf
/home/was_wcm/ansible/usr/local/openssl/lib
server:/ansibletest/usr/local # ldconfig
server:/ansibletest/usr/local # vi /etc/profile
export OPENSSL=/home/was_wcm/ansible/usr/local/openssl/bin
export PATH=$OPENSSL:$PATH:$HOME/bin
server:/ansibletest/usr/local # source /etc/profile
server:/ansibletest/usr/local # ldd /home/was_wcm/ansible/usr/local/openssl/bin/openssl
linux-vdso.so.1 => (0x00007fff5f6ed000)
libssl.so.1.0.0 => /home/was_wcm/ansible/usr/local/openssl/lib/libssl.so.1.0.0 (0x00007fa9d7179000)
libcrypto.so.1.0.0 => /home/was_wcm/ansible/usr/local/openssl/lib/libcrypto.so.1.0.0 (0x00007fa9d6d9f000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007fa9d6b6a000)
libc.so.6 => /lib64/libc.so.6 (0x00007fa9d67f6000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa9d73e6000)
再次編譯python
server:/ansibletest/Python-2.7.11 # make
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 _ssl
_tkinter bsddb185 bz2
dbm dl gdbm
imageop readline sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
running build_scripts
server:/ansibletest/Python-2.7.11 # make install
server:/ansibletest/Python-2.7.11 # ln -s /ansibletest/src/python27/bin/python /usr/bin/python
server:/ansibletest/Python-2.7.11 # python
Python 2.7.11 (default, Oct 12 2016, 17:03:57)
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Traceback (most recent call last):
File "/etc/pythonstart", line 7, in <module>
import readline
ImportError: No module named readline
>>>
(缺少readline模組的問題姑且不論,因為對於ansible的環境來說無關緊要)
因為編譯ansible需要很多依賴環境,依賴環境的編譯還有著一定的先後順序,因為它們之間也存在依賴關係,下面開始編譯環境。
3、開始編譯安裝ansible環境
編譯setuptools
server:/ansibletest # tar zxf setuptools-7.0.tar.gz
server:/ansibletest # cd setuptools-7.0/
server:/ansibletest/setuptools-7.0 # python setup.py install
編譯pycrypto
server:/ansibletest # tar zxf pycrypto-2.6.1.tar.gz
server:/ansibletest # cd pycrypto-2.6.1/
server:/ansibletest/pycrypto-2.6.1 # python setup.py install
編譯yaml
server:/ansibletest # tar zxf yaml-0.1.4.tar.gz
server:/ansibletest # cd yaml-0.1.4/
server:/ansibletest/yaml-0.1.4 # ./configure --prefix=/ansibletest/usr/local/yaml
server:/ansibletest/yaml-0.1.4 # make
server:/ansibletest/yaml-0.1.4 # make install
編譯PyYAML
server:/ansibletest # tar zxf PyYAML-3.11.tar.gz
server:/ansibletest # cd PyYAML-3.11/
server:/ansibletest/PyYAML-3.11 # python setup.py install
編譯MarkupSafe
server:/ansibletest # tar zxf MarkupSafe-0.9.3.tar.gz
server:/ansibletest # cd MarkupSafe-0.9.3/
server:/ansibletest/MarkupSafe-0.9.3 # python setup.py install
編譯Jinja2
server:/ansibletest # tar zxf Jinja2-2.7.3.tar.gz
server:/ansibletest # cd Jinja2-2.7.3/
server:/ansibletest/Jinja2-2.7.3 # python setup.py install
編譯ecdsa
server:/ansibletest # tar zxf ecdsa-0.11.tar.gz
server:/ansibletest # cd ecdsa-0.11/
server:/ansibletest/ecdsa-0.11 # python setup.py install
server:/ansibletest/Python-2.7.11 # make
編譯paramiko
server:/ansibletest # tar xvzf paramiko-1.15.1.tar.gz
server:/ansibletest # cd paramiko-1.15.1
server:/ansibletest # pythonsetup.py install
編譯simplejson
server:/ansibletest # tar xvzf simplejson-3.6.5.tar.gz
server:/ansibletest # cdsimplejson-3.6.5
server:/ansibletest # pythonsetup.py install
編譯ansible
server:/ansibletest # tar xvzf ansible-1.7.2.tar.gz
server:/ansibletest # cd ansible-1.7.2/
server:/ansibletest/ansible-1.7.2 # python setup.py install
至此一個完整的ansible伺服器端算是設定完成
一個小小的驗證
設定用戶端IP
server:~ # cat /etc/ansible/hosts
[slave]
192.168.1.101
server:/ansibletest/ansible-1.7.2 # ./bin/ansible all -m ping --ask-pass
SSH password:
paramiko: The authenticity of host '192.168.1.101' can't be established.
The ssh-rsa key fingerprint is 21e1cca2719628f4859afa0b1ea805ee.
Are you sure you want to continue connecting (yes/no)?
(all是對所有分組的進行批次處理)
下面關於Ansible的文章您也可能喜歡,不妨參考下:
使用Ansible批次管理遠端伺服器 http://www.linuxidc.com/Linux/2015-05/118080.htm
Ansible安裝設定與簡單使用 http://www.linuxidc.com/Linux/2015-07/120399.htm
在 CentOS 7 中安裝並使用自動化工具 Ansible http://www.linuxidc.com/Linux/2015-10/123801.htm
Ansible和Docker的作用和用法 http://www.linuxidc.com/Linux/2014-11/109783.htm
CentOS 7上搭建Jenkins+Ansible服務 http://www.linuxidc.com/Linux/2016-12/138737.htm
Ansible批次搭建LAMP環境 http://www.linuxidc.com/Linux/2014-10/108264.htm
Ansible :一個設定管理和IT自動化工具 http://www.linuxidc.com/Linux/2014-11/109365.htm
Ansible基礎—安裝與常用模組 http://www.linuxidc.com/Linux/2017-02/140216.htm
自動化運維工具之 Ansible 介紹及安裝使用 http://www.linuxidc.com/Linux/2016-12/138104.htm
Ansible入門notify和handlers http://www.linuxidc.com/Linux/2017-02/140871.htm
CentOS 6.5安裝自動化工具Ansible和圖形化工具Tower http://www.linuxidc.com/Linux/2017-03/141422.htm
相關文章