日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

centos 7使用tar包安装ansible

發(fā)布時(shí)間:2025/3/21 编程问答 11 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos 7使用tar包安装ansible 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
由于我的yum源沒有ansible軟件包,防止以后內(nèi)網(wǎng)服務(wù)器也沒有ansible的yum源,干脆一點(diǎn),直接tar包安裝!!!!

下載軟件包

- # 1.python安裝 # python2.7安裝 [root@VM-0-17-centos ~]# wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz [root@VM-0-17-centos ~]# tar xvzf Python-2.7.8.tgz [root@VM-0-17-centos ~]# cd Python-2.7.8 [root@VM-0-17-centos Python-2.7.8]# ./configure --prefix=/usr/local [root@VM-0-17-centos Python-2.7.8]# make && make install# 將python頭文件拷貝到標(biāo)準(zhǔn)目錄,以避免編譯ansible時(shí),找不到所需的頭文件 [root@VM-0-17-centos ~]# cd /usr/local/include/python2.7 [root@VM-0-17-centos ~]# cp -a ./* /usr/local/include/# 備份舊版本的python,并且符號鏈接新版本的python [root@VM-0-17-centos ~]# cd /usr/bin [root@VM-0-17-centos ~]# mv python python.old [root@VM-0-17-centos ~]# ln -s /usr/local/bin/python2.7 /usr/local/bin/python [root@VM-0-17-centos ~]# rm -f /usr/bin/python && cp /usr/local/bin/python2.7 /usr/bin/python# 修改yum腳本,使其指向舊版本的python,已避免其無法運(yùn)行 [root@VM-0-17-centos ~]# vim /usr/bin/yum #!/usr/bin/python --> #!/usr/bin/python2.4# python-devel安裝 Tips :若python版本已經(jīng)為2.6或以上,則不需要再重裝python,只是還需要安裝python開發(fā)包:python-dev(有的操作系統(tǒng)下為python-devel) [root@VM-0-17-centos ~]# yum -y install python-devel- # 2.setuptools模塊安裝 [root@VM-0-17-centos ~]# wget https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz [root@VM-0-17-centos ~]# tar -xf setuptools-7.0.tar.gz [root@VM-0-17-centos ~]# cd setuptools-7.0/ [root@VM-0-17-centos setuptools-7.0]# python setup.py install- # 3.pyYaml安裝 [root@VM-0-17-centos ~]# wget http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz [root@VM-0-17-centos ~]# tar -xf yaml-0.1.5.tar.gz [root@VM-0-17-centos ~]# cd yaml-0.1.5/ [root@VM-0-17-centos yaml-0.1.5]# ./configure --prefix=/usr/local [root@VM-0-17-centos yaml-0.1.5]# make --jobs=`grep processor /proc/cpuinfo | wc -l` [root@VM-0-17-centos yaml-0.1.5]# make install[root@VM-0-17-centos ~]# wget https://pypi.python.org/packages/source/P/PyYAML/PyYAML-3.11.tar.gz [root@VM-0-17-centos ~]# tar -xf PyYAML-3.11.tar.gz [root@VM-0-17-centos ~]# cd PyYAML-3.11/ [root@VM-0-17-centos PyYAML-3.11]# python setup.py install- # 4.Jinjia2模塊安裝 [root@VM-0-17-centos ~]# tar -xf MarkupSafe-0.9.3.tar.gz [root@VM-0-17-centos ~]# cd MarkupSafe-0.9.3/ [root@VM-0-17-centos MarkupSafe-0.9.3]# python setup.py install[root@VM-0-17-centos ~]# wget https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.7.3.tar.gz [root@VM-0-17-centos ~]# tar -xf Jinja2-2.7.3.tar.gz [root@VM-0-17-centos ~]# cd Jinja2-2.7.3/ [root@VM-0-17-centos Jinja2-2.7.3]# python setup.py install- # 5.paramiko模塊安裝 [root@VM-0-17-centos ~]# wget https://pypi.python.org/packages/source/e/ecdsa/ecdsa-0.11.tar.gz [root@VM-0-17-centos ~]# tar -xf ecdsa-0.11.tar.gz [root@VM-0-17-centos ~]# cd ecdsa-0.11/ [root@VM-0-17-centos ecdsa-0.11]# python setup.py install[root@VM-0-17-centos ~]# wget https://pypi.python.org/packages/source/p/paramiko/paramiko-1.15.1.tar.gz [root@VM-0-17-centos ~]# tar -xf paramiko-1.15.1.tar.gz [root@VM-0-17-centos ~]# cd paramiko-1.15.1/ [root@VM-0-17-centos paramiko-1.15.1]# python setup.py install- # 7.simplejson模塊安裝 [root@VM-0-17-centos ~]# wget https://pypi.python.org/packages/source/s/simplejson/simplejson-3.6.5.tar.gz [root@VM-0-17-centos ~]# tar -xf simplejson-3.6.5.tar.gz [root@VM-0-17-centos ~]# cd simplejson-3.6.5/ [root@VM-0-17-centos simplejson-3.6.5]# python setup.py install- # 8.ansible安裝 [root@VM-0-17-centos ~]# wget https://mirrors.huaweicloud.com/ansible/ansible-1.7.2.tar.gz [root@VM-0-17-centos ~]# tar -xf ansible-1.7.2.tar.gz [root@VM-0-17-centos ~]# cd ansible-1.7.2/ [root@VM-0-17-centos ansible-1.7.2]# python setup.py install[root@VM-0-17-centos ~]# ansible --version ansible 1.7.2

