利用 Ansiable 自動化部署 Veeam Backup & Replication 9.5U4b

  • 2019 年 11 月 3 日
  • 筆記

利用 Ansiable 自動化部署 Veeam Backup & Replication 9.5U4b

前言

上周出差期間接到一個做CMP(雲管平台)Partner的需求,要在無人值守的安裝 VBR,由於在過去的一年裡 Veeeam 陸續的在中國的公有雲平台登錄,如:Azure、AWS、騰訊雲、阿里雲… 在這之前,我對 Veeam 的無人值守安裝做過功課。在和這個兄弟攀談的過程中,而和以前我做DRaaS和CMP時一樣,在這個CMP的環境里,大部分自動化功能都是用 Ansible 來實現的,這對Veeam 今後在CMP Partner的推廣還會有助力,說干就干。

本文主要內容

  • 1 Ansible 介紹
  • 2 前提:Veeam的靜默安裝模式
  • 3 Ansiable 自動化部署環境準備環境準備
    • 3.1 自動化引擎 — Ansible 伺服器的部署
    • 3.2 執行對象 — Windows 伺服器的部署
    • 3.3 WinRM 及 帳戶身份驗證模式
  • 4 連通性測試,win-ping
  • 5 編寫 Asible Playbook 進行流程編排
  • 6 執行 Asible Playbook 實現自動化部署
  • 參考書籍與推薦閱讀
  • 本文的原文鏈接

1 Ansiable 介紹

在多雲管理的世界裡,大家經常會討論自動化部署問題。而只要是涉及到Windows伺服器,都不免一聲嘆息。因為很多工具對Windows的支援都不是太好,大部分情況下,我們都要為Windows搞一套獨立的工具與環境。而我們都喜歡 ansible 的原因是,這個自動化運維工具廣泛的支援各種系統,當然,最重要的是它支援windows 😉

Ansible是傑出的自動化運維工具,使用Python進行開發,它博採眾長,集多種運維工具(puppet、chef、func、fabric…)的優點於一身,可以實現批量系統配置和程式部署、運行命令等功能。如此優秀,以至於在 2015年被 redhat 收入懷中。Ansible 是基於模組進行工作的,本身是一個自動化引擎,我們通常會在 Playbook中用自動化語言定義什麼樣的操作會被執行。通俗的講,Ansible就像是自動演奏的鋼琴,而Playbook是樂譜,而Ansible Tower則是提供UI和Restful API的介面,Ansible 的架構如下:

Ansiable

想更多的了解這個推薦 Jesse Keating 大神的《Mastering Ansible》也歡迎隨時和我討論。

《Mastering Ansible》 by Jesse Keating
https://www.ansible.com/resources/ebooks/mastering-ansible

2 前提:Veeam的靜默安裝模式

我創建的 Ansible Playbook 用於 在 Windows Server,(這裡是我們使用 Windows Server 2019 做為 VBR 伺服器)上安裝與部署 Veeam Backup & Replication Server 9.5 Update 4b,使用 Ansible 實現的 Veeam Backup & Replication Server 的靜默安裝。

Veeam有非常優秀的靜默安裝模式,幾乎所有的組件都可以進行自動安裝,這樣用戶就可以在無人值守的情況下,進行試大批量的自定義的安裝,對於災備自動化來說也非常有幫助。

安裝的順序與模組如下,詳情請參考,Veeam的官方文檔。

User Guide for VMware vSphere > Deployment > Installing Veeam Backup & Replication in Unattended Mode

