管理并维护 Windows 和 Linux 的 Log Analytics 代理Managing and maintaining the Log Analytics agent for Windows and Linux

在 Azure Monitor 中初始部署 Log Analytics Windows 或 Linux 代理后,如果代理到达了其生命周期中的停用阶段时,则你可能需要重新配置代理,对其进行更新或者将其从计算机中删除。After initial deployment of the Log Analytics Windows or Linux agent in Azure Monitor, you may need to reconfigure the agent, upgrade it, or remove it from the computer if it has reached the retirement stage in its lifecycle. 可以轻松地手动或自动管理这些日常维护任务,从而减少运行错误并降低费用。You can easily manage these routine maintenance tasks manually or through automation, which reduces both operational error and expenses.

升级代理Upgrading agent

可以根据部署方案和 VM 的运行环境手动或自动将适用于 Windows 和 Linux 的 Log Analytics 代理升级到最新版本。The Log Analytics agent for Windows and Linux can be upgraded to the latest release manually or automatically depending on the deployment scenario and environment the VM is running in. 可以使用以下方法来升级代理。The following methods can be used to upgrade the agent.

环境Environment 安装方法Installation Method 升级方法Upgrade method
Azure VMAzure VM 适用于 Windows/Linux 的 Log Analytics 代理 VM 扩展Log Analytics agent VM extension for Windows/Linux 默认情况下代理会自动升级,除非你通过将 autoUpgradeMinorVersion 属性设置为 false 来将 Azure 资源管理器模板配置为选择退出。Agent is automatically upgraded by default unless you configured your Azure Resource Manager template to opt out by setting the property autoUpgradeMinorVersion to false.
自定义 Azure VM 映像Custom Azure VM images 手动安装适用于 Windows/Linux 的 Log Analytics 代理Manual install of Log Analytics agent for Windows/Linux 将 VM 更新到最新版本的代理需要从命令行运行 Windows 安装程序包或 Linux 自解压和可安装的 shell 脚本包。Updating VMs to the newest version of the agent needs to be performed from the command line running the Windows installer package or Linux self-extracting and installable shell script bundle.
非 Azure VMNon-Azure VMs 手动安装适用于 Windows/Linux 的 Log Analytics 代理Manual install of Log Analytics agent for Windows/Linux 将 VM 更新到最新版本的代理需要从命令行运行 Windows 安装程序包或 Linux 自解压和可安装的 shell 脚本包。Updating VMs to the newest version of the agent needs to be performed from the command line running the Windows installer package or Linux self-extracting and installable shell script bundle.

升级 Windows 代理Upgrade Windows agent

若要将 Windows VM 上的代理更新为未使用 Log Analytics VM 扩展安装的最新版本,可以通过命令提示符、脚本或其他自动化解决方案来运行,也可以使用 MMASetup-<platform>.msi 安装向导。To update the agent on a Windows VM to the latest version not installed using the Log Analytics VM extension, you either run from the Command Prompt, script or other automation solution, or by using the MMASetup-<platform>.msi Setup Wizard.

可以通过执行以下步骤从你的 Log Analytics 工作区下载 Windows 代理的最新版本。You can download the latest version of the Windows agent from your Log Analytics workspace, by performing the following steps.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 在 Azure 门户中,单击“所有服务”。In the Azure portal, click All services. 在资源列表中,键入“Log Analytics”。In the list of resources, type Log Analytics. 开始键入时,会根据输入筛选该列表。As you begin typing, the list filters based on your input. 选择“Log Analytics 工作区”。Select Log Analytics workspaces.

  3. 在 Log Analytics 工作区列表中选择一个工作区。In your list of Log Analytics workspaces, select the workspace.

  4. 在你的 Log Analytics 工作区中,选择“高级设置”,然后选择“连接的源”,最后选择“Windows Server”。In your Log Analytics workspace, select Advanced settings, then select Connected Sources, and finally Windows Servers.

  5. 在“Windows Server”页上,选择“下载 Windows 代理”,根据 Windows 操作系统的处理器体系结构下载相应的版本。 From the Windows Servers page, select the appropriate Download Windows Agent version to download depending on the processor architecture of the Windows operating system.

备注

在升级适用于 Windows 的 Log Analytics 代理期间,不支持配置或重新配置要报告到的工作区。During the upgrade of the Log Analytics agent for Windows, it does not support configuring or reconfiguring a workspace to report to. 若要配置该代理,需要遵循添加或删除工作区下列出的受支持的方法之一。To configure the agent, you need to follow one of the supported methods listed under Adding or removing a workspace.

使用安装向导进行升级To upgrade using the Setup Wizard

  1. 使用具有管理权限的帐户登录到计算机。Sign on to the computer with an account that has administrative rights.

  2. 执行 MMASetup-<platform>.exe 以启动安装向导。Execute MMASetup-<platform>.exe to start the Setup Wizard.

  3. 在安装向导的第一页上,单击“下一步”。On the first page of the Setup Wizard, click Next.

  4. 在“Microsoft Monitoring Agent 安装”对话框中,单击“我同意”以接受许可协议。In the Microsoft Monitoring Agent Setup dialog box, click I agree to accept the license agreement.

  5. 在“Microsoft Monitoring Agent 安装”对话框中,单击“升级”。In the Microsoft Monitoring Agent Setup dialog box, click Upgrade. 状态页面将显示升级进度。The status page displays the progress of the upgrade.

  6. 当“Microsoft Monitoring Agent 配置已成功完成。”When the Microsoft Monitoring Agent configuration completed successfully. 页面出现时,单击“完成”。page appears, click Finish.

从命令行进行升级To upgrade from the command line

  1. 使用具有管理权限的帐户登录到计算机。Sign on to the computer with an account that has administrative rights.

  2. 若要提取代理安装文件,请在提升的命令提示符处运行 MMASetup-<platform>.exe /c,这会提示要将文件提取到的路径。To extract the agent installation files, from an elevated command prompt run MMASetup-<platform>.exe /c and it will prompt you for the path to extract files to. 或者,可以通过传递参数 MMASetup-<platform>.exe /c /t:<Full Path> 来指定路径。Alternatively, you can specify the path by passing the arguments MMASetup-<platform>.exe /c /t:<Full Path>.

  3. 运行以下命令,其中 D:\ 是升级日志文件的位置。Run the following command, where D:\ is the location for the upgrade log file.

    setup.exe /qn /l*v D:\logs\AgentUpgrade.log AcceptEndUserLicenseAgreement=1
    

升级 Linux 代理Upgrade Linux agent

支持从以前的版本 (>1.0.0-47) 进行升级。Upgrade from prior versions (>1.0.0-47) is supported. 使用 --upgrade 命令执行安装时,会将代理的所有组件都升级到最新版本。Performing the installation with the --upgrade command will upgrade all components of the agent to the latest version.

运行以下命令来升级代理。Run the following command to upgrade the agent.

sudo sh ./omsagent-*.universal.x64.sh --upgrade

添加或删除工作区Adding or removing a workspace

Windows 代理Windows agent

如果你不但希望将 Windows 代理重新配置为向另一工作区进行报告或者从其配置中删除某个工作区,而且还要将代理配置为向多个工作区进行报告(通常称为多宿主),则需要执行本部分中的步骤。The steps in this section are necessary when you want to not only reconfigure the Windows agent to report to a different workspace or to remove a workspace from its configuration, but also when you want to configure the agent to report to more than one workspace (commonly referred to as multi-homing). 将 Windows 代理配置为向多个工作区进行报告只能在初始安装代理后使用下述方法执行。Configuring the Windows agent to report to multiple workspaces can only be performed after initial setup of the agent and using the methods described below.

从控制面板更新设置Update settings from Control Panel

  1. 使用具有管理权限的帐户登录到计算机。Sign on to the computer with an account that has administrative rights.

  2. 打开“控制面板”Open Control Panel.

  3. 选择“Microsoft Monitoring Agent”,然后单击“Azure Log Analytics”选项卡 。Select Microsoft Monitoring Agent and then click the Azure Log Analytics tab.

  4. 若要删除工作区,请选中该工作区,然后单击“删除”。If removing a workspace, select it and then click Remove. 如果还需代理停止向任何其他工作区报告,请重复此步骤。Repeat this step for any other workspace you want the agent to stop reporting to.

  5. 若要添加工作区,请单击“添加”,然后在“添加 Log Analytics 工作区”对话框中粘贴工作区 ID 和工作区密钥(主密钥) 。If adding a workspace, click Add and on the Add a Log Analytics Workspace dialog box, paste the Workspace ID and Workspace Key (Primary Key).

  6. 单击“确定”以保存你的更改。Click OK to save your changes.

