SMB:使用 Ansible 自动化配置 samba 客户端服务端

写在前面


  • 考试顺便整理
  • 博文内容整理 使用 Ansible 部署 samba 客户端和服务端
  • 理解不足小伙伴帮忙指正

对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》


涉及到的文件

[student@workstation filestorage-automation]$ tree .
.
├── ansible.cfg
├── inventory
├── smb_client.yml
├── smb_server.yml
├── smb_vars.yml
└── templates└── smb.conf.j2[student@workstation filestorage-automation]$

涉及到的 主机清单

[student@workstation filestorage-automation]$ cat inventory
[servers]
serverd.lab.example.com[clients]
servera.lab.example.com
serverb.lab.example.com
serverc.lab.example.com
[student@workstation filestorage-automation]$

这里我们使用 serverd 做服务端,使用 servera,b,c 做客户端

[student@workstation filestorage-review]$ cat ansible.cfg
[defaults]
inventory=inventory
remote_user=devops

ansible 配置文件 ,使用 devops 作ssh 用户

samba 对应的配置文件的 jija 模版


[student@workstation filestorage-automation]$ cat templates/smb.conf.j2
[global]workgroup = SAMBAsecurity = userpassdb backend = tdbsamsmb encrypt = requiredserver min protocol = SMB3[{{ share_name }}]path = {{ shared_dir }}write list = @{{ allowed_group }}
[student@workstation filestorage-automation]$

通过模版配置文件,我们可以看到使用的是最基本的配置文件,下面为涉及到的变量

[student@workstation filestorage-review]$ cat smb_vars.yml
---
shared_dir: /srv/developers
share_name: devdata
mount_point: /devs_data# User account for mounting the share
samba_usermount: sambamount
samba_passmount: redhatallowed_group: developers
[student@workstation filestorage-review]$

服务端部署

服务端需要执行的剧本

  • 安装Samba软件包:使用yum模块安装Samba软件包。
  • 创建Linux和Samba用户:创建一个用于挂载共享的Linux和Samba用户。
  • 创建Linux组:创建一个用于具有写访问权限的用户组。
  • 创建Samba用户:为Samba用户创建密码,并将其添加到Samba用户数据库中。
  • 创建目录:使用file模块创建要共享的目录,并设置所有者、组和权限。
  • 配置Samba:使用template模块将SMB配置文件模板复制到目标位置。
  • 启动SMB服务:使用service模块启动和启用SMB服务。
  • 开放Samba防火墙服务:使用firewalld模块开启Samba防火墙服务。
  • 定义处理程序:定义名为 reload smb 的处理程序,用于在配置更改后重新加载SMB服务。
[student@workstation filestorage-automation]$ cat  smb_server.yml
---
- name: Share a directory with SMBhosts: serverd.lab.example.combecome: truevars_files:- smb_vars.ymltasks:- name: the samba package is installedyum:name: sambastate: present# Creating the Linux and Samba user for the multiuser mount.# That user is only used to mount the share.- name: the Linux user for Samba mount existsuser:name: "{{ samba_usermount }}"shell: /sbin/nologincreate_home: nosystem: yes- name: the Samba user for Samba mount existscommand: smbpasswd -s -a {{ samba_usermount }}args:stdin: "{{ samba_passmount }}\n{{ samba_passmount }}"# Group and users with write access to the share- name: the Linux group existsgroup:name: "{{ allowed_group }}"system: yes- name: the Linux users exist for Samba usersuser:name: "{{ item['name'] }}"shell: /sbin/nologingroups:- "{{ allowed_group }}"loop: "{{ samba_users }}"no_log: true- name: the Samba users existcommand: smbpasswd -s -a {{ item['name'] }}args:stdin: "{{ item['password'] }}\n{{ item['password'] }}"loop: "{{ samba_users }}"no_log: true- name: the directory existsfile:path: "{{ shared_dir }}"owner: rootgroup: "{{ allowed_group }}"mode: '2775'state: directorysetype: samba_share_t- name: the directory is sharedtemplate:src: templates/smb.conf.j2dest: /etc/samba/smb.confowner: rootgroup: rootmode: '0644'setype: samba_etc_tnotify: reload smb- name: the smb service is started and enabledservice:name: smbstate: startedenabled: yes- name: the samba firewall service is openedfirewalld:service: sambastate: enabledimmediate: yespermanent: yeshandlers:- name: reload smbservice:name: smbstate: reloaded
[student@workstation filestorage-automation]$

