配置 Linux 加固版本库服务器的操作系统
本步骤描述了 Ansible® playbook,其中包含大量操作系统 (OS) 配置任务,可帮助服务器做好准备,使其成为 Veeam® Linux® 加固备份服务器。 该 playbook 针对 Red Hat® 发行版进行测试。
游戏本执行以下任务:
- 升级操作系统软件包
- 配置时区
- 添加用户 调用
veeamlhbr
并将文件系统的所有权更改为该用户 - 配置 Linux 防火墙
- 更改 DNS 条目
可以使用编辑器(如 Visual Studio Code)在笔记本电脑上本地编写播放列表,然后将其传输到自动化服务器 \swlib\ansible
目录,或者使用文本编辑器(如 vi 或 nano)在自动化服务器上本地编辑。
服务器名称和 IP 地址必须在 AD/DNS 服务器的 DNS 中注册。
创建游戏手册
播放列表 create_lhbr.yml
以下面的代码开始。
- hosts: lhbr
vars_files:
- vault
vars:
password: "{{ vault_lhbr_password }}"
timezone: <timezone>
vbr_ip: <vbr_ip>
ansible_ip: <ansible_ip>
dns_1: <addns1>
dns_2: <addns2>
tasks:
将前面代码片段中的 timezone
、vbr_ip
、ansible_ip
、addns1
和 addns2
替换为在前面步骤中获取的值。 前面的代码会执行以下操作:
- 定义在清单文件中定义为
lhbr
的主机上运行游戏本。 - 定义一个包含其他变量的文件,名为
vault
。 上一步创建的vault
文件已加密,其中包含密码等敏感变量。 - 定义时区、配置防火墙的 VBR 服务器和自动化服务器的 IP 地址,以及 DNS 更改的 DNS IP 地址。
升级操作系统软件包
下面的代码片段更新了软件包缓存并升级了操作系统软件包。
tasks:
- name: Update cache
yum:
update_cache: yes
- name: Upgrade all packages
yum:
name: "*"
state: latest
配置时区
在 Red Hat 发行版中,NTP 服务器已配置并指向 servertime.service.softlayer.com
。 因此,只需配置正确的时区即可。
- name: Set timezone
community.general.timezone:
name: "{{ timezone }}"
为版本库配置文件系统
代码片段执行以下操作:
- 卸载
/disk1
文件系统。 - 捕捉分区的 UUID,以便配置
fstab
。 - 使用 UUID 作为
/mnt/veeamrepo01
挂载xfs
分区。
- name: Unmount and remove from /etc/fstab
ansible.posix.mount:
path: /disk1
state: absent
- name: Unmount and remove from /etc/fstab
ansible.posix.mount:
path: /mnt/veeamrepo01
state: absent
- name: Get UUID of /dev/sdb1 and store in variable
command: blkid -s UUID -o value /dev/sdb1
register: uuid_dev_sdb1
- name: Mount as /mnt/veeamrepo01 and add to /etc/fstab
ansible.posix.mount:
path: /mnt/veeamrepo01
src: "UUID={{ uuid_dev_sdb1.stdout }}"
fstype: xfs
state: mounted
在运行前面的代码之前,如果在服务器上运行 df -Th
命令,输出如下所示:
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 42M 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda3 xfs 929G 9.2G 920G 1% /
/dev/sda1 xfs 1006M 273M 734M 28% /boot
/dev/sdb1 xfs 11T 80G 11T 1% /disk1
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/1001
运行前面的代码后,如果运行 df -Th
命令,输出显示如下:
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 32G 0 32G 0% /dev
tmpfs tmpfs 32G 0 32G 0% /dev/shm
tmpfs tmpfs 32G 42M 32G 1% /run
tmpfs tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda3 xfs 929G 9.2G 920G 1% /
/dev/sda1 xfs 1006M 273M 734M 28% /boot
/dev/sdb1 xfs 11T 80G 11T 1% /mnt/veeamrepo01
tmpfs tmpfs 6.3G 0 6.3G 0% /run/user/1001
添加用户并更改文件系统的所有权
代码片段执行以下操作:
- 添加一个组,名为
veeamlhbr
。 - 添加一个用户,名为
veeamlhbr
。 - 更改
/mnt/veeamrepo01
的所有权,并设置权限,使所有者可以读取、写入和运行,而组不能读取、写入和运行。 其他用户无法读取、写入和运行。 Veeam 使用该用户读写文件系统。
更改 Linux 服务器上身份验证证书的文件权限,以最大限度地提高版本库的安全性。 有关详细信息,请参阅 增强加固版本库安全性的提示。
- name: Create the veeamlhbr group
ansible.builtin.group:
name: veeamlhbr
state: present
- name: Add the user 'veeamlhbr' with a bash shell
ansible.builtin.user:
name: veeamlhbr
shell: /bin/bash
create_home: yes
password: "{{ password | password_hash('sha512') }}"
state: present
groups: veeamlhbr,wheel
append: yes
- name: Change ownership of /mnt/veeamrepo01 to veeamlhbr
ansible.builtin.file:
path: /mnt/veeamrepo01
state: directory
owner: veeamlhbr
group: veeamlhbr
mode: "700"
配置 Linux 防火墙
代码片段执行以下操作:
- 允许从 TCP 端口
22
上的 Veeam 备份服务器 SSH。 在初始连接 Veeam 备份服务器并安装所需的 Veeam 服务后,此规则将被移除。 - 允许从自动化服务器进行 SSH 访问。 配置任务完成后,可删除此规则。 不过,今后的维护工作可能会变得更加困难。
- 允许通过 TCP 端口
6162
访问 Veeam 备份服务器。 该端口是用于与版本库服务器通信的 Veeam 控制通道。 - 防火墙已启动,启动时已启用,并已启用日志记录功能。
- name: Enable firewalld on system reboot
service:
name: firewalld
enabled: yes
- name: Allow SSH
ansible.posix.firewalld:
service: ssh
permanent: yes
state: enabled
- name: Allow incoming access from the vbr server for management
ansible.posix.firewalld:
port: 6162/tcp
permanent: yes
state: enabled
- name: Reload firewall and enable firewall on boot
service:
name: firewalld
state: restarted
更改 DNS
以下代码片段将 DNS 从 IBM Cloud® DNS 解析器 - 10.0.80.11
和 10.0.80.12
更改为 VMware Cloud Foundation for Classic - Automated 实例 DNS - addns1
和 addns2
。
- name: Change resolv nameserver_1
replace:
path: /etc/resolv.conf
regexp: "10.0.80.11"
replace: "{{ dns_1 }}"
- name: Change resolv nameserver_2
replace:
path: /etc/resolv.conf
regexp: "10.0.80.12"
replace: "{{ dns_2 }}"
最终确定游戏手册
保存文件。 确保文件保存在自动化服务器的 \swlib\ansible
目录中。