使用 PowerShell 删除工作区Remove a workspace using PowerShell

$workspaceId = "<Your workspace Id>"
$mma = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg'
$mma.RemoveCloudWorkspace($workspaceId)
$mma.ReloadConfiguration()

使用 PowerShell 在 Azure 商业版中添加工作区Add a workspace in Azure commercial using PowerShell

$workspaceId = "<Your workspace Id>"
$workspaceKey = "<Your workspace Key>"
$mma = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg'
$mma.AddCloudWorkspace($workspaceId, $workspaceKey)
$mma.ReloadConfiguration()

使用 PowerShell 在中国区 Azure 中添加工作区Add a workspace in Azure for China using PowerShell

$workspaceId = "<Your workspace Id>"
$workspaceKey = "<Your workspace Key>"
$mma = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg'
$mma.AddCloudWorkspace($workspaceId, $workspaceKey, 2)
$mma.ReloadConfiguration()

备注

如果以前已使用命令行或脚本安装或配置了代理,EnableAzureOperationalInsights 会被 AddCloudWorkspaceRemoveCloudWorkspace 取代。If you've used the command line or script previously to install or configure the agent, EnableAzureOperationalInsights was replaced by AddCloudWorkspace and RemoveCloudWorkspace.

Linux 代理Linux agent

以下步骤演示了如何重新配置 Linux 代理,以便将其注册到不同的工作区,或者从其配置中删除工作区。The following steps demonstrate how to reconfigure the Linux agent if you decide to register it with a different workspace or to remove a workspace from its configuration.

  1. 若要验证该代理是否已注册到工作区,请运行以下命令:To verify it is registered to a workspace, run the following command:

    /opt/microsoft/omsagent/bin/omsadmin.sh -l

    此命令应返回类似以下示例的状态:It should return a status similar to the following example:

    Primary Workspace: <workspaceId> Status: Onboarded(OMSAgent Running)

    状态中还应显示代理正在运行,这一点非常重要,否则以下重新配置代理的步骤不会成功完成。It is important that the status also shows the agent is running, otherwise the following steps to reconfigure the agent will not complete successfully.

  2. 如果代理已注册到工作区,请运行以下命令删除已注册的工作区。If it is already registered with a workspace, remove the registered workspace by running the following command. 如果未注册,请继续执行下一步。Otherwise if it is not registered, proceed to the next step.

    /opt/microsoft/omsagent/bin/omsadmin.sh -X

  3. 若要注册到不同的工作区,请运行以下命令:To register with a different workspace, run the following command:

    /opt/microsoft/omsagent/bin/omsadmin.sh -w <workspace id> -s <shared key> [-d <top level domain>]

  4. 若要验证更改是否生效,请运行以下命令:To verify your changes took effect, run the following command:

    /opt/microsoft/omsagent/bin/omsadmin.sh -l

    此命令应返回类似以下示例的状态:It should return a status similar to the following example:

    Primary Workspace: <workspaceId> Status: Onboarded(OMSAgent Running)

无需重启代理服务即可使更改生效。The agent service does not need to be restarted in order for the changes to take effect.

更新代理设置Update proxy settings

若要将代理配置为在部署后通过代理服务器或 Log Analytics 网关与服务通信,请使用以下任一方法来完成此任务。To configure the agent to communicate to the service through a proxy server or Log Analytics gateway after deployment, use one of the following methods to complete this task.

Windows 代理Windows agent

使用控制面板更新设置Update settings using Control Panel

  1. 使用具有管理权限的帐户登录到计算机。Sign on to the computer with an account that has administrative rights.

  2. 打开“控制面板”Open Control Panel.

  3. 选择“Microsoft Monitoring Agent”,然后单击“代理设置”选项卡 。Select Microsoft Monitoring Agent and then click the Proxy Settings tab.

  4. 单击“使用代理服务器”,然后提供代理服务器或网关的 URL 和端口号。Click Use a proxy server and provide the URL and port number of the proxy server or gateway. 如果代理服务器或 Log Analytics 网关要求身份验证,请键入用户名和密码进行身份验证,然后单击“确定”。If your proxy server or Log Analytics gateway requires authentication, type the username and password to authenticate and then click OK.

使用 PowerShell 更新设置Update settings using PowerShell