[《Veeam 靜默安裝 》] (https://helpcenter.veeam.com/docs/backup/vsphere/silent_mode.html?ver=95u4)

  • Veeam Backup Catalog
  • Veeam Backup & Replication Server
  • Veeam Backup & Replication Console
  • Veeam Explorers:
    • Veeam Explorer for Active Directory
    • Veeam Explorer for Exchange
    • Veeam Explorer for Oracle
    • Veeam Explorer for SharePoint
    • Veeam Explorer for Microsoft SQL
  • Veeam Update 4b

目前在雲管理模式下, Veeam Backup Enterprise Manager 和 Cloud Connect Portal 都自定義部署,而且通常是多對一模式,在此我們沒有涉及。

3 Ansiable 自動化部署環境準備

3.1 自動化引擎–Ansible 伺服器的部署

Linux 版本與 擴展庫配置

此處我們使用CentOS 7.7 做為Ansible 伺服器,版本如下,我們只需要進行OS的最小化安裝即可

[root@localhost ~]# cat /etc/redhat-release  CentOS Linux release 7.7.1908 (Core)  [root@localhost ~]# 

先為Yum庫配置epel源,再安裝Ansible

yum install -y epel-release  yum update -y  yum install -y ansible git vim htop

安裝Python PiP 與 pywinrm

yum install -y python-pip  pip install --upgrade pip # optional  pip install pywinrm  

配置Inventory文件,定義hosts

此處為了簡便,我們使用Ansible默認的inventory文件,/etc/ansible/hosts

[VBR]  172.16.60.133    [VBR:vars]  ansible_connection=winrm  ansible_user="Administrator"  #ansible_ssh_pass=!vault | $ANSIBLE_VAULT;1.1;AES256  ansible_ssh_port=5985  ansible_winrm_server_cert_validation=ignore  ansible_winrm_transport=ntlm

執行對象–Windows 伺服器的部署

在我們的環境中,Windows是我們自動化安裝VBR的伺服器。 為了使 Windows Server 準備授予 WinRM 訪問許可權,我使用了以下腳本使我們環境可以快速的Ready!

ConfigureRemotingForAnsible.ps1 腳本,您可以前往Ansible社區的Github下載,腳本執行如下
ConfigureRemotingForAnsible.ps1

PS C:UsersAdministratorDesktopcode> .ConfigRemotingForAnsiable.ps1 -Verbose  VERBOSE: Verifying WinRM service.  VERBOSE: PS Remoting is already enabled.  VERBOSE: SSL listener is already active.  VERBOSE: Basic auth is already enabled.  VERBOSE: Firewall rule already exists to allow WinRM HTTPS.  VERBOSE: HTTP: Enabled | HTTPS: Enabled  VERBOSE: PS Remoting has been successfully configured for Ansible.  PS C:UsersAdministratorDesktopcode>

WinRM 及 帳戶身份驗證模式

Ansible 從1.7之後的版本支援 Windows服務的管理,管理機仍然需要一台Linux伺服器,通訊方式為PowerShell,為了與Windows通訊管理機還須要安裝WinRm模組,方可和遠程Windows主機正常通訊。

WinRM使用帳戶身份驗證時,可以使用幾種不同的選項,在這裡我選擇了 NTLM + Ansiable 加密模組 的方式作為 WinRM 帳戶身份驗證。

注意:在本文中使用的密碼方式,是通過Ansible 加密做為密碼傳遞基礎的,您可以使用不同的選項,如明文密碼。此方法在Hosts文件定義主機時,和在YAML文件中定義Playbook的方法相同。Ansible 加密方法不是本文討論的重點,如關心此處請查看Ansible 手冊

選項 本地賬戶 AD賬戶 憑據委託 HTTP 加密
Basic
Certificate
Kerberos
NTLM
CredSSP

4 連通性測試,win-ping

ansible 有一個非常好的工具win-ping,專門用來測試與Windows的Host定義是不是可以聯通。詳情可以參照,Asiable的手冊。

[《Ansible 用戶手冊》] (https://https://docs.ansible.com/ansible/2.5/user_guide/quickstart.html)

[root@localhost ~]# ansible VBR -m win_ping --vault-password-file vault_pass.txt    172.16.60.133 | SUCCESS => {      "changed": false,      "ping": "pong"  }

5 編寫 Asible Playbook 進行自動化編排

Playbook中的所有預定義應答,請參考Veeam的手冊,在這裡我們定義的伺服器為VBR,這與真實的主機名已經解偶,Playbook中繼承了 win_package Ansible 模組,這可以自動處理參數中所需的大多數轉義。在軟體源的定義中,我給出了最簡單的路徑,您可以按照需求進行定義。

- name: VBR Community Edition Setup    hosts: VBR    gather_facts: yes    vars:      vbr_source: "D:\"      sql_username: "svc_sql"      sql_userpassword: !vault|          $ANSIBLE_VAULT;1.1;AES256      sql_sapassword: !vault |          $ANSIBLE_VAULT;1.1;AES256    tasks:    - name: Pre - Install 2012 System CLR Types      win_package:          path: "{{ vbr_source }}Redistr\x64\SQLSysClrTypes.msi"          state: present      tags: pre    - name: Pre - Install 2012 Shared management objects      win_package:          path: "{{ vbr_source }}Redistr\x64\SharedManagementObjects.msi"          state: present      tags: pre    - name: SQL - Create Local SQL User      win_user:          name: "{{ sql_username }}"          password: "{{ sql_userpassword }}"          password_never_expires: yes          state: present          groups:              - Users      tags: pre    - name: SQL - Install SQL 2016 Express      win_package:          path: "{{ vbr_source }}Redistr\x64\SqlExpress\2016SP1\SQLEXPR_x64_ENU.exe"          product_id: SQL 2016 Express          arguments:          - '/q'          - '/ACTION=Install'          - '/IACCEPTSQLSERVERLICENSETERMS'          - '/FEATURES=SQL'          - '/INSTANCENAME=VEEAMSQL2016'          - '/SQLSVCACCOUNT={{ sql_username }}'          - '/SQLSVCPASSWORD={{ sql_userpassword }}'          - '/SECURITYMODE=SQL'          - '/SAPWD={{ sql_sapassword }}'          - '/ADDCURRENTUSERASSQLADMIN'          - '/UPDATEENABLED=0'          - '/TCPENABLED=1'          - '/NPENABLED=1'      tags: sql    - name: Install VBR Catalog      win_package:          path: "{{ vbr_source }}Catalog\VeeamBackupCatalog64.msi"          state: present          arguments:              - 'VBRC_SERVICE_ACCOUNT_TYPE=1'              - 'ACCEPT_THIRDPARTY_LICENSES=1'      tags: vbr    - name: Install VBR Server      win_package:          path: "{{ vbr_source }}Backup\Server.x64.msi"          state: present          arguments: "VBR_SERVICE_ACCOUNT_TYPE=1 VBR_SQLSERVER_AUTHENTICATION=1 VBR_SQLSERVER_SERVER=(local)\VEEAMSQL2016 VBR_SQLSERVER_USERNAME=sa VBR_SQLSERVER_PASSWORD={{ sql_sapassword }} ACCEPT_THIRDPARTY_LICENSES=1 ACCEPTEULA=YES"      tags: vbr    - name: Install VBR Console      win_package:          path: "{{ vbr_source }}Backup\Shell.x64.msi"          state: present          arguments:              - 'ACCEPTEULA=YES'              - 'ACCEPT_THIRDPARTY_LICENSES=1'      tags: vbr    - name: Install VBR Explorer for ActiveDirectory      win_package:          path: "{{ vbr_source }}Explorers\VeeamExplorerForActiveDirectory.msi"          state: present          arguments:              - 'ACCEPT_EULA=1'              - 'ACCEPT_THIRDPARTY_LICENSES=1'      tags: vbr    - name: Install VBR Explorer for Exchange      win_package:          path: "{{ vbr_source }}Explorers\VeeamExplorerForExchange.msi"          state: present          arguments:              - 'ACCEPT_EULA=1'              - 'ACCEPT_THIRDPARTY_LICENSES=1'      tags: vbr    - name: Install VBR Explorer for Oracle      win_package:          path: "{{ vbr_source }}Explorers\VeeamExplorerForOracle.msi"          state: present          arguments:              - 'ACCEPT_EULA=1'              - 'ACCEPT_THIRDPARTY_LICENSES=1'      tags: vbr    - name: Install VBR Explorer for SharePoint      win_package:          path: "{{ vbr_source }}Explorers\VeeamExplorerForSharePoint.msi"          state: present          arguments:              - 'ACCEPT_EULA=1'              - 'ACCEPT_THIRDPARTY_LICENSES=1'      tags: vbr    - name: Install VBR Explorer for SQL      win_package:          path: "{{ vbr_source }}Explorers\VeeamExplorerForSQL.msi"          state: present          arguments:              - 'ACCEPT_EULA=1'              - 'ACCEPT_THIRDPARTY_LICENSES=1'      tags: vbr    - name: Install VBR Update 4b      win_package:          path: "{{ vbr_source }}Updates\veeam_backup_9.5.4.2866.update4b_setup.exe"          product_id: VBR Update 4b          arguments: "/silent /noreboot VBR_AUTO_UPGRADE=1"      tags: update    

執行 Asible Playbook 實現自動化安裝

[root@localhost ~]# ansible-playbook ./Veeam_setup.yml --vault-password-file vault_pass.txt    PLAY [VBR Community Edition Setup] *******************************************************************************    TASK [Gathering Facts] *******************************************************************************************  ok: [172.16.60.133]    TASK [Pre - Install 2012 System CLR Types] ***********************************************************************  changed: [172.16.60.133]    TASK [Pre - Install 2012 Shared management objects] **************************************************************  changed: [172.16.60.133]    TASK [SQL - Create Local SQL User] *******************************************************************************  ok: [172.16.60.133]    TASK [SQL - Install SQL 2016 Express] ****************************************************************************  changed: [172.16.60.133]    TASK [Install VBR Catalog] ***************************************************************************************  changed: [172.16.60.133]    TASK [Install VBR Server] ****************************************************************************************  changed: [172.16.60.133]    TASK [Install VBR Console] ***************************************************************************************  changed: [172.16.60.133]    TASK [Install VBR Explorer for ActiveDirectory] ******************************************************************  changed: [172.16.60.133]    TASK [Install VBR Explorer for Exchange] *************************************************************************  changed: [172.16.60.133]    TASK [Install VBR Explorer for Oracle] ***************************************************************************  changed: [172.16.60.133]    TASK [Install VBR Explorer for SharePoint] ***********************************************************************  changed: [172.16.60.133]    TASK [Install VBR Explorer for SQL] ******************************************************************************  changed: [172.16.60.133]    TASK [Install VBR Update 4b] *************************************************************************************  changed: [172.16.60.133]    PLAY RECAP *******************************************************************************************************  172.16.60.133              : ok=14   changed=12   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0  

此時,可以看到伺服器的上我們需要的服務都已經啟動

PS C:UsersAdministrator> Get-service Veeam*    Status   Name               DisplayName  ------   ----               -----------  Running  VeeamBackupSvc     Veeam Backup Service  Running  VeeamBrokerSvc     Veeam Broker Service  Running  VeeamCatalogSvc    Veeam Guest Catalog Service  Running  VeeamCloudSvc      Veeam Cloud Connect Service  Running  VeeamDeploySvc     Veeam Installer Service  Running  VeeamDistributi... Veeam Distribution Service  Running  VeeamMountSvc      Veeam Mount Service  Running  VeeamNFSSvc        Veeam vPower NFS Service  Running  VeeamTransportSvc  Veeam Data Mover Service      PS C:UsersAdministrator> Get-service SQL*    Status   Name               DisplayName  ------   ----               -----------  Stopped  SQLAgent$VEEAMS... SQL Server Agent (VEEAMSQL2016)  Running  SQLBrowser         SQL Server Browser  Running  SQLTELEMETRY$VE... SQL Server CEIP service (VEEAMSQL2016)  Running  SQLWriter          SQL Server VSS Writer

參考書籍與推薦閱讀

[1.《Veeam 靜默安裝 》] (https://helpcenter.veeam.com/docs/backup/vsphere/silent_mode.html?ver=95u4)
https://helpcenter.veeam.com/docs/backup/vsphere/silent_mode.html?ver=95u4

[2.《Ansible 用戶手冊》] (https://https://docs.ansible.com/ansible/2.5/user_guide/quickstart.html)
https://www.ansible.com/resources/ebooks/mastering-ansible

3.《Mastering Ansible》 by Jesse Keating
https://www.ansible.com/resources/ebooks/mastering-ansible