#我的第三十六堂云计算课# #site大型网站高并发集群设计与实现 第1章 Ansible 自动化运维实战#

第1章 Ansible 自动化运维实战

一、abstract-简介:是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。无客户端。
二、install-部署:yum -y install ansible
1、rpm -ql ansible :列出所有文件
2、rpm -qc ansible :查看配置文件
3、ansible-doc -l :看所有模块(A10,华为,docker,EC2,aws等等广大厂商设备)
4、ansible-doc -s yum :看yum模块,了解其功能
三、ssh-key(免密方式):ssh-keygen、ssh-copy-id IP地址
四、ansible基础:
1、测试连通性:ansible host1 -m ping -o
注意:-m 指定模块。什么功能、ping只是其中一个模块。还有shell,yum等等
2、ansible host2 -m ping -u root -k -o :增加用户名选项、增加密码选项
注意:去掉(yes/no)的询问:
vim /etc/ssh/ssh_config
在vim中写入:
StrictHostKeyChecking no
systemctl restart sshd
五、Ad-Hoc-点对点模式:
1、shell模块:ansible-doc shell (帮助)
(1)获取主机名:ansible webserver -m shell -a ‘hostname’ -o
ansible webserver -m shell -a ‘hostname’ -o -f 2 //-f 2 指定线程数
(2)部署apache:ansible host2 -m shell -a ‘yum -y install httpd’ -o
(3)查询系统负载:ansible host3 -m shell -a ‘uptime’ -o
2、复制模块:ansible-doc copy (帮助)
案例:ansible webserver -m copy -a ‘src=/etc/hosts dest=/tmp/2.txt owner=root group=bin mode=777’
3、用户模块:ansible-doc user (帮助)
(1)创建用户:ansible webserver -m user -a ‘name=qianfeng state=present’
(2)修改密码:
1).生成加密密码:echo ‘777777’ | openssl passwd -1 -stdin
生成加密密码值: 1 1 1XVzsJMDr$5wI4oUaQ.emxap6s.N272.
2).修改密码:ansible webserver -m user -a ‘name=qianfeng password=“ 1 1 1XVzsJMDr$5wI4oUaQ.emxap6s.N272.”’
(3)修改shell:ansible webserver -m user -a ‘name=qianfeng shell=/sbin/nologin append=yes’
(4)删除用户:ansible webserver -m user -a ‘name=qianfeng state=absent remove=yes’ //userdel -r
4、软件包管理:ansible-doc service(帮助)
(1)升级所有包:ansible host1 -m yum -a ‘name="*" state=latest’
(2)安装apache:ansible host2 -m yum -a ‘name=“httpd” state=latest’
5、服务模块:ansible-doc service (帮助)
(1)启动:ansible host2 -m service -a ‘name=httpd state=started’
(2)开机启动:ansible host2 -m service -a ‘name=httpd state=started enabled=yes’
(3)停止:ansible host2 -m service -a ‘name=httpd state=stopped’
(4)重启:ansible host2 -m service -a ‘name=httpd state=restarted’
(5)开机禁止启动:ansible host2 -m service -a ‘name=httpd state=started enabled=no’
6、文件模块:ansible-doc file (帮助)
(1)创建文件:ansible host1 -m file -a ‘path=/tmp/88.txt mode=777 state=touch’
(2)创建目录:ansible host1 -m file -a ‘path=/tmp/99 mode=777 state=directory’
7、收集模块:ansible-doc file (帮助)
(1)查询所有信息:ansible host3 -m setup
(2)filter过滤:ansible host3 -m setup -a ‘filter=ansible_all_ipv4_addresses’

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值