一.ansible 說明

在成都做網(wǎng)站、成都網(wǎng)站設(shè)計過程中,需要針對客戶的行業(yè)特點(diǎn)、產(chǎn)品特性、目標(biāo)受眾和市場情況進(jìn)行定位分析,以確定網(wǎng)站的風(fēng)格、色彩、版式、交互等方面的設(shè)計方向。
創(chuàng)新互聯(lián)還需要根據(jù)客戶的需求進(jìn)行功能模塊的開發(fā)和設(shè)計,包括內(nèi)容管理、前臺展示、用戶權(quán)限管理、數(shù)據(jù)統(tǒng)計和安全保護(hù)等功能。
ansible 是一款自動化工具,可以完成配置系統(tǒng)、軟件發(fā)布、高級任務(wù)的編排、編排更高級的任務(wù),比如連續(xù)部署或零停機(jī)時間滾動更新。
二.anisble 安裝
2.1這里希望通過yum方式安裝,需要安裝EPEL
下載地址:
1 | https: //admin .fedoraproject.org /mirrormanager/mirrors/EPEL |
2.2.安裝epel:
1 | rpm -ivh epel-release-latest-7.noarch.rpm |
2.3.安裝ansible,自動解決依賴關(guān)系
2.4.安裝列表如下:
1 | ansible、PyYAML、libtomcrypt、libtommath、libyaml、python-babel、python-backports 、python-backports-ssl_match_hostname 、python-httplib2 python-jinja2、python-keyczar、python-markupsafe、python-setuptools、python2-crypto、python2-ecdsa、python2-paramiko、python2-pyasn1、sshpass |
2.5.查看ansible版本:
1 2 | # rpm -qa | grep ansible
ansible-2.2.0.0-4.el7.noarch
|

2.6.結(jié)構(gòu)說明
1 2 3 4 5 6 7 8 9 10 | /etc/ansible/ansible .cfg #主配置文件
/etc/ansible/hosts #認(rèn)證主機(jī)列表
/etc/ansible/roles #角色配置路徑
/usr/bin/ansible #主命令
/usr/bin/ansible-console
/usr/bin/ansible-doc #ansible幫助文檔
/usr/bin/ansible-galaxy
/usr/bin/ansible-playbook #playbook命令
/usr/bin/ansible-pull
/usr/bin/ansible-vault
|
三.ansible 認(rèn)證及基本使用
3.1.實(shí)驗(yàn)環(huán)境說明:
172.16.110.39 ansible
172.16.110.47 client1
3.2.anisble基于ssh認(rèn)證,這里通過添加主機(jī)key認(rèn)證的方式來進(jìn)行認(rèn)證。
服務(wù)端
#ssh-keygen -t rsa -P ''
#scp /root/.ssh/id_rsa.pub root@172.16.110.47:/data
#
客戶端
#cd /data/
#cat id_rsa.pub >> /root/.ssh/authorized_keys
#chmod 600 /root/.ssh/authorized_keys
#
3.3.運(yùn)行說明
1 2 | # ansible -h
Usage: ansible <host-pattern> [options]
|
3.3.1.運(yùn)行簡單的ping測試
1 2 3 | # ansible all -m ping
[WARNING]: provided hosts list is empty, only localhost is available
[WARNING]: No hosts matched, nothing to do
|
提示,沒有提供服務(wù)器列表,所以添加列表
主機(jī)列表可以ip、域名、分組、正則匹配等方式運(yùn)行
3.3.2.主機(jī)ip列表方式:
# vim /etc/ansible/hosts
[webservers]
10.237.154.25

ansible all -m ping

SUCCESS:表示成功
false:表示未進(jìn)行改變
pong:返回值,表示成功
3.3.3.分組方式運(yùn)行命令:
1 2 3 4 | vim /etc/ansible/hosts
[webserver]
172.16.110.47
|
1 2 3 | # ansible webserver -a "ls /root"
172.16.110.47 | SUCCESS | rc=0 >>
anaconda-ks.cfg
|

