ansible,
ansible,
ansbile:
运维工作:系统安装(物理机,虚拟机)--》程序包安装,配置,服务启动 --》批量操作 --》程序发布 --》监控
OS provisioning;
物理机:PXE、cobbler
虚拟机:image 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
本文转自阿伦艾弗森 51CTO博客,原文链接:http://blog.51cto.com/perper/1978158,如需转载请自行联系原作者
评论暂时关闭