[comment]: # ({92b4e67d-25de3dba})
# 1 构建可加载插件

[comment]: # ({/92b4e67d-25de3dba})

[comment]: # ({bc1ff65c-55534b94})
### 概述

本页提供从源代码构建可加载插件二进制文件所需的步骤。

如果下载了源代码压缩包，则可以离线构建插件，即无需互联网连接。

以PostgreSQL插件为例，其他可加载插件可以类似方式构建。

[comment]: # ({/bc1ff65c-55534b94})

[comment]: # ({a9697414-10bb98ef})
### 步骤

**1**. 从[Zabbix Cloud Images and Appliances](https://cdn.zabbix.com/zabbix-agent2-plugins/sources/)下载插件源码
官方下载页面即将上线

**2**. 将压缩包传输至准备构建插件的机器

**3**. 解压tar包 例如

    tar xvf zabbix-agent2-plugin-postgresql-6.0.13.tar.gz

请确保将"zabbix-agent2-plugin-postgresql-6.0.13.tar.gz"替换为实际下载的压缩包名称

**4**. 进入解压后的目录

    cd <path to directory>

**5**. 执行

    make

**6**. 插件可执行文件可存放于任意位置 只要能被Zabbix agent 2加载 在插件配置file中指定插件二进制路径 例如PostgreSQL插件的postgresql.conf

    Plugins.PostgreSQL.System.Path=/path/to/executable/zabbix-agent2-plugin-postgresql

**7**. 插件配置file路径必须在Zabbix agent 2配置file的Include参数中指定

    
Include=/path/to/plugin/configuration/file/postgresql.conf

[comment]: # ({/a9697414-10bb98ef})

[comment]: # ({07350bcb-f9fd2647})


### Makefile目标

Zabbix提供的可加载插件包含简单的Makefile文件，支持以下构建目标：

| 构建目标 | 描述 |
|--|--------|
| make   | 编译插件 |
| make clean | 删除构建插件时生成的所有常规文件 |
| make check | 执行自测试（需真实PostgreSQL数据库） |
| make style | 使用'golangci-lint'检查Go代码风格 |
| make format | 使用'go fmt'格式化Go代码 |
| make dist | 创建包含插件源码及所有依赖包源码的归档文件（用于构建插件及其自测试） |

[comment]: # ({/07350bcb-f9fd2647})