ansible的配置

注:centos7.0安裝ansible后發(fā)現(xiàn)找不到ansible.cfg,配置文件的路徑如下,并將配置文件拷貝過去 [root@VM-0-17-centos ~]# cd ansible-1.7.2/examples/ [root@VM-0-17-centos examples]# ls ansible.cfg hosts playbooks [root@VM-0-17-centos examples]# mkdir /etc/ansible [root@VM-0-17-centos examples]# cp hosts ansible.cfg /etc/ansible [root@VM-0-17-centos examples]# ll /etc/ansible total 12 -rw-r--r-- 1 root root 7172 Aug 27 11:30 ansible.cfg -rw-r--r-- 1 root root 965 Aug 27 11:30 hosts默認(rèn)配置文件位置為/etc/ansible/ansilble.cfg,配置文件位置可以修改。Ansible 按照如下位置和順序來查找ansible.cfg 文件: 1.ANSIBLE_CONFIG 環(huán)境變量所指定的文件。 2../ansible.cfg(當(dāng)前目錄下的ansible.cfg)。 3.~/.ansible.cfg(家目錄下的.ansible.cfg)。 4./etc/ansible/ansible.cfg。

配置ssh登錄

# 推薦將公鑰傳到被管理主機(jī)上面 [root@VM-0-17-centos ~]# ssh-keygen -t rsa # 創(chuàng)建公鑰 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Qj0BOMA7w5BT57pyv29IBTpni5rMPXt9RivKSKp8wCA root@VM-0-17-centos The key's randomart image is: +---[RSA 2048]----+ | +o...... | |+ .o+ . . | | + o.o. o | |E B.o.. . | |+ .B o. S | | o..o . . | |+o=o .. . . | |+=o=+..o + | |oo.o**o + | +----[SHA256]-----+ [root@VM-0-17-centos ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub 121.37.227.88 # 將公鑰傳給被管理主機(jī) root@121.37.227.88's password: # 輸入密碼 [root@VM-0-17-centos ~]# ssh 121.37.227.88 # 遠(yuǎn)程登錄被管理主機(jī)Welcome to Huawei Cloud Service[root@ecs-proxy ~]# # 成功!# 也可以選擇在本機(jī)的配置文件上面添加被管理主機(jī)的用戶名密碼,但是并不安全 [root@VM-0-17-centos ~]# vim /etc/ansible/hosts # 修改配置文件 [webservers] 121.37.227.88 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=123456 ps:當(dāng)?shù)谝淮芜h(yuǎn)程的時(shí)候需要確認(rèn)一下主機(jī)之間的公鑰連接,我們需要在配置文件中將這個(gè)選項(xiàng)修改 [root@VM-0-17-centos ~]# vim /etc/ansible/ansible.cfg 39 host_key_checking = False 執(zhí)行測試 [root@VM-0-17-centos ~]# ansible -i /etc/ansible/hosts webservers -m ping 121.37.227.88 | success >> {"changed": false, "ping": "pong" # 成功 } # 查看服務(wù)器的狀態(tài) [root@VM-0-17-centos ~]# ansible webservers -m command -a 'w' 121.37.227.88 | success | rc=0 >>14:22:03 up 36 days, 20:56, 3 users, load average: 0.00, 0.03, 0.07 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT root tty1 21Jul20 36days 0.07s 0.07s -bash root pts/0 220.112.46.251 10:05 2:46m 0.06s 0.06s -bash root pts/1 106.54.95.242 14:22 1.00s 0.06s 0.01s w
—我遇到的坑坑坑坑們—
執(zhí)行playbook時(shí)報(bào)錯(cuò) pkg_resources.DistributionNotFound: The 'pynacl>=1.0.1' distribution was not found and is required by paramiko提示pynacl沒有安裝或者安裝版本過低 [root@VM-0-17-centos ~]# pip install pynacl 再報(bào)錯(cuò) paramiko 2.7.1 requires bcrypt>=3.1.3, which is not installed. 提示bcrypt沒有安裝 [root@VM-0-17-centos ~]# pip install bcrypt--------------------------------------------------------------------------------執(zhí)行ansible時(shí)報(bào)出紫色的[DEPRECATION WARNING]警告 [DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it can also be a list of hosts, a directory or a list of paths , use [defaults] inventory=/path/to/file|dir instead. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. [DEPRECATION WARNING]: DEFAULT_MODULE_LANG option, Modules are coded to set their own locale if needed for screenscraping . This feature will be removed in version 2.9. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. [DEPRECATION WARNING]: DEFAULT_SUDO_EXE option, In favor of Ansible Become, which is a generic framework. See become_exe. , use become instead. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg. [DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of Ansible Become, which is a generic framework. See become_user. , use become instead. This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.解決辦法: 在ansible.cfg文件中根據(jù)提示將deprecation_warnings改為FALSE [root@VM-0-17-centos ~]# vim /etc/ansible/ansible.cfg 103 deprecation_warnings = False

總結(jié)

以上是生活随笔為你收集整理的centos 7使用tar包安装ansible的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。