| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 系统运维 -> 云计算(ansible自动化运维) -> 正文阅读 |
|
[系统运维]云计算(ansible自动化运维) |
准备三台主机 ansible 192.168.2.30 需要联网 192.168.2.40 192.168.2.50 1.yum安装ansible wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo [root@localhost ~]# yum -y install ansible 修改配置文件 [root@localhost ansible]# vim hosts 添加: 修改主配置文件 [root@localhost ansible]# vim ansible.cfg 14 inventory ?????= /etc/ansible/hosts 68 roles_path ???= /etc/ansible/roles 71 host_key_checking = False 111 log_path = /var/log/ansible.log ping ?可以测试主控端和远程主机的连接情况 [root@localhost ansible]# ansible group1 -m ping [root@localhost ansible]# ansible ?all ?-m ?command ?-a ?'ls /home' [root@localhost ansible]# ansible ?all ?-m ?command ?-a ?'touch ?/home/aa' [root@localhost ansible]# ansible ?all ?-m ?command ?-a "chdir=/home ls" [root@localhost ansible]# ansible ?all ?-m ?command ?-a "creates=/etc/fstab ls /home" [root@localhost ansible]# ansible ?all ?-m ?command ?-a ?"creates=/etc/fstabb ls /home" [root@localhost ansible]# ansible ?all ?-m ?command ?-a ?"removes=/etc/fstabb ls /home" [root@localhost ansible]# ansible ?all ?-m ?command ?-a ?"removes=/etc/fstab ls /home" [root@localhost ansible]# ansible all -m command -a "echo 11111 > /home/aa" [root@localhost ansible]# ansible all -m shell -a "echo 1111111 > /home/aa" [root@localhost ansible]# ansible all -m shell -a "cat /home/aa" 安装openssl-devel [root@localhost ~]# yum -y install openssl-devel [root@localhost ~]# openssl passwd -1 123.com $1$polZRW5S$3Hk0.MeN1bQ267/wJLjM2. [root@localhost ~]# ansible all -m user -a 'name=one password=$1$polZRW5S$3Hk0.MeN1bQ267/wJLjM2.' [root@localhost ~]# ansible all -m shell -a "tail -1 /etc/shadow" 客户端验证: 编写脚本 [root@localhost ~]# vim test.sh 给脚本加权限 [root@localhost ~]# chmod +x test.sh [root@localhost ~]# ansible all -m script -a 'chdir=/root test.sh' [root@localhost ~]# ansible all -m script -a 'creates=/etc/fstab chdir=/root test.sh' [root@localhost ~]# ansible all -m script -a 'removes=/etc/fstab chdir=/root test.sh' Copy模块 [root@localhost ~]# touch heh [root@localhost ~]# ansible all -m copy -a 'src=/root/heh dest=/home' [root@localhost ~]# ansible all -m shell -a 'ls /home' [root@localhost ~]# ansible all -m copy -a "content='1111111\n222222' dest=/home/heh" [root@localhost ~]# ansible all -m shell -a 'cat /home/heh' ?101 ?ansible all -m copy -a "content='4444444\n3333333' dest=/home/heh" ??102 ?ansible all -m shell -a 'cat /home/heh' [root@localhost ~]# ansible all -m copy -a 'src=/root/heh dest=/home' [root@localhost ~]# ansible all -m shell -a 'cat /home/heh' [root@localhost ~]# echo 1111 > heh [root@localhost ~]# ansible all -m copy -a 'src=/root/heh dest=/home force=no' [root@localhost ~]# ansible all -m shell -a 'cat /home/heh' [root@localhost ~]# ansible all -m copy -a 'src=/root/heh dest=/home backup=yes' [root@localhost ~]# ansible all -m shell -a 'ls /home/' [root@localhost ~]# mkdir haha [root@localhost ~]# ansible all -m copy -a 'src=/root/haha dest=/home' [root@localhost ~]# touch haha/1 [root@localhost ~]# ansible all -m copy -a 'src=/root/haha dest=/home' [root@localhost ~]# ansible all -m shell -a 'ls /home/' [root@localhost ~]# ansible all -m copy -a 'src=/root/heh dest=/home owner=one group=one mode=777' [root@localhost ~]# ansible all -m shell -a 'ls -l /home/heh' [root@localhost ~]# ansible all -m copy -a 'src=/root/haha dest=/home owner=one group=one mode=777' [root@localhost ~]# ansible all -m shell -a 'ls -ld /home/haha' [root@localhost ~]# ansible all -m shell -a 'ls -l /home/haha/1' Yum模块 [root@localhost ~]# ansible all -m yum -a 'name=samba state=installed' [root@localhost ~]# ansible all -m service -a 'name=smb state=started' [root@localhost ~]# ansible all -m shell -a 'systemctl status smb' [root@localhost ~]# ansible all -m service -a 'name=smb state=restarted' [root@localhost ~]# ansible all -m service -a 'name=smb state=reloaded' [root@localhost ~]# ansible all -m service -a 'name=smb enabled=yes' [root@localhost ~]# ansible all -m shell -a 'systemctl is-enabled smb' [root@localhost ~]# ansible all -m file -a 'path=/home/ee state=touch' [root@localhost ~]# ansible all -m file -a 'path=/home/rr state=directory' [root@localhost ~]# ansible all -m file -a 'state=link src=/home/rr path=/home/tt' [root@localhost ~]# ansible all -m file -a 'state=hard src=/home/ee path=/home/yy' [root@localhost ~]# ansible all -m shell -a 'ls -l /home' [root@localhost ~]# ansible all -m shell -a 'ls -l /home/rr' [[root@localhost ~]# ansible all -m file -a 'path=/home/rr owner=one group=one mode=777' [root@localhost ~]# ansible all -m setup 下面还有很多,只截了一部分 [root@localhost ~]# ansible all -m cron -a "name=one hour=8 minute=10 job='echo 11111 >> /home/ee'" [root@localhost ~]# ansible all -m shell -a 'crontab -l' [root@localhost ~]# ansible all -m file -a 'name=/home/oo state=touch' [root@localhost ~]# ansible all -m shell -a "echo -e '111111\n222222\n3333333' > /home/oo" [root@localhost ~]# ansible all -m shell -a 'cat /home/oo' [root@localhost ~]# ansible all -m lineinfile -a "regexp='^2' line='444444' path=/home/oo" [root@localhost ~]# ansible all -m shell -a 'cat /home/oo' [root@localhost ~]# ansible all -m lineinfile -a "insertbefore='^1' line='555555' path=/home/oo" [root@localhost ~]# ansible all -m shell -a 'cat /home/oo' 164 ?ansible all -m lineinfile -a "insertafter='^4' line='6666666' path=/home/oo" ??165 ?ansible all -m shell -a 'cat /home/oo' ?167 ?ansible all -m lineinfile -a " line='88888888' path=/home/oo" ??168 ?ansible all -m shell -a 'cat /home/oo' ? |
|
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/16 0:47:37- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |