上週出差期間接到一個作CMP(雲管平臺)Partner的需求,要在無人值守的安裝 VBR,因爲在過去的一年裏 Veeeam 陸續的在國內的公有云平臺登陸,如:Azure、AWS、騰訊雲、阿里雲... 在這以前,我對 Veeam 的無人值守安裝作過功課。在和這個兄弟攀談的過程當中,而和之前我作DRaaS和CMP時同樣,在這個CMP的環境裏,大部分自動化功能都是用 Ansible 來實現的,這對Veeam 從此在CMP Partner的推廣還會有助力,說幹就幹。html
在多雲管理的世界裏,你們常常會討論自動化部署問題。而只要是涉及到Windows服務器,都難免一聲嘆息。由於不少工具對Windows的支持都不是太好,大部分狀況下,咱們都要爲Windows搞一套獨立的工具與環境。而咱們都喜歡 ansible 的緣由是,這個自動化運維工具普遍的支持各類系統,固然,最重要的是它支持windows ;-)python
Ansible是傑出的自動化運維工具,使用Python進行開發,它博採衆長,集多種運維工具(puppet、chef、func、fabric...)的優勢於一身,能夠實現批量系統配置和程序部署、運行命令等功能。如此優秀,以致於在 2015年被 redhat 收入懷中。Ansible 是基於模塊進行工做的,自己是一個自動化引擎,咱們一般會在 Playbook中用自動化語言定義什麼樣的操做會被執行。通俗的講,Ansible就像是自動演奏的鋼琴,而Playbook是曲譜,而Ansible Tower則是提供UI和Restful API的接口,Ansible 的架構以下:git
想更多的瞭解這個推薦 Jesse Keating 大神的《Mastering Ansible》也歡迎隨時和我討論。<br> 《Mastering Ansible》 by Jesse Keating https://www.ansible.com/resources/ebooks/mastering-ansiblegithub
我建立的 Ansible Playbook 用於 在 Windows Server,(這裏是咱們使用 Windows Server 2019 作爲 VBR 服務器)上安裝與部署 Veeam Backup & Replication Server 9.5 Update 4b,使用 Ansible 實現的 Veeam Backup & Replication Server 的靜默安裝。sql
Veeam有很是優秀的靜默安裝模式,幾乎全部的組件均可以進行自動安裝,這樣用戶就能夠在無人值守的狀況下,進行試大批量的自定義的安裝,對於災備自動化來講也很是有幫助。shell
安裝的順序與模塊以下,詳情請參考,Veeam的官方文檔。 <br> User Guide for VMware vSphere > Deployment > Installing Veeam Backup & Replication in Unattended Mode <br> [《Veeam 靜默安裝 》] (https://helpcenter.veeam.com/docs/backup/vsphere/silent_mode.html?ver=95u4)vim
目前在雲管理模式下, Veeam Backup Enterprise Manager 和 Cloud Connect Portal 都自定義部署,並且一般是多對一模式,在此咱們沒有涉及。windows
此處咱們使用CentOS 7.7 作爲Ansible 服務器,版本以下,咱們只須要進行OS的最小化安裝便可bash
[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
此處爲了簡便,咱們使用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是咱們自動化安裝VBR的服務器。 爲了使 Windows Server 準備授予 WinRM 訪問權限,我使用瞭如下腳本使咱們環境能夠快速的Ready!
ConfigureRemotingForAnsible.ps1 腳本,您能夠前往Ansible社區的Github下載,腳本執行以下 ConfigureRemotingForAnsible.ps1
PS C:\Users\Administrator\Desktop\code> .\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:\Users\Administrator\Desktop\code>
Ansible 從1.7以後的版本支持 Windows服務的管理,管理機仍然須要一臺Linux服務器,通訊方式爲PowerShell,爲了與Windows通訊管理機還需要安裝WinRm模塊,方可和遠程Windows主機正常通訊。
WinRM使用賬戶身份驗證時,可使用幾種不一樣的選項,在這裏我選擇了 NTLM + Ansiable 加密模塊 的方式做爲 WinRM 賬戶身份驗證。<br> <mark>注意:在本文中使用的密碼方式,是經過Ansible 加密作爲密碼傳遞基礎的,您可使用不一樣的選項,如明文密碼。此方法在Hosts文件定義主機時,和在YAML文件中定義Playbook的方法相同。Ansible 加密方法不是本文討論的重點,如關心此處請查看Ansible 手冊 <mark>
選項 | 本地帳戶 | AD帳戶 | 憑據委託 | HTTP 加密 |
---|---|---|---|---|
Basic | 是 | 否 | 否 | 否 |
Certificate | 是 | 否 | 否 | 否 |
Kerberos | 否 | 是 | 是 | 是 |
<mark>NTLM</mark> | 是 | 是 | 否 | 是 |
CredSSP | 是 | 是 | 是 | 是 |
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" }
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
[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:\Users\Administrator> 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:\Users\Administrator> 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 <br> [2.《Ansible 用戶手冊》] (https://https://docs.ansible.com/ansible/2.5/user_guide/quickstart.html) https://www.ansible.com/resources/ebooks/mastering-ansible <br> 3.《Mastering Ansible》 by Jesse Keating https://www.ansible.com/resources/ebooks/mastering-ansible