Cách dùng winrm trên windows
Windows Remote Management (WinRM) là gì? Đây là một thuật ngữ Kỹ thuật và công nghệ
Show
Windows Remote Management (WinRM) là Windows Remote Management (WinRM). Đây là nghĩa tiếng Việt của thuật ngữ Windows Remote Management (WinRM) - một thuật ngữ thuộc nhóm Technology Terms - Công nghệ thông tin. Độ phổ biến(Factor rating): 5/10 Windows Remote Management (WinRM) là một tiện ích xuất xưởng với Windows Vista cho phép người quản trị hệ thống để chạy các kịch bản quản lý từ xa. kết nối từ xa được quản lý từ xa bằng cách sử dụng giao thức WS-Management, được xây dựng trên SOAP (Simple Object Access Protocol). WinRM cho phép phần cứng và hệ điều hành khác nhau từ các nhà cung cấp khác nhau để tương thích từ xa. Thuật ngữ Windows Remote Management (WinRM)
Đây là thông tin Thuật ngữ Windows Remote Management (WinRM) theo chủ đề được cập nhập mới nhất năm 2022. Thuật ngữ Windows Remote Management (WinRM)Trên đây là thông tin giúp bạn hiểu rõ hơn về Thuật ngữ Windows Remote Management (WinRM). Hãy truy cập tudienso.com để tra cứu thông tin các thuật ngữ chuyên ngành tiếng Anh, Trung, Nhật, Hàn...liên tục được cập nhập. Windows Remote Management (WinRM) là Windows Remote Management (WinRM). Đây là nghĩa tiếng Việt của thuật ngữ Windows Remote Management (WinRM) - một thuật ngữ
thuộc nhóm Technology Terms - Công nghệ thông tin. Windows Remote Management (WinRM) là một tiện ích xuất xưởng với Windows Vista cho phép người quản trị hệ thống để chạy các kịch bản quản lý từ xa. kết nối từ xa được quản lý từ xa bằng cách sử dụng giao thức WS-Management, được xây dựng trên SOAP (Simple Object Access Protocol). WinRM cho phép phần cứng và hệ điều hành khác nhau từ các nhà
cung cấp khác nhau để tương thích từ xa. Windows Remote Management cho phép quản trị mạng để truy cập, thao tác và tìm kiếm dữ liệu từ cả hai máy tính cục bộ và từ xa. Điều này có thể ngay cả khi phần cứng và các hệ điều hành từ các nhà cung cấp khác nhau kể từ khi giao thức có thể được thực hiện trên hệ điều hành Windows không như Linux.
WinRM cho phép quản trị dữ liệu từ xa thu thập từ hệ thống khác nhau và kết hợp chúng và đặt chúng ở một vị trí trung tâm trên một máy tính hoặc máy chủ. WinRM đảm bảo sự riêng tư thông qua mã hóa và xác thực khi đăng nhập. Windows Remote Management (WinRM) is a utility shipped with Windows Vista that allows system administrators to run management scripts remotely. Remote connections are remotely managed using the
WS-Management protocol, which is built on SOAP (Simple Object Access Protocol). WinRM allows different hardware and operating systems from different vendors to interoperate remotely. Windows Remote Management allows network administrators to access, manipulate and search data from both local and remote computers. This is possible even if the hardware and operating systems are from different vendors since the protocol can be
implemented on non-Windows operating systems such as Linux. WinRM allows an administrator to remotely collect data from various systems and combine them and place them in a central location on a computer or server. WinRM ensures privacy through encryption and authentication when logging in. Source: Windows Remote Management (WinRM) là gì? Technology Dictionary - Filegi - Techtopedia - Techterm
Giới thiệuAnsible là một công cụ quản lý cấu hình mạnh mẽ và tiện dụng. Ansible sử dụng giao thức SSH để kết nối và quản lý các máy khác. Thế nhưng, trên Windows lại không có SSH (Microsoft dự kiến sẽ tích hợp sẵn OpenSSH vào Windows trong tương lai, nhưng chưa phải bây giờ :))) ). Vậy nên, ta cần phải sử dụng WinRM, một tính năng của Windows để cho phép Ansible quản trị từ xa. WinRM WinRM là giao thức quản trị từ xa (windows remote management) được Microsoft phát triển dành cho các hệ điều hành Windows. Giao thức này cho phép người dùng quản trị các máy Windows từ xa qua HTTP/HTTPS. Từ phiên bản Windows Server 2012, WinRM được bật sẵn, nhưng để giao tiếp được với Ansible thì ta cần phải cấu hình thêm kha khá mới chạy được (và chạy an toàn). Có thể dùng key SSH để kết nối không? Việc quản trị các host windows từ xa được thực hiện qua giao thức WinRM (Windows Remote Management). WinRM hỗ trợ nhiều phương pháp chứng thực khác nhau (coi bảng bên dưới). Gần giống với SSH Key là Phương pháp chứng thực bằng certificate X509 dựa trên cặp certificate – private key (coi cụ thể hơn trong phần cài đặt). Môi trường yêu cầuTrong bài viết này, mình sẽ hướng dẫn cấu hình Ansible quản trị Windows cho môi trường WorkGroup, sử dụng certificate – private key để kết nối. Nếu có thời gian, mình sẽ bổ sung thêm cách cấu hình trong môi trường Domain. Người viết thử nghiệm trên CentOS 7 và Windows Server 2012 R2 Standard Linux – Controller
Windows – Slaves
Nếu phiên bản Windows của bạn là 2008 trở về trước, có thể upgrade phiên bản PowerShell trong máy bằng cách sau, mở PowerShell trên Windows dưới quyền Administrator và gõ những lệnh sau: $url = "https://raw.githubusercontent.com/jborean93/ansible-windows/master/scripts/Upgrade-PowerShell.ps1" $file = "$env:temp\Upgrade-PowerShell.ps1" $username = "Administrator" $password = "PasswordCuaBan" (New-Object -TypeName System.Net.WebClient).DownloadFile($url, $file) Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force # Chon version 3.0, 4.0 hoac 5.1, tot nhat la ban 4.0 tro len &$file -Version 5.1 -Username $username -Password $password -Verbose # Tat tinh nang thuc thi script Set-ExecutionPolicy -ExecutionPolicy Restricted -Force $reg_winlogon_path = "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" Set-ItemProperty -Path $reg_winlogon_path -Name AutoAdminLogon -Value 0 Remove-ItemProperty -Path $reg_winlogon_path -Name DefaultUserName -ErrorAction SilentlyContinue Remove-ItemProperty -Path $reg_winlogon_path -Name DefaultPassword -ErrorAction SilentlyContinue Chú ý: Để đảm bảo an toàn, cần setup một đường mạng Private để Ansible liên lạc với các máy Windows. Không nên quản trị các máy này qua đường mạng Public. Cài đặtCài đặt Ansible trên Linux Controller Ansible dùng gói pywinrm để tương tác với các máy chạy Windows thông qua giao thức WinRM. Set up Ansible trên Linux khá đơn giản, ta dùng những lệnh sau: sudo yum install -y epel-release sudo yum install ansible sudo yum install python-pip sudo pip install "pywinrm>=0.3.0" Sau khi đã cài đặt xong, ta cần phải tạo cặp certificate – private key, ta sẽ đặt file certificate trên các host Windows (tương tự như public key). Điều chỉnh username thành user Admin local chạy trên máy windows, sau đó chạy script sau để tạo cặp key: # set the name of the local user that will have the key mapped to # This is the local admin user on windows hosts USERNAME="userAdminLocal" cat > openssl.conf << EOL distinguished_name = req_distinguished_name [req_distinguished_name] [v3_req_client] extendedKeyUsage = serverAuth subjectAltName = otherName:1.3.6.1.4.1.311.20.2.3;UTF8:[email protected] EOL export OPENSSL_CONF=openssl.conf openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -out cert.pem -outform PEM -keyout cert_key.pem -subj "/CN=$USERNAME" -extensions v3_req_client rm openssl.conf Trong folder /etc/ansible, tạo folder group_vars, trong folder này, tạo file windows, chứa thông tin private key dùng để kết nối tới Windows --- ansible_port: 5986 ansible_connection: winrm ansible_winrm_cert_pem: /etc/ansible/certs/cert.pem ansible_winrm_cert_key_pem: /etc/ansible/certs/cert_key.pem ansible_winrm_transport: certificate ansible_winrm_server_cert_validation: ignore Tiếp theo, điều chỉnh file /etc/ansible/hosts như sau: [windows:children] #win-* win-test win-db [win-test] 10.10.10.15 10.10.10.16 [win-db] 10.10.10.123 10.10.10.124 [windows:children] có nghĩa là những group win-test, win-db sẽ kế thừa các thuộc tính được cấu hình trong /etc/ansible/group_vars/windows. Sau này khi cần tạo thêm group mới, ta chỉ cần add thêm vô mục [windows:childern] là được. Cài đặt trên các host chạy Windows Cấu hình trên các host windows khá đơn giản nếu có AD (không có AD thì phải làm tay từng con, hơi mệt). Các bạn tải về bộ script mình đã soạn sẵn ở đây: GitHub Các bước làm tuần tự:
Sau khi cài đặt xong, ta đứng trên máy Controller, gõ lệnh sau để kiểm tra khả năng kết nối tới các máy Windows [[email protected]]# ansible win-test -m win_ping 10.10.10.16 | SUCCESS => { "changed": false, "ping": "pong" } 10.10.10.15 | SUCCESS => { "changed": false, "ping": "pong" } Một số lỗi thường gặp khi cấu hình WinRMSau đây là một số lỗi thường gặp khi cấu hình WinRM:
Một số tùy chọn chứng thực của WinRMỞ trên là hướng dẫn chạy script nhanh gọn lẹ, còn mục dưới đây là dành cho bạn nào cần tìm hiểu thêm về các tùy chọn chứng thực của Ansible. Khi giao tiếp giữa Ansible và WinRM, ta cần chọn một chuẩn chứng thực để 2 bên kết nối được với nhau (như dùng password, certificate, Kerberos…). Ta chọn loại giao thức chứng thực cho Ansible bằng biến ansible_winrm_transport Các giao thức chứng thực được hỗ trợ:
Basiclà giao thức chứng thực đơn giản, chỉ dùng username/password. Đây cũng là giao thức kém bảo mật nhất, dữ liệu nếu truyền qua HTTP thì có thể dễ dàng bị bẻ khóa. Chỉ hỗ trợ chứng thực bằng Local Account trên từng máy. Dùng cho môi trường Test/Dev, KHÔNG DÙNG CHO MÔI TRƯỜNG PRODUCTION Cấu hình trên Ansible ansible_user: LocalUsername ansible_password: PasswordLocalUser ansible_connection: winrm ansible_winrm_transport: basic Cấu hình trên Windows Giao thức này mặc định là tắt, để bật lên thì ta dùng lệnh sau: Set-Item -Path WSMan:\localhost\Service\Auth\Basic -Value $true CertificateĐây là cách chứng thực dùng cặp certificate – private key, tương tự như dùng SSH key pair trên linux. Tuy nhiên format file và quá trình tạo key có chút khác biệt. Cấu hình trên Ansible ansible_connection: winrm ansible_winrm_cert_pem: /path/to/certificate/public/key.pem ansible_winrm_cert_key_pem: /path/to/certificate/private/key.pem ansible_winrm_transport: certificate Cấu hình trên Windows Giao thức này mặc định là tắt, để bật lên thì ta dùng lệnh sau: Set-Item -Path WSMan:\localhost\Service\Auth\Certificate -Value $true Một số thao tác cần nắm thêmLấy thông tin về WinRM winrm get winrm/config winrm get winrm/config/Service winrm get winrm/config/Winrs Lấy thông tin về WinRM Listener winrm e winrm/config/Listener Xóa WinRM Listener # remove all listeners Remove-Item -Path WSMan:\localhost\Listener\* -Recurse -Force # only remove listeners that are run over HTTPS Get-ChildItem -Path WSMan:\localhost\Listener | Where-Object { $_.Keys -contains "Transport=HTTPS" } | Remove-Item -Recurse -Force Một số ứng dụngTriển khai phần mềm hàng loạtHiện mình biết là có một giải pháp của Microsoft là SCCM (System Center Configuration Manager). Tham khảo tại đây: https://cloudcraft.info/gioi-thieu-sccm/ Thực sự thì không phải ai cũng đủ tiền để chơi với Microsoft cả. Đối với những hệ thống chỉ cõ 100~200 server Windows đổ lại, ta có thể dùng Ansible để quản lý việc cài đặt phần mềm này. Có 2 cách để deploy phần mềm trên Windows thông qua Ansible
Đồng bộ cấu hình firewallSếp: “Em chặn port SMB trên mấy con Windows để ngừa ransomware nhé” Nhân viên: “Dạ anh, bao nhiêu con vậy anh?” Sếp: “100 con thôi em” Nhân viên: “….” => Dùng Ansible Tạm kếtỞ bài viết sau, mình sẽ hướng dẫn các bạn sử dụng playbook/ad-hoc command để chạy các tác vụ quản lý cho Windows như:
Link bài 2: Quản trị Windows bằng Ansible-Playbook Tham khảohttp://docs.ansible.com/ansible/latest/user_guide/windows_setup.html |