客户端配置

  • 安装 cifs-utils 软件包:使用yum模块确保目标主机上安装了cifs-utils软件包。
  • 创建凭据文件:使用copy模块创建一个凭据文件(/etc/samba/creds.txt),其中包含SMB用户名和密码。用户名和密码从samba_usermount和samba_passmount变量中获取。
  • 挂载SMB共享:使用mount模块挂载SMB共享。path参数指定本地系统上的挂载点,src参数指定SMB共享的位置(//serverd.lab.example.com/{{ share_name }})。opts参数指定挂载选项,包括凭据文件路径(/etc/samba/creds.txt)、multiuser模式和seal安全选项。fstype参数将文件系统类型指定为cifs。
  • 创建Linux用户:使用user模块在目标主机上创建Linux用户。用户名和密码从samba_users变量中获取。密码使用SHA-512算法以’redhatsalt’作为盐值进行哈希处理。
[student@workstation filestorage-automation]$ cat smb_client.yml
---
- name: Access an SMB sharehosts: servera.lab.example.combecome: truevars_files:- smb_vars.ymltasks:- name: the cifs-utils package is installedyum:name: cifs-utilsstate: present- name: the credential file existscopy:content: "username={{ samba_usermount }}\n\password={{ samba_passmount }}\n"dest: /etc/samba/creds.txtowner: rootgroup: rootmode: '0600'no_log: true- name: the SMB share is mountedmount:path: "{{ mount_point }}"src: "//serverd.lab.example.com/{{ share_name }}"opts: "credentials=/etc/samba/creds.txt,multiuser,seal"state: mountedfstype: cifs- name: the Linux users existuser:name: "{{ item.name }}"shell: /bin/bashpassword: "{{ item.password | \password_hash('sha512', 'redhatsalt') }}"loop: "{{ samba_users }}"no_log: true
[student@workstation filestorage-automation]$

博文部分内容参考

© 文中涉及参考链接内容版权归原作者所有,如有侵权请告知,这是一个开源项目,如果你认可它,不要吝啬星星哦 😃


红帽服务管理与自动化(RH358)授课笔记


© 2018-2023 liruilonger@gmail.com, All rights reserved. 保持署名-非商用-相同方式共享(CC BY-NC-SA 4.0)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/85177.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

百度之星(数学基础题)

糖果促销 小度最喜欢吃糖啦!!! 这天商店糖果促销,可给小度高兴坏了。 促销规则:一颗糖果有一张糖纸,p 张糖纸可以换取一颗糖果。换出来糖果的包装纸当然也能再换糖果。 小度想吃 k 颗糖果,他…

以太坊代币标准ERC20、ERC721

两个概念 ERC(Ethereum Request for Comment) 以太坊意见征集稿EIP(Ethereum Improvement Proposals)以太坊改进提案 ERC和EIP用于使得以太坊更加完善;在ERC中提出了很多标准,用的最多的标准就是它的Token标准; 有哪些标准详细见https://eips.ethereum…

三行代码实现图像画质修复,图片清晰度修复,清晰度提升python

核心代码 # 原始文件 enhancer ImageEnhance.Sharpness(Image.open(文件路径.png)) # 增强图片 img_enhanced enhancer.enhance(增强系数float) # 输出目标文件 img_enhanced.save(文件名.png)注意,输入输出文件格式必须一致 所需依赖 # 文件选择框&#xff0c…

【lesson7】yum的介绍及使用

文章目录 预备工作yum的基本过程yum的操作**yum源问题:****yum三板斧:**yum listyum searchyum list | grepyum installyum install -yyum removeyum remove -y 预备工作 首先有三个问题: 问题解答: 这里我们联想到了手机 问题…

论文阅读:AugGAN: Cross Domain Adaptation with GAN-based Data Augmentation

Abstract 基于GAN的图像转换方法存在两个缺陷:保留图像目标和保持图像转换前后的一致性,这导致不能用它生成大量不同域的训练数据。论文提出了一种结构感知(Structure-aware)的图像转换网络(image-to-image translation network)。 Proposed Framework…

Golang 字符串

目录 1. Golang 字符串1.1. 基础概念1.2. 字符串编码1.3. 遍历字符串1.4. 类型转换1.5. 总结1.6. String Concatenation (字符串连接)1.6.1. Using the operator1.6.2. Using the operator1.6.3. Using the Join method1.6.4. Using Sprintf method1.6.5. Using Go string Bu…

K-means 聚类算法学习笔记

K-means 聚类算法 是一种无监督学习算法,用来将 n n n 个样本点分成 k k k 类,使得整个数据集的误差平方和 S S E SSE SSE 最小。在本例中,样本点是指平面直角坐标系上的点,聚类中心也是平面直角坐标系上的点,而每个…

5.5V-65V Vin同步降压控制器,具有线路前馈SCT82630DHKR

描述: SCT82630是一款65V电压模式控制同步降压控制器,具有线路前馈。40ns受控高压侧MOSFET的最小导通时间支持高转换比,实现从48V输入到低压轨的直接降压转换,降低了系统复杂性和解决方案成本。如果需要,在低至6V的输…

Java“牵手”义乌购商品详情数据,义乌购商品详情接口,义乌购API接口申请指南

义乌购隶属浙江义乌购电子商务有限公司旗下网站。该平台定位为依托实体市场,服务实体市场,以诚信为根本,将7万网上商铺与实体商铺一一对应绑定,为采购商和经营户提供可控、可信、可溯源的交易保障。 义乌购平台现有商铺商品、市场…

网络连接中的三次握手和四次挥手

三次握手和四次挥手都是TCP协议通信过程中建立和关闭连接的步骤。 三次握手的步骤如下: 客户端发送SYN包,进入SYN-SENT状态。服务器接收到SYN包,回复一个ACK包和一个SYN包,进入SYN-RECEIVED状态。客户端收到ACK包和SYN包&#x…

Fair原理篇Fair逻辑动态化架构设计与实现

本文的核心内容包括: 数据逻辑处理布局中的逻辑处理Flutter类型数据处理一、数据逻辑处理 我们接触的每一个Flutter界面,大多由布局和逻辑相关的代码组成。如Flutter初始工程的Counting Demo的代码: class _MyHomePageState extends State<MyHomePage> {// 变量 int…

OpenHarmony Meetup常州站招募令

OpenHarmony Meetup 常州站正火热招募中&#xff01; 诚邀充满激情的开发者参与线下盛会~ 探索OpenHarmony前沿科技&#xff0c;畅谈未来前景&#xff0c; 感受OpenHarmony生态构建之路的魅力&#xff01; 线下参与&#xff0c;名额有限&#xff0c;仅限20位幸运者&#xff01…

计算机网络常见问题

1.谈一谈对OSI七层模型和TCP/IP四层模型的理解&#xff1f; 1.1.为什么要分层&#xff1f; 在计算机中网络是个复杂的系统&#xff0c;不同的网络与网络之间由于协议&#xff0c;设备&#xff0c;软件等各种原因在协调和通讯时容易产生各种各样的问题。例如&#xff1a;各物流…

【MySQL】 MySQL的增删改查(进阶)--贰

文章目录 &#x1f6eb;新增&#x1f6ec;查询&#x1f334;聚合查询&#x1f6a9;聚合函数&#x1f388;GROUP BY子句&#x1f4cc;HAVING &#x1f38b;联合查询⚾内连接⚽外连接&#x1f9ed;自连接&#x1f3c0;子查询&#x1f3a1;合并查询 &#x1f3a8;MySQL的增删改查(…

web前端之float布局与flex布局

float布局 <style>.nav {overflow: hidden;background-color: #6adfd0; /* 导航栏背景颜色 */}.nav a {float: left;display: block;text-align: center;padding: 14px 16px;text-decoration: none;color: #000000; /* 导航栏文字颜色 */}.nav a:hover {background-col…

测试基础知识

测试的基础知识 软件&#xff1a;控制硬件工作的工具。 软件测试&#xff1a;使用技术手段验证软件是否满足使用需求。 软件测试目的&#xff1a;减少软件缺陷&#xff0c;保证软件质量。 测试主流技能&#xff1a;功能测试、自动化测试、接口测试、性能测试 功能测试&#xff…

三相组合式过电压保护器试验

三相组合式过电压保护器试验 试验目的 三相组合式过电压保护器主要分为有带串联间隙过压保护器和无间隙过压保护器两大类&#xff0c;其试验项目内容要求分别使用高压工频交流和高压直流电源。 三相组合式过电压保护器试验&#xff0c;主要是为了及早发现设备内部绝缘受潮及…

C语言实现循环双链表

在C语言中&#xff0c;实现一个循环双链表需要定义一个节点结构体&#xff0c;这个结构体包含三个字段&#xff1a;数据字段&#xff0c;指向前一个节点的指针&#xff0c;以及指向下一个节点的指针。定义节点结构体&#xff1a; 1)定义节点结构体&#xff1a; typedef struc…

解锁学习新方式——助您迈向成功之路

近年来&#xff0c;随着吉林开放大学广播电视大学的崛起&#xff0c;越来越多的学子选择这所优秀的学府来实现自己的梦想。而作为一名学者&#xff0c;我有幸见证了电大搜题微信公众号的诞生&#xff0c;为广大学子提供了一个全新的学习支持平台。 电大搜题微信公众号&#xff…

《深度学习工业缺陷检测》专栏介绍 CSDN独家改进实战

&#x1f4a1;&#x1f4a1;&#x1f4a1;深度学习工业缺陷检测 1&#xff09;提供工业小缺陷检测性能提升方案&#xff0c;满足部署条件&#xff1b; 2&#xff09;针对缺陷样品少等难点&#xff0c;引入无监督检测&#xff1b; 3&#xff09;深度学习 C、C#部署方案&#…