ansbile:
運維工作:系統安裝(物理機,虛擬機)--》程序包安裝,配置,服務啓動 --》批量操作 --》程序發佈 --》監控
OS provisioning;
物理機:PXE、cobbler
虛擬機:p_w_picpath templates
configration:
puppet(ruby)
saltstack(python)
chef
cfengine
Command and control:
fabric
預發佈驗證:
新版本的代碼先發布到服務器(跟線上環境配置完全相同,只是未接入調度器)
程序發佈:
不能影響用戶體驗;
系統不能停機;
不能導致系統故障或造成系統完全不可用;
灰度發佈;
發佈路徑:
/webapp/tuangou-1.1
/web/app/tuangou
/webapp/tuangou-1.2
在調度器上關閉一批主機(maintanace)--> 關閉服務 --> 部署新版本的應用程序 -->啓動服務 --> 調度器上啓用這一批服務器
自動化灰度發佈:腳本、發佈平臺;
運維工具的分類;
agent:puppet,func
agentless:ansible,fabric
ssh
ansible:
模塊化,調用特定的模塊,完成特定的任務;
基於python語言實現,由paramiko、PyYAML和Jinja2三個關鍵模塊;
部署簡單,agentless;
主從模式
支持自定義模塊
支持playbook
冪等性;
配置文件;
/etc/ansible/ansbile.cfg
/etc/ansible/hosts
for i in 15 16 17; do ssh 172.16.6.$i 'date';done
查看某個命令的具體用法:
ansible-doc -s command
ansible 172.16.6.15 -m command -a 'ifconfig'
ansible all -m command -a 'ifconfig'
ansible all -a 'ping'
下載FTP文件;
ansible webservers -a 'wget -O /tmp/apr-1.4.6.tar.bz2 ftp://172.16.6.49:2121/mage-app/sources/httpd/apr-1.4.6.tar.bz2'
創建用戶:
ansible webservers -m user -a 'name=hacluster state=present'
刪除用戶;
ansible webservers -m user -a 'name=hacluster state=absent'
常用模塊:
command:直接運行命令
-a ‘COMMAND’
user:添加用戶
-a ‘name= state= system= ’
group:添加組
-a 'name= gid= state= system= '
cron:添加計劃任務
-a 'name= minute= hour= day= month weekday= job= user= state= '
ansible all -m cron -a 'name="sync time from ntpserver" minute="*/10" job="/sbin/ntpdate 172.16.6.14 & > /dev/null"'
ansible all -m cron -a 'name="sync time from ntpserver" state=absent’
copy:文件複製
-a 'dest= src= mode= owner= group'
ansible all -m copy -a 'src=/etc/fstab dest=/tmp/fstab.tmp mode=600'
file:創建刪除文件夾,創建鏈接
-a 'path= mode= owner= group= state=(link\directory\present\absent)'
創建文件,鏈接,刪除鏈接
ansible all -m file -a 'path=/tmp/testdir state=directory'
ansible all -m file -a 'path=/tmp/testdir state=link src=/tmp/fstab.tmp force=yes'
ansible all -m file -a 'path=/tmp/testdir state=absent src=/tmp/fstab.tmp force=yes'
ping
ansible all -m ping
yum:yum安裝包
-a 'name= state=present\latest\absent'
ansible webservers -m yum -a 'name=ftp state=latest'
service:服務啓動停止
-a 'name= state=started\stopped\restarted enabled=yes'
ansible webservers -m service -a 'name=httpd state=started enabled=yes'
shell:遠程運行shell命令
-a 'command'
ansible webservers -m shell -a 'echo centos | passwd --stdin centos'
script:遠程運行本地shell腳本
-a '/path/test.sh'
ansible webservers -m script -a '/tmp/cc.sh'
setup:獲取信息
ansible webservers -m setup