当前位置:网站首页>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
边栏推荐
- 通过流式数据集成实现数据价值(4)-流数据管道
- 杰理之系统事件有哪些【篇】
- [codeforces - 208e] blood cousins
- Go语言实践模式 - 函数选项模式(Functional Options Pattern)
- 《谷雨系列》空投
- Redis exception read error on connection solution
- Random neurons and random depth of dropout Technology
- How to use SQL statement union to get another column of another table when the content of a column in a table is empty
- Number theory blocking (integer division blocking)
- Interviewer: let's talk about some commonly used PHP functions. Fortunately, I saw this article before the interview
猜你喜欢
随机推荐
DBA常用SQL语句(6)- 日常管理
Comparative analysis of meta universe from the dimension of knowledge dissemination
杰理之AES能256bit吗【篇】
Amazon cloud technology entry Resource Center, easy access to the cloud from 0 to 1
SAP excel has completed file level validation and repair. Some parts of this workbook may have been repaired or discarded.
SAP RFC_ CVI_ EI_ INBOUND_ Main BP master data creation example (Demo customer only)
[educational codeforces round 80] problem solving Report
art-template 模板引擎
Windows安装redis并将redis设置成服务开机自启
《Redis设计与实现》
2022年流动式起重机司机考试题库模拟考试平台操作
面试官:说几个PHP常用函数,幸好我面试之前看到了这篇文章
第二章 In-Memory 体系结构 (IM-2.2)
Example of data object mask used by SAP translate
Dropout技术之随机神经元与随机深度
《谷雨系列》空投
[COCI] lattice (dichotomy + tree divide and conquer + string hash)
LeetCode 1249. Minimum Remove to Make Valid Parentheses - FB高频题1
杰理之更准确地确定异常地址【篇】
Planning and construction of industrial meta universe platform