docker部署zabbix
docker pull mysql:5.7
docker pull zabbix/zabbix-server-mysql:centos-latest
docker pull zabbix/zabbix-web-nginx-mysql:latest
docker pull zabbix/zabbix-java-gateway:latest
docker network create -d bridge zabbix_net
docker run -dit -p 3306:3306 --name zabbix-mysql --network zabbix_net --restart always -v /etc/localtime:/etc/localtime -e MYSQL_DATABASE
="zabbix" -e MYSQL_USER
="zabbix" -e MYSQL_PASSWORD
="zabbix123" -e MYSQL_ROOT_PASSWORD
="root123" mysql:5.7
docker run -v /etc/localtime:/etc/localtime -dit --restart
=always --name
=zabbix-java-gateway --network zabbix_net zabbix/zabbix-java-gateway:latest
docker volume create zabbix-server-vol
docker run -dit -p 10051:10051 --mount source
=zabbix-server-vol,target
=/etc/zabbix -v /etc/localtime:/etc/localtime -v /usr/lib/zabbix/alertscripts:/usr/lib/zabbix/alertscripts --name
=zabbix-server-mysql --restart
=always --network zabbix_net -e DB_SERVER_HOST
="zabbix-mysql" -e MYSQL_DATABASE
="zabbix" -e MYSQL_USER
="zabbix" -e MYSQL_PASSWORD
="zabbix123" -e MYSQL_ROOT_PASSWORD
="root123" -e ZBX_JAVAGATEWAY
="zabbix-java-gateway" zabbix/zabbix-server-mysql:centos-latest
docker run -dit -p 8080:8080 -v /etc/localtime:/etc/localtime --name zabbix-web-nginx-mysql --restart
=always --network zabbix_net -e DB_SERVER_HOST
="zabbix-mysql" -e MYSQL_DATABASE
="zabbix" -e MYSQL_USER
="zabbix" -e MYSQL_PASSWORD
="zabbix123" -e MYSQL_ROOT_PASSWORD
="root123" -e ZBX_SERVER_HOST
="zabbix-server-mysql" zabbix/zabbix-web-nginx-mysql:latest
部署成功,在浏览器中输入http://IP(:8080)/zabbix,打开zabbix首页,其中用户名密码分别是admin/zabbix。
创建监控项以及触发器
创建新的应用集 创建监控项 创建触发器 使用py脚本发送报警信息到企业微信,所以需要有python环境。
自定义微信报警
安装python环境
docker
exec -it --user root zabbix-server-mysql /bin/bash
yum -y groupinstall
"Development tools"
yum -y
install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
yum
install -y libffi-devel zlib1g-dev
yum
install zlib* -y
yum -y
install wget
wget wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
tar -xvJf Python-3.7.2.tar.xz
mkdir /usr/local/python3
cd Python-3.7.2
./configure --prefix
=/usr/local/python3 --enable-optimizations --with-ssl
make && make install
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
python3 -V
pip3 -V
whereis python3
python3: /usr/lib/python3.6 /usr/lib64/python3.6 /usr/local/bin/python3 /usr/include/python3.6m
/usr/local/python3
/usr/local/bin/python3 -V
Python 3.7.2
ln -s /usr/local/bin/python3 /usr/bin/python
python -V
Python 3.7.2
grep -Ev
'^$|#' /etc/zabbix/zabbix_server.conf
LogFile
=/var/log/zabbix/zabbix_server.log
LogFileSize
=0
PidFile
=/var/run/zabbix/zabbix_server.pid
SocketDir
=/var/run/zabbix
DBHost
=localhost
DBName
=zabbix
DBUser
=zabbix
DBPassword
=123456
SNMPTrapperFile
=/var/log/snmptrap/snmptrap.log
Timeout
=4
AlertScriptsPath
=/usr/lib/zabbix/alertscripts
ExternalScripts
=/usr/lib/zabbix/externalscripts
LogSlowQueries
=3000
cd /usr/lib/zabbix/alertscripts
chmod +x weixin_alarm.py
vim weixin_alarm.py
:set ff
:set ff
=unix
:wq
相关报错:
使用pip3安装软件报错:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
解决办法:
首先安装 openssl-devel
sudo yum install openssl-devel
进入python安装包,重新编译
cd Python-3.7.2
./configure --prefix=/usr/local/python3 --enable-optimizations --with-ssl
make && make install
Traceback
(most recent call last
):
File
"/usr/lib/zabbix/alertscripts/weixin_alarm.py", line 28,
in <module
>
filemode
= 'a'
File
"/usr/local/lib/python3.7/logging/__init__.py", line 1900,
in basicConfig
h
= FileHandler
(filename, mode
)
File
"/usr/local/lib/python3.7/logging/__init__.py", line 1092,
in __init__
StreamHandler.__init__
(self, self._open
())
File
"/usr/local/lib/python3.7/logging/__init__.py", line 1121,
in _open
return open
(self.baseFilename, self.mode, encoding
=self.encoding
)
PermissionError:
[Errno 13
] Permission denied:
'/tmp/weixin.log'
解决:
cd /tmp
chown zabbix:zabbix weixin.log
cd /usr/lib/zabbix/alertscripts
chown zabbix:zabbix weixin_alarm.py
配置微信报警类型
创建媒体类型:
修改时间显示问题
docker
exec -it zabbix-web-nginx-mysql /bin/bash
find / -name zabbix.conf
/etc/php7/php-fpm.d/zabbix.conf
vi /etc/php7/php-fpm.d/zabbix.conf
php_value
[date.timezone
] = Asia/Shanghai
logstash相关配置
version:
'3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
hostname: elasticsearch
container_name: elasticsearch
restart: always
environment:
-
'ES_JAVA_OPTS=-Xms1g -Xmx1g'
ulimits:
memlock:
soft: -1
hard: -1
nofile:
soft: 65536
hard: 65536
volumes:
- ./elasticsearch/data:/usr/share/elasticsearch/data
- ./elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ./elasticsearch/logs:/user/share/elasticsearch/logs
ports:
- 9200:9200
- 9300:9300
networks:
- esnet
kibana:
image: docker.elastic.co/kibana/kibana:7.1.1
hostname: kibana
container_name: kibana
restart: always
volumes:
- ./kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
ports:
- 5601:5601
networks:
- esnet
depends_on:
- elasticsearch
logstash:
image: docker.elastic.co/logstash/logstash:7.1.1
hostname: logstash
container_name: logstash
restart: always
volumes:
- ./logstash/config:/usr/share/logstash/config
- ./logstash/pipeline:/usr/share/logstash/pipeline
ports:
- 5044:5044
- 19009:8080
environment:
LS_JAVA_OPTS:
'-Xmx512m -Xms512m'
networks:
- esnet
depends_on:
- elasticsearch
networks:
esnet:
http.host:
"0.0.0.0"
- pipeline.id: main
pipeline.workers: 1
path.config:
"/usr/share/logstash/pipeline/logstash.conf"
- pipeline.id: logout_to_zabbix
pipeline.workers: 1
path.config:
"/usr/share/logstash/pipeline/logout_to_zabbix.conf"
input
{
kafka
{
bootstrap_servers
=> "xx.xx.xx.xx:xxxx"
topics
=> "_system_log_collect"
group_id
=> "zabbix_logs"
codec
=> "json"
}
}
filter
{
json
{
source => "_source"
}
mutate
{
add_field
=>["[zabbix_key]",
"oslogs1"]
add_field
=>["[zabbix_host]",
"Zabbix server"]
add_field
=> ["parsed_message",
"from %{[container][name]}, %{[fields][server]} message: %{[message]}"]
}
}
output
{
if ("error" in [message
] or
"ERROR" in [message
] or
"ERR" in [message
] or
"Failed" in [message
]) and
"接口调用异常" not
in [message
] {
zabbix
{
zabbix_host
=> "[zabbix_host]"
zabbix_key
=> "[zabbix_key]"
zabbix_server_host
=> "xxx.xxx.xxx.xxx"
zabbix_server_port
=> "10051"
zabbix_value
=> "parsed_message"
}
}
}
logstash中安装logstash-output-zabbix插件
docker
exec -it logstash /bin/bash
/usr/share/logstash/bin/logstash-plugin
install logstash-output-zabbix
Validating logstash-output-zabbix
Installing logstash-output-zabbix
Installation successful
input
{
stdin
{
type => "stdin"
}
}
output
{
stdout
{ codec
=> rubydebug
}
}
}