当前位置:网站首页>ansible 云计算 自动化
ansible 云计算 自动化
2022-04-23 09:56:00 【数据库从删库到跑路】
四台服务器:
ansible: 管理端
node01 node02 node03: 被管理节点
1) 安装
[root@ansible ~]# yum install ansible -y
2) 查看帮助
[root@ansible ~]# ansible-doc -l | wc -l # 查看模块数量
[root@ansible ~]# ansible-doc -s yum # 查看yum模块的参数
[root@ansible ~]# ansible-doc yum # 查看相关帮助信息 (搜索/EXAMPLES)
[root@ansible ~]# ansible node03 -m setup # 获取对端节点的内置相关变量(主机名 ip地址等)
3) 如何查看某个模块的详细帮助信息
查看源代码: /usr/lib/python2.7/site-packages/ansible/modules/packaging/os/yum.py
ansible-doc yum # 查看相关帮助信息 (搜索/EXAMPLES)
常用四大模块:
yum copy file service
几个重要概念:
安装present
卸载absent
升级latest
排除exclude
指定仓库enablerepo
语法格式:
ansible 主机名或组名 -m 指定模块 -a 具体命令
yum模块:
#示例1: 安装当前最新的apache软件, 如果存在则更新
[root@ansible ~]# ansible group1 -m yum -a "name=httpd state=latest"
#示例2: 安装当前最新的apache软件, 通过本地仓库安装
[root@ansible ~]# ansible group1 -m yum -a "name=httpd state=latest enablerepo=c7-local-http"
#示例3: 删除apache软件
[root@ansible ~]# ansible group1 -m yum -a "name=httpd state=absent"
copy模块:
#示例1: 将本地的httpd.conf文件Listen端口修改为8080, 然后推送到远端服务器
[root@ansible ~]# ansible group1 -m copy -a "src=/etc/ansible/source_code/copy_module/httpd.conf dest=/etc/httpd/conf/httpd.conf owner=root group=root mode=644"
#示例2: 将本地的httpd.conf文件Listen端口修改为8088, 然后推送到远端, 检查远端是否存在上一次的备份文件
[root@ansible ~]# ansible group1 -m copy -a "src=/etc/ansible/source_code/copy_module/httpd.conf dest=/etc/httpd/conf/httpd.conf owner=root group=root mode=644 backup=yes"
# 查看是否有对应的备份文件
[root@ansible ~]# ssh node01 ls /etc/httpd/conf/httpd\*
#示例3: 往远程的主机文件中写入内容
[root@ansible ~]# ansible group1 -m copy -a "content='Hello World......\n' dest=/var/www/html/index.html"
# 校验对端服务器对应的文件内容是否已经修改
[root@ansible ~]# ssh node01 cat /var/www/html/index.html
file模块:
#示例1: 创建文件/var/www/html/hostname.html, 并设定属主 属组 权限
[root@ansible ~]# ansible group1 -m file -a "path=/var/www/html/hostname.html state=touch owner=apache group=apache mode=644"
# 查看文件否创建成功
[root@ansible copy_module]# ssh node01 ls -lt /var/www/html/hostname.html
#示例2: 创建目录/var/www/html/imgs, 并设定属主 属组 权限
[root@ansible ~]# ansible group1 -m file -a "path=/var/www/html/imgs state=directory owner=apache group=apache mode=755"
[root@ansible ~]# ssh node01 ls -ld /var/www/html/imgs
#示例3: 递归授权目录的方式
[root@ansible ~]# ansible group1 -m file -a "path=/var/www/html/ owner=apache group=apache mode=755"
[root@ansible ~]# ansible group1 -m file -a "path=/var/www/html/ owner=apache group=apache recurse=yes" # 递归授权
service模块:
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=stopped" # 先停止服务
查看服务状态:
[root@ansible ~]# ssh node01 systemctl status httpd | grep 'Active: '
Active: inactive (dead) since # stopped状态
#示例1: 启动Httpd服务
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=started"
查看服务状态:
[root@ansible ~]# ssh node01 systemctl status httpd | grep 'Active: '
Active: active (running) since Mon # running状态
#示例2: 重载Httpd服务
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=reloaded"
#示例3: 重启Httpd服务
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=restarted"
#示例4: 停止Httpd服务
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=stopped"
#示例5: 启动Httpd服务, 并加入开机自启
[root@ansible ~]# ansible group1 -m service -a "name=httpd state=started enabled=yes"
版权声明
本文为[数据库从删库到跑路]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_60655253/article/details/124274616
边栏推荐
- ES-aggregation聚合分析
- SQL调优系列文章之—SQL性能方法论
- 论文阅读《Integrity Monitoring Techniques for Vision Navigation Systems》——3背景
- Nvidia最新三维重建技术Instant-ngp初探
- CSP认证 202203-2 出行计划(多种解法)
- SAP 03-amdp CDs table function using 'with' clause
- Introduction to sap pi / PO login and basic functions
- 防疫登记小程序
- [Niuke practice match 68] fans of Niuniu (matrix fast power cycle matrix optimization)
- SAP excel has completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.
猜你喜欢
《谷雨系列》空投
论文阅读《Integrity Monitoring Techniques for Vision Navigation Systems》——5结果
Easy to understand subset DP
Yarn核心参数配置
元宇宙时代的职业规划与执行
Computer network security experiment II DNS protocol vulnerability utilization experiment
Leetcode0587. Install fence
ABAP implementation publishes restful services for external invocation example
failureForwardUrl与failureUrl
Dropout技术之随机神经元与随机深度
随机推荐
解决VMware卸载后再安装出现的问题
杰理之通常影响CPU性能测试结果的因素有:【篇】
[ACM-ICPC 2018 Shenyang Network preliminaries] J. Ka Chang (block + DFS sequence)
MapReduce核心和基础Demo
Computer network security experiment II DNS protocol vulnerability utilization experiment
工业元宇宙平台规划与建设
Compile and debug mysql8 with clion under MacOS x
"Gu Yu series" airdrop
Comparative analysis of meta universe from the dimension of knowledge dissemination
Odoo 服务器搭建备忘
Redis 异常 read error on connection 解决方案
ARM调试(1):两种在keil中实现printf重定向到串口的方法
一文读懂PlatoFarm新经济模型以及生态进展
CSP认证 202203-2 出行计划(多种解法)
Pyqt5 and communication
P1390 sum of common divisor (Mobius inversion)
F-niu Mei's apple tree (diameter combined)
Longest common front string
(Extended) bsgs and higher order congruence equation
Dropout技术之随机神经元与随机深度