出現(xiàn)以上問題說明ssh認(rèn)證有問題,重新弄一遍。
3.3.5.使用正則列表:
1 2 3 | vim /etc/ansible/hosts
[webserver]
172.16.110.4[7:8]
|
1 2 3 4 5 6 7 | # ansible webserver -a "/sbin/ifconfig ens33 | grep netmask"
172.16.110.48 | FAILED | rc=1 >>
|: Unknown host
ifconfig : `--help' gives usage information.
172.16.110.47 | FAILED | rc=1 >>
|: Unknown host
ifconfig : `--help' gives usage information.
|
這里增加了管道,ansible增加管道必須使用shell的模塊運(yùn)行
1 2 3 4 5 | # ansible webserver -m shell -a "/sbin/ifconfig ens33 | grep netmask"
172.16.110.47 | SUCCESS | rc=0 >>
inet 172.16.110.47 netmask 255.255.255.0 broadcast 172.16.110.255
172.16.110.48 | SUCCESS | rc=0 >>
inet 172.16.110.48 netmask 255.255.255.0 broadcast 172.16.110.255
|
3.4.Inventory 參數(shù)的說明,摘自網(wǎng)上
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | ansible_ssh_host
將要連接的遠(yuǎn)程主機(jī)名.與你想要設(shè)定的主機(jī)的別名不同的話,可通過此變量設(shè)置.
ansible_ssh_port
ssh 端口號.如果不是默認(rèn)的端口號,通過此變量設(shè)置.
ansible_ssh_user
默認(rèn)的 ssh 用戶名
ansible_ssh_pass
ssh 密碼(這種方式并不安全,我們強(qiáng)烈建議使用 --ask-pass 或 SSH 密鑰)
ansible_sudo_pass
sudo 密碼(這種方式并不安全,我們強(qiáng)烈建議使用 --ask- sudo -pass)
ansible_sudo_exe (new in version 1.8)
sudo 命令路徑(適用于1.8及以上版本)
ansible_connection
與主機(jī)的連接類型.比如: local , ssh 或者 paramiko. Ansible 1.2 以前默認(rèn)使用 paramiko.1.2 以后默認(rèn)使用 'smart' , 'smart' 方式會根據(jù)是否支持 ControlPersist, 來判斷 'ssh' 方式是否可行.
ansible_ssh_private_key_file
ssh 使用的私鑰文件.適用于有多個密鑰,而你不想使用 SSH 代理的情況.
ansible_shell_type
目標(biāo)系統(tǒng)的shell類型.默認(rèn)情況下,命令的執(zhí)行使用 'sh' 語法,可設(shè)置為 'csh' 或 'fish' .
ansible_python_interpreter
目標(biāo)主機(jī)的 python 路徑.適用于的情況: 系統(tǒng)中有多個 Python, 或者命令路徑不是 "/usr/bin/python" ,比如 \*BSD, 或者 /usr/bin/python
不是 2.X 版本的 Python.我們
不使用 "/usr/bin/env" 機(jī)制,因?yàn)檫@要求遠(yuǎn)程用戶的路徑設(shè)置正確,且要求 "python" 可執(zhí)行程序名不可為 python以外的名字(實(shí)際有可能名為python26).
與 ansible_python_interpreter 的工作方式相同,可設(shè)定如 ruby 或 perl 的路徑....
|
示例說明:
1 2 3 4 | some_host ansible_ssh_port=2222 ansible_ssh_user=manager
aws_host ansible_ssh_private_key_file= /home/example/ . ssh /aws .pem
freebsd_host ansible_python_interpreter= /usr/local/bin/python
ruby_module_host ansible_ruby_interpreter= /usr/bin/ruby .1.9.3
|
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
文章名稱:Ansible基本說明及安裝-創(chuàng)新互聯(lián)
標(biāo)題URL:http://jinyejixie.com/article20/dpscco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、動態(tài)網(wǎng)站、網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、網(wǎng)站導(dǎo)航
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)