复制以下示例 PowerShell 代码,使用特定于自己环境的信息对其进行更新,并使用 PS1 文件扩展名将其保存。Copy the following sample PowerShell code, update it with information specific to your environment, and save it with a PS1 file name extension. 在直接连接到 Azure Monitor 中的 Log Analytics工作区的每台计算机上运行该脚本。Run the script on each computer that connects directly to the Log Analytics workspace in Azure Monitor.

param($ProxyDomainName="https://proxy.contoso.com:30443", $cred=(Get-Credential))

# First we get the Health Service configuration object. We need to determine if we
#have the right update rollup with the API we need. If not, no need to run the rest of the script.
$healthServiceSettings = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg'

$proxyMethod = $healthServiceSettings | Get-Member -Name 'SetProxyInfo'

if (!$proxyMethod)
{
    Write-Output 'Health Service proxy API not present, will not update settings.'
    return
}

Write-Output "Clearing proxy settings."
$healthServiceSettings.SetProxyInfo('', '', '')

$ProxyUserName = $cred.username

Write-Output "Setting proxy to $ProxyDomainName with proxy username $ProxyUserName."
$healthServiceSettings.SetProxyInfo($ProxyDomainName, $ProxyUserName, $cred.GetNetworkCredential().password)

Linux 代理Linux agent

