采用docker安装部署.
安装mariadb
docker run --name zabbix-db \
--restart=always \
-e MYSQL_ROOT_PASSWORD='mysql_root_password' \
-e MYSQL_DATABASE=zabbix \
-e MYSQL_USER=zabbix \
-e MYSQL_PASSWORD=zabbix \
-v /usr/local/docker/mariadb/mysql:/var/lib/mysql \
-v /usr/local/docker/mariadb/conf.d:/etc/mysql/conf.d \
-d mariadb --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
制作包含sendEmail的zabbix_server镜像
cat <<EOF | tee ~/Dockerfile
FROM zabbix/zabbix-server-mysql
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories && apk add --no-cache perl-crypt-ssleay perl-io-socket-ssl ca-certificates tzdata && wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz -P /tmp/ && tar xzf /tmp/sendEmail-v1.56.tar.gz -C /tmp/ && rm -f /tmp/sendEmail-v1.56.tar.gz && sed -i "s/SSL_version => 'SSLv3 TLSv1'/SSL_version => 'TLSv1'/g" /tmp/sendEmail-v1.56/sendEmail && mv /tmp/sendEmail-v1.56/sendEmail /usr/bin && chmod +x /usr/bin/sendEmail && rm -rf /tmp/* && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone
EXPOSE 10051/TCP 162/UDP
WORKDIR /var/lib/zabbix
ENTRYPOINT ["docker-entrypoint.sh"]
EOF
docker build -t jfbrother/zabbix-server-mysql:latest .
创建zabbix_server alertscripts目录以及脚本文件
mkdir -p /usr/local/docker/zabbix/alertscripts/
mkdir -p /usr/local/docker/zabbix/externalscripts/
[root@localhost ~]# cat /usr/local/docker/zabbix/alertscripts/sendemail.sh
#!/bin/bash
SMTP_server='smtp.qq.com:587' # SMTP服务器,我用 QQ TLS 的端口。
username='test@qq.com' # 用户名
password='password' # 密码
from_email_address='test@qq.com' # 发件人Email地址
to_email_address="$1" # 收件人Email地址,zabbix传入的第一个参数
message_subject_utf8="$2" # 邮件标题,zabbix传入的第二个参数
message_body_utf8="$3" # 邮件内容,zabbix传入的第三个参数
echo "`date +"%F %T"` send to $to_email_address" >> /tmp/send.log
message_subject="$message_subject_utf8"
# 发送邮件
sendEmail='/usr/bin/sendEmail'
$sendEmail -s "$SMTP_server" -xu "$username" -xp "$password" -f "$from_email_address" -t "$to_email_address" -u "$message_subject_utf8" -m "$message_body_utf8" -o message-content-type=text -o tls=yes -v >> /tmp/send.log
echo $? >> /tmp/send.log
echo "zabbix 参数1 = $1" >> /tmp/send.log
echo "zabbix 参数2 = $2" >> /tmp/send.log
echo "zabbix 参数3 = $3" >> /tmp/send.log
注意: 当zabbix_server无法调用sendemail时, 可能是宿主机与容器内对sendemail.sh的所有者uid不一致导致
# useradd zabbix
# groupadd zabbix
# groupmod -g 1000 zabbix
# usermod -u 100 zabbix
docker run --name zabbix-server \
--link zabbix-db:mysql-server \
--restart=always \
-e MYSQL_USER=zabbix \
-e MYSQL_PASSWORD=zabbix \
-e ZBX_DEBUGLEVEL=5 \
-v /usr/local/docker/zabbix/externalscripts:/usr/lib/zabbix/externalscripts \
-v /usr/local/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts \
-p 10051:10051 \
-d jfbrother/zabbix-server-mysql
制作包含中文字体的zabbix_web
上传 simhei.ttf 到服务器端
cat <<EOF | tee ~/Dockerfile
FROM zabbix/zabbix-web-nginx-mysql
COPY simhei.ttf /usr/share/zabbix/fonts
EXPOSE 80/TCP 443/TCP
WORKDIR /usr/share/zabbix
RUN sed -i 's/graphfont/simhei/g' ./include/defines.inc.php
VOLUME ["/etc/ssl/nginx"]
ENTRYPOINT ["docker-entrypoint.sh"]
EOF
docker build -t jfbrother/zabbix-web-nginx-mysql .
docker run --name zabbix-web \
--link zabbix-db:mysql-server \
--link zabbix-server:zabbix-server \
-e MYSQL_USER=zabbix \
-e MYSQL_PASSWORD=zabbix \
-e PHP_TZ='Asia/Hong_Kong' \
-e ZBX_SERVER_NAME='Jfbrother Monitor' \
-p 80:80 \
--restart=always \
-d jfbrother/zabbix-web-nginx-mysql
导入模板
docker-compose 部署zabbix-server
- 复制docker image到服务器上
# scp jfbrother-zabbix-server-mysql.img zabbix-server.com:/root/
# scp jfbrother-zabbix-web-nginx-mysql.img zabbix-server.com/root/
# docker load < /root/jfbrother-zabbix-server-mysql.img
# docker load < /root/jfbrother-zabbix-web-nginx-mysql.img
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mariadb latest 1d1589f26c3a 8 hours ago 401MB
jfbrother/zabbix-web-nginx-mysql latest e388af16e84f 2 months ago 187MB
jfbrother/zabbix-server-mysql latest 44177e0dfbbe 2 months ago 106MB
- 创建目录
# mkdir -p /usr/local/docker/zabbix/{alertscripts,externalscripts}
# mkdir -p /usr/local/docker/mairadb/{conf.d,mysql}
- 复制zabbix自定义脚本
# scp sendemail.sh sendrequest.sh zabbix-server:/usr/local/docker/zabbix/alertscripts
# chown -R 100:1000 /usr/local/docker/zabbix/
- 编辑compose文件内容
version: '2'
services:
zabbix-db:
restart: always
image: mariadb
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
volumes:
- /usr/local/docker/mariadb/mysql:/var/lib/mysql
- /usr/local/docker/mariadb/conf.d:/etc/mysql/conf.d
environment:
- MYSQL_ROOT_PASSWORD=mysql_root_password
- MYSQL_DATABASE=zabbix
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
zabbix-server:
restart: always
image: jfbrother/zabbix-server-mysql
depends_on:
- zabbix-db
links:
- "zabbix-db:mysql-server"
ports:
- "10051:10051"
volumes:
- /usr/local/docker/zabbix/externalscripts:/usr/lib/zabbix/externalscripts
- /usr/local/docker/zabbix/alertscripts:/usr/lib/zabbix/alertscripts
environment:
- MYSQL_USER=root
- MYSQL_PASSWORD=mysql_root_password
- ZBX_DEBUGLEVEL=5
zabbix-web:
restart: always
image: jfbrother/zabbix-web-nginx-mysql
depends_on:
- zabbix-db
- zabbix-server
links:
- "zabbix-db:mysql-server"
- "zabbix-server:zabbix-server"
ports:
- "8081:80"
environment:
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
- PHP_TZ=Asia/Hong_Kong
- ZBX_SERVER_NAME=JfMonitorPreview
- 启动服务
# docker-compose -f zabbix-compose.yml up -d
zabbix web界面配置监控节点
- 导入jfbrother模板
- 创建已运行zabbix_agentd的被监控节点
- 创建报警媒介
- 关联Admin用户