当前位置: 首页 > news >正文

ansible临时命令实验题

ansible临时命令实验题

1、对node1主机操作,安装httpd服务,网页存放在/www目录中,能够通过curl http://node1访问到网页内容为welcome to luoqi

安装httpd服务:

[student@master ansible]$ ansible node1 -m yum -a 'name=httpd state=present'

创建网页目录并设置selinux上下文:

[student@master ansible]$ ansible node1 -m file -a 'path=/www state=directory setype=httpd_sys_content_t'

生成网页文件:(文件内容为welcome to luoqi)

[student@master ansible]$ ansible node1 -m copy -a 'content="welcome to luoqi" dest=/www/index.html'
[student@master ansible]$ ansible node1 -m file -a 'path=/www/index.html setype="httpd_sys_content_t"'

修改httpd配置:

[student@master ansible]$ ansible node1 -m replace -a 'path=/etc/httpd/conf/httpd.conf regexp="/var/www" replace="/www" backup=yes'
[student@master ansible]$ ansible node1 -m replace -a 'path=/etc/httpd/conf/httpd.conf regexp="/www/html" replace="/www" backup=yes'

启动httpd并设置开机自启:

[student@master ansible]$ ansible node1 -m service -a 'name=httpd state=started enabled=yes'

验证结果:

[student@master ansible]$ curl http://node1
welcome to luoqi

2、对node2主机操作,创建一个1000MiB的分区,格式化成ext4的文件系统,并挂载到/testdir目录下

使用ansible node2 -m shell -a 'df -Th’验证

创建磁盘分区:

[student@master ansible]$ ansible-galaxy collection install http://ansible.example.com/materials/community-general-6.3.0.tar.gz -p collections/
[student@master ansible]$ ansible node2 -m parted -a 'device=/dev/vdb number=1 part_type=primary part_start=10MiB part_end=1010MiB state=present'

格式化分区为ext4:

[student@master ansible]$ ansible node2 -m filesystem -a 'dev=/dev/vdb1 fstype=ext4'

创建挂载点:(/testdir)

[student@master ansible]$ ansible node2 -m file -a 'path=/testdir state=directory'

查看分区UUID:

[student@master ansible]$ ansible node2 -m shell -a 'blkid /dev/vdb1'
[student@master ansible]$ ansible-galaxy collection install http://ansible.example.com/materials/ansible-posix-1.5.1.tar.gz -p collections/

永久挂载分区:

[student@master ansible]$ ansible node2 -m mount -a 'src="UUID=801c5e74-d403-4576-ba57-a3c5230b022f" path=/testdir fstype=ext4 state=mounted'

验证结果:

[student@master ansible]$ ansible node2 -m shell -a 'df -Th'
node2 | CHANGED | rc=0 >>
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  4.0M     0  4.0M   0% /dev
tmpfs          tmpfs     985M     0  985M   0% /dev/shm
tmpfs          tmpfs     394M  5.6M  389M   2% /run
/dev/vda3      xfs        17G  1.4G   16G   8% /
/dev/vda1      xfs      1014M  182M  833M  18% /boot
tmpfs          tmpfs     197M     0  197M   0% /run/user/1000
/dev/vdb1      ext4      966M   24K  900M   1% /testdir

3、对node3主机操作创建卷组datastorage,逻辑卷database,大小为800M,格式化为xfs的文件系统,并挂载到/lv目录下
使用ansible node3 -m shell -a 'df -Th’验证

创建物理卷分区:

[student@master ansible]$ ansible node3 -m parted -a 'device=/dev/vdb number=1 part_type=primary part_start=2530MiB part_end=4530MiB state=present'
[student@master ansible]$ ansible node3 -m yum -a "name=lvm2 state=present"

创建卷组datastorage:

[student@master ansible]$ ansible node3 -m lvg -a 'vg=datastorage pvs=/dev/vdb1'

创建逻辑卷database

[student@master ansible]$ ansible node3 -m lvol -a 'lv=database size=800M vg=datastorage'

格式化逻辑卷为 xfs:

[student@master ansible]$ ansible node3 -m filesystem -a 'dev=/dev/datastorage/database fstype=xfs'

创建挂载点:(/lv)

[student@master ansible]$ ansible node3 -m file -a 'path=/lv state=directory mode=0755'

查看逻辑卷UUID:

[student@master ansible]$ ansible node3 -m shell -a 'blkid /dev/datastorage/database'

永久挂载逻辑卷:

[student@master ansible]$ ansible node3 -m mount -a 'src=UUID=eec71a08-e123-457e-8b75-3b87f5c1c69a path=/lv fstype=xfs state=mounted'

验证结果:

[student@master ansible]$ ansible node3 -m shell -a 'df -Th'
node3 | CHANGED | rc=0 >>
Filesystem                       Type      Size  Used Avail Use% Mounted on
devtmpfs                         devtmpfs  4.0M     0  4.0M   0% /dev
tmpfs                            tmpfs     985M     0  985M   0% /dev/shm
tmpfs                            tmpfs     394M  5.6M  389M   2% /run
/dev/vda3                        xfs        17G  1.4G   16G   9% /
/dev/vda1                        xfs      1014M  182M  833M  18% /boot
tmpfs                            tmpfs     197M     0  197M   0% /run/user/1000
/dev/mapper/datastorage-database xfs       794M   38M  757M   5% /l
http://www.dtcms.com/a/361849.html

相关文章:

  • 自动化运维-ansible中的管理机密
  • Ansible之playbook剧本
  • Docker镜像安全守护神HarborGuard
  • Shell编程入门指南
  • apollo学习之纳什均衡求解最优策略
  • MySQL 中 InnoDB 引擎的事务隔离级别与“可重复读”隔离级别下的 SQL 编写规范
  • 2025 中国算力大会精彩回顾:算力驱动未来,液冷引领革新
  • 从 Oracle 到 TiDB,通过ETL工具,高效实现数据拉通
  • HarvardX TinyML小笔记2(番外3:数据工程)(TODO)
  • 【C++游记】AVL树
  • 通过 select into outfile / load data infile 进行数据导入导出学习笔记
  • 【网络安全入门基础教程】网络安全就业方向(非常详细)零基础入门到精通,收藏这篇就够了
  • three.js+WebGL踩坑经验合集(10.2):镜像问题又一坑——THREE.InstancedMesh的正反面向光问题
  • 亥姆霍兹线圈和放载流线圈
  • 【SpreadJS V18.2 新特性】Table 与 DataTable 双向转换功能详解
  • SD卡自动检测与挂载脚本
  • React 第七十一节 Router中generatePath的使用详解及注意事项
  • table表格字段明细展示
  • 【前端教程】ES6 Promise 实战教程:从基础到游戏案例
  • django的URL路由配置常用方式
  • C# Task 入门:让你的程序告别卡顿
  • 基于STM32单片机的无线鼠标设计
  • 【ComfyUI】图像反推描述词总结
  • 杰理ac791无法控制io脚原因
  • 【算法】算法题核心类别与通用解题思路
  • 时序数据库IoTDB:为何成为工业数据管理新宠?
  • 【frontend】w3c的发展历史ToDo
  • accelerate、trainer、lightning还是pytorch?
  • SpringBoot 分库分表 - 实现、配置与优化
  • 雅思听力第四课:配对题核心技巧与词汇深化