如果 Linux 计算机需要通过代理服务器或 Log Analytics 网关进行通信,请执行以下步骤。Perform the following steps if your Linux computers need to communicate through a proxy server or Log Analytics gateway. 代理配置值具有以下语法 [protocol://][user:password@]proxyhost[:port]The proxy configuration value has the following syntax [protocol://][user:password@]proxyhost[:port]. proxyhost 属性接受代理服务器的完全限定域名或 IP 地址。The proxyhost property accepts a fully qualified domain name or IP address of the proxy server.

  1. 运行以下命令编辑文件 /etc/opt/microsoft/omsagent/proxy.conf,并针对特定设置更改相关的值。Edit the file /etc/opt/microsoft/omsagent/proxy.conf by running the following commands and change the values to your specific settings.

    proxyconf="https://proxyuser:proxypassword@proxyserver01:30443"
    sudo echo $proxyconf >>/etc/opt/microsoft/omsagent/proxy.conf
    sudo chown omsagent:omiusers /etc/opt/microsoft/omsagent/proxy.conf
    
  2. 运行以下命令重启代理:Restart the agent by running the following command:

    sudo /opt/microsoft/omsagent/bin/service_control restart [<workspace id>]
    

卸载代理Uninstall agent

使用下列过程之一通过命令行或安装向导卸载 Windows 或 Linux 代理。Use one of the following procedures to uninstall the Windows or Linux agent using the command line or setup wizard.

Windows 代理Windows agent

从控制面板卸载Uninstall from Control Panel

  1. 使用具有管理权限的帐户登录到计算机。Sign on to the computer with an account that has administrative rights.

  2. 在“控制面板”中,单击“程序和功能” 。In Control Panel, click Programs and Features.

  3. 在“程序和功能”中依次单击“Microsoft Monitoring Agent”、“卸载”、“是” 。In Programs and Features, click Microsoft Monitoring Agent, click Uninstall, and then click Yes.

备注

还可以通过双击“MMASetup-<platform>.exe”运行代理安装向导,该程序可从 Azure 门户中的工作区下载。The Agent Setup Wizard can also be run by double-clicking MMASetup-<platform>.exe, which is available for download from a workspace in the Azure portal.

从命令行卸载Uninstall from the command line

下载的代理文件是使用 IExpress 创建的独立安装包。The downloaded file for the agent is a self-contained installation package created with IExpress. 代理和支持文件的安装程序包含在该包中,需要提取才能使用以下示例中所示的命令行正确卸载。The setup program for the agent and supporting files are contained in the package and need to be extracted in order to properly uninstall using the command line shown in the following example.

  1. 使用具有管理权限的帐户登录到计算机。Sign on to the computer with an account that has administrative rights.

  2. 若要提取代理安装文件,请在提升的命令提示符处运行 extract MMASetup-<platform>.exe,这会提示要将文件提取到的路径。To extract the agent installation files, from an elevated command prompt run extract MMASetup-<platform>.exe and it will prompt you for the path to extract files to. 或者,可以通过传递参数 extract MMASetup-<platform>.exe /c:<Path> /t:<Path> 来指定路径。Alternatively, you can specify the path by passing the arguments extract MMASetup-<platform>.exe /c:<Path> /t:<Path>. 若要深入了解 IExpress 支持的命令行开关,请参阅 IExpress 的命令行开关,然后根据需要更新示例。For more information on the command-line switches supported by IExpress, see Command-line switches for IExpress and then update the example to suit your needs.

  3. 在提示符下键入 %WinDir%\System32\msiexec.exe /x <Path>:\MOMAgent.msi /qbAt the prompt, type %WinDir%\System32\msiexec.exe /x <Path>:\MOMAgent.msi /qb.

Linux 代理Linux agent

若要删除代理,请在 Linux 计算机上运行以下命令。To remove the agent, run the following command on the Linux computer. --purge 参数可彻底删除代理及其配置。The --purge argument completely removes the agent and its configuration.

wget https://raw.githubusercontent.com/Microsoft/OMS-Agent-for-Linux/master/installer/scripts/onboard_agent.sh && sh onboard_agent.sh --purge

将代理配置为向 Operations Manager 管理组报告Configure agent to report to an Operations Manager management group

Windows 代理Windows agent

执行以下步骤可将适用于 Windows 的 Log Analytics 代理配置为向 System Center Operations Manager 管理组报告。Perform the following steps to configure the Log Analytics agent for Windows to report to a System Center Operations Manager management group.

备注

从 Microsoft Operations Management Suite (OMS) 过渡到 Azure Monitor 期间,Windows 或 Linux 的 OMS 代理称为 Windows 或 Linux 的 Log Analytics 代理。As part of the ongoing transition from Microsoft Operations Management Suite (OMS) to Azure Monitor, the OMS Agent for Windows or Linux will be referred to as the Log Analytics agent for Windows and Log Analytics agent for Linux.

  1. 使用具有管理权限的帐户登录到计算机。Sign on to the computer with an account that has administrative rights.

  2. 打开“控制面板”Open Control Panel.

  3. 单击“Microsoft Monitoring Agent”,然后单击“Operations Manager”选项卡 。Click Microsoft Monitoring Agent and then click the Operations Manager tab.

  4. 如果 Operations Manager 服务器与 Active Directory 集成,请单击“自动更新 AD DS 中的管理组分配”。If your Operations Manager servers have integration with Active Directory, click Automatically update management group assignments from AD DS.

  5. 单击“添加”以打开“添加管理组”对话框。Click Add to open the Add a Management Group dialog box.

  6. 在“管理组名称”字段,键入管理组的名称。In Management group name field, type the name of your management group.

  7. 在“主管理服务器”字段,键入主管理服务器的计算机名。In the Primary management server field, type the computer name of the primary management server.

  8. 在“管理服务器端口”字段,键入 TCP 端口号。In the Management server port field, type the TCP port number.

  9. 在“代理操作帐户”下面,选择本地系统帐户或本地域帐户。Under Agent Action Account, choose either the Local System account or a local domain account.

  10. 单击“确定”关闭“添加管理组”对话框中,再单击“确定”关闭“Microsoft Monitoring Agent 属性”对话框。Click OK to close the Add a Management Group dialog box and then click OK to close the Microsoft Monitoring Agent Properties dialog box.

Linux 代理Linux agent

执行以下步骤可将适用于 Linux 的 Log Analytics 代理配置为向 System Center Operations Manager 管理组报告。Perform the following steps to configure the Log Analytics agent for Linux to report to a System Center Operations Manager management group.

备注

从 Microsoft Operations Management Suite (OMS) 过渡到 Azure Monitor 期间,Windows 或 Linux 的 OMS 代理称为 Windows 或 Linux 的 Log Analytics 代理。As part of the ongoing transition from Microsoft Operations Management Suite (OMS) to Azure Monitor, the OMS Agent for Windows or Linux will be referred to as the Log Analytics agent for Windows and Log Analytics agent for Linux.

  1. 编辑 /etc/opt/omi/conf/omiserver.confEdit the file /etc/opt/omi/conf/omiserver.conf

  2. 确保以 httpsport= 开头的行定义了端口 1270。Ensure that the line beginning with httpsport= defines the port 1270. 例如:httpsport=1270Such as: httpsport=1270

  3. 重新启动 OMI 服务器:sudo /opt/omi/bin/service_control restartRestart the OMI server: sudo /opt/omi/bin/service_control restart

后续步骤Next steps