打算入坑zabbix,尝试部署是第一步,为了简单期间,选择设备安装Centos 7.5,采用docker方式开始部署最新的zabbix4.4
docker方式
准备环境
- 安装docker
- 安装docker-compose
- 选择zabbix的docker镜像类型,推荐底层系统alpine,web服务nginx,数据库postgreSQL,其他选项详见dockerhub
docker-compose配置
可以在github1上寻找对应的docker-compose配置,下面为自己使用的,仅作参考
version: '2'
services:
zabbix-server:
image: zabbix/zabbix-server-pgsql:alpine-4.4-latest
ports:
- "10051:10051"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts:ro
- ./zbx_env/usr/lib/zabbix/externalscripts:/usr/lib/zabbix/externalscripts:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
- ./zbx_env/var/lib/zabbix/mibs:/var/lib/zabbix/mibs:ro
volumes_from:
- zabbix-snmptraps:ro
links:
- pgsql-server:pgsql-server
- zabbix-java-gateway:zabbix-java-gateway
ulimits:
nproc: 65535
nofile:
soft: 20000
hard: 40000
mem_limit: 512m
restart: always
env_file:
- .env_db_pgsql
- .env_srv
networks:
- zabbix-net
zabbix-web-nginx-pgsql:
image: zabbix/zabbix-web-nginx-pgsql:alpine-4.4-latest
ports:
- "80:80"
- "8000:80"
- "8443:443"
links:
- pgsql-server:pgsql-server
- zabbix-server:zabbix-server
mem_limit: 512m
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro
- ./simkai.ttf:/usr/share/zabbix/assets/fonts/DejaVuSans.ttf:ro
env_file:
- .env_db_pgsql
- .env_web
depends_on:
- zabbix-server
- pgsql-server
networks:
- zabbix-net
zabbix-agent:
image: zabbix/zabbix-agent2:latest
ports:
- "10050:10050"
volumes:
- /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro
- ./zbx_env/etc/zabbix/zabbix_agentd.d:/etc/zabbix/zabbix_agentd.d:ro
- ./zbx_env/var/lib/zabbix/modules:/var/lib/zabbix/modules:ro
- ./zbx_env/var/lib/zabbix/enc:/var/lib/zabbix/enc:ro
- ./zbx_env/var/lib/zabbix/ssh_keys:/var/lib/zabbix/ssh_keys:ro
links:
- zabbix-server:zabbix-server
env_file:
- .env_agent2
privileged: true
pid: "host"
networks:
- zabbix-net
zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:alpine-4.4-latest
ports:
- "10052:10052"
env_file:
- .env_java
networks:
- zabbix-net
zabbix-snmptraps:
image: zabbix/zabbix-snmptraps:alpine-4.4-latest
ports:
- "162:162/udp"
volumes:
- ./zbx_env/var/lib/zabbix/snmptraps:/var/lib/zabbix/snmptraps:rw
networks:
- zabbix-net
pgsql-server:
image: postgres:11
volumes:
- ./zbx_env/var/lib/postgresql/data:/var/lib/postgresql/data
env_file:
- .env_db_pgsql
restart: always
networks:
- zabbix-net
networks:
zabbix-net:
ipam:
config:
- subnet: 172.16.66.0/24
gateway: 172.16.66.1
.env_srv
# ZBX_LISTENIP=
# ZBX_HISTORYSTORAGEURL=http://elasticsearch:9200/ # Available since 3.4.5
# ZBX_HISTORYSTORAGETYPES=uint,dbl,str,log,text # Available since 3.4.5
# ZBX_DEBUGLEVEL=3
# ZBX_STARTPOLLERS=5
# ZBX_IPMIPOLLERS=0
# ZBX_STARTPREPROCESSORS=3 # Available since 3.4.0
# ZBX_STARTPOLLERSUNREACHABLE=1
# ZBX_STARTTRAPPERS=5
# ZBX_STARTPINGERS=1
# ZBX_STARTDISCOVERERS=1
# ZBX_STARTHTTPPOLLERS=1
# ZBX_STARTTIMERS=1
# ZBX_STARTESCALATORS=1
# ZBX_STARTALERTERS=3 # Available since 3.4.0
ZBX_JAVAGATEWAY_ENABLE=true
# ZBX_JAVAGATEWAY=zabbix-java-gateway
# ZBX_JAVAGATEWAYPORT=10052
ZBX_STARTJAVAPOLLERS=5
ZBX_STARTVMWARECOLLECTORS=6
ZBX_VMWAREFREQUENCY=60
ZBX_VMWAREPERFFREQUENCY=60
ZBX_VMWARECACHESIZE=8M
ZBX_VMWARETIMEOUT=10
ZBX_ENABLE_SNMP_TRAPS=true
# ZBX_SOURCEIP=
# ZBX_HOUSEKEEPINGFREQUENCY=1
# ZBX_MAXHOUSEKEEPERDELETE=5000
# ZBX_SENDERFREQUENCY=30
# ZBX_CACHESIZE=8M
# ZBX_CACHEUPDATEFREQUENCY=60
# ZBX_STARTDBSYNCERS=4
# ZBX_HISTORYCACHESIZE=16M
# ZBX_HISTORYINDEXCACHESIZE=4M
# ZBX_TRENDCACHESIZE=4M
# ZBX_VALUECACHESIZE=8M
# ZBX_TIMEOUT=4
# ZBX_TRAPPERIMEOUT=300
# ZBX_UNREACHABLEPERIOD=45
# ZBX_UNAVAILABLEDELAY=60
# ZBX_UNREACHABLEDELAY=15
# ZBX_LOGSLOWQUERIES=3000
# ZBX_STARTPROXYPOLLERS=1
# ZBX_PROXYCONFIGFREQUENCY=3600
# ZBX_PROXYDATAFREQUENCY=1
# ZBX_LOADMODULE="dummy1.so,dummy2.so,dummy10.so"
# ZBX_TLSCAFILE=
# ZBX_TLSCRLFILE=
# ZBX_TLSCERTFILE=
# ZBX_TLSKEYFILE=
.env_web
ZBX_SERVER_HOST=zabbix-server
ZBX_SERVER_PORT=10051
ZBX_SERVER_NAME=Composed installation
# ZBX_HISTORYSTORAGEURL=http://elasticsearch:9200/ # Available since 3.4.5
# ZBX_HISTORYSTORAGETYPES=['uint', 'dbl', 'str', 'text', 'log'] # Available since 3.4.5
ZBX_MAXEXECUTIONTIME=600
ZBX_MEMORYLIMIT=128M
ZBX_POSTMAXSIZE=16M
ZBX_UPLOADMAXFILESIZE=2M
ZBX_MAXINPUTTIME=300
# Timezone one of: http://php.net/manual/en/timezones.php
PHP_TZ=Asia/Shanghai
.env_db_pgsql
DB_SERVER_HOST=pgsql-server
DB_SERVER_PORT=5432
# POSTGRES_USER=zabbix
POSTGRES_USER=zabbix
# POSTGRES_PASSWORD=zabbix
POSTGRES_PASSWORD=zabbix
# POSTGRES_ROOT_PASSWORD=
POSTGRES_ROOT_PASSWORD=root_pwd
# POSTGRES_ALLOW_EMPTY_PASSWORD=false
# POSTGRES_DATABASE=zabbix
POSTGRES_DATABASE=zabbix
.env_agent
# ZBX_SOURCEIP=
# ZBX_DEBUGLEVEL=3
# ZBX_ENABLEREMOTECOMMANDS=0
# ZBX_LOGREMOTECOMMANDS=0
ZBX_SERVER_HOST=zabbix-server
# ZBX_PASSIVE_ALLOW=true
# ZBX_PASSIVESERVERS=
# ZBX_ACTIVE_ALLOW=true
# ZBX_ACTIVESERVERS=
# ZBX_LISTENIP=
# ZBX_STARTAGENTS=3
ZBX_HOSTNAME=zabbix-server
# ZBX_HOSTNAMEITEM=system.hostname
# ZBX_METADATA=
# ZBX_METADATAITEM=
# ZBX_REFRESHACTIVECHECKS=120
# ZBX_BUFFERSEND=5
# ZBX_BUFFERSIZE=100
# ZBX_MAXLINESPERSECOND=20
# ZBX_ALIAS=""
# ZBX_TIMEOUT=3
# ZBX_UNSAFEUSERPARAMETERS=0
# ZBX_LOADMODULE="dummy1.so,dummy2.so,dummy10.so"
# ZBX_TLSCONNECT=unencrypted
# ZBX_TLSACCEPT=unencrypted
# ZBX_TLSCAFILE=
# ZBX_TLSCRLFILE=
# ZBX_TLSSERVERCERTISSUER=
# ZBX_TLSSERVERCERTSUBJECT=
# ZBX_TLSCERTFILE=
# ZBX_TLSKEYFILE=
# ZBX_TLSPSKIDENTITY=
# ZBX_TLSPSKFILE=
简单docker命令
在zabbix对应的dockerfile.yaml文件夹下,启动容器
docker-compose up -d
关闭容器
docker-compose stop
配置中数据已经在本地持久化,可以查看对应的./zbx_env/var/lib/postgresql/data
目录,重启容器不影响之前的配置.
查看容器
docker-compose ps
具体状态
docker ps
查看日志
docker-compose logs zabbix-server
其他
图表中文字体
系统中自带的DejaVuSans
字体在显示中文时会显示为小方框,影响使用,需要替换字体即可。
zabbix在4.2版本开始更换了字体目录,详见/usr/share/zabbix/include/defines.inc.php
中
define('ZBX_FONTPATH', realpath('assets/fonts')); // where to search for font (GD > 2.0.18)
define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
define('ZBX_GRAPH_LEGEND_HEIGHT', 120); // when graph height is less then this value, some legend will not show up
由于默认文件中字体名为DejaVuSans,只需要将docker-compose.yaml文件中web中加入字体文件的映射:
- ./zbx_env/etc/ssl/nginx:/etc/ssl/nginx:ro
- ./simkai.ttf:/usr/share/zabbix/assets/fonts/DejaVuSans.ttf:ro
simkai.ttf为需要替换的字体,如果web已启动,只需要重建web容器就可生效(删除原容器,重新启动,只删除web容器不影响监控)。另修改yaml文件时留意空格缩进。
网段冲突
使用docker方式特别留意监控目标是172开头的私有地址段,需要查看下是否docker的地址段一致,docker默认使用172开头的16位掩码的地址段,如果监控目标ip也属于这个地址段,根据路由规则,就会在docker网络中,根本无法访问外部的监控目标,需要更改docker网桥地址。
docker平台物理环境
监控平台最好选择一台性能不错且稳定的机器,之前在测试环境中,选择一台品牌pc,内存4g,感觉有些性能不足,于是打算扩展内存,增加一条DDR3 4g(主频1600MHz),形成双通道,开机识别正常。
之后,发现zabbix-server、pgsql等容器经常宕掉,没有征兆,自动重启也异常,docker方式部署的ebk中kibana也异常无法启动,甚是诡异。想到增加过内存条,于是更换一条内存,不组成双通道,重启,发现机器运行流畅,docker容器也